Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Trace propagation broken when there is no continue_trace call #4033

Open
szokeasaurusrex opened this issue Feb 10, 2025 · 0 comments
Open

Trace propagation broken when there is no continue_trace call #4033

szokeasaurusrex opened this issue Feb 10, 2025 · 0 comments

Comments

@szokeasaurusrex
Copy link
Member

szokeasaurusrex commented Feb 10, 2025

How do you use Sentry?

Sentry Saas (sentry.io)

Version

latest master

Steps to Reproduce

Make file main.py:

import sentry_sdk
import httpx


def main():
    print("Headers in isolation scope (correctly propagated):")
    for header, value in sentry_sdk.get_isolation_scope().iter_headers():
        print(header, value)

    print("")

    print(
        "Headers not propagated on outgoing request outside of transaction (but should be):"
    )
    print(httpx.get("http://httpbin.org/get").text)

    print("")

    with sentry_sdk.start_transaction(name="main", sampled=True) as t:
        print("Headers on the transaction (not propagated, but should be):")
        for header, value in t.iter_headers():
            print(header, value)

        print("")

        print("The transaction headers, not the incoming ones, are propagated:")
        print(httpx.get("http://httpbin.org/get").text)


if __name__ == "__main__":
    sentry_sdk.init(
        traces_sample_rate=1.0,
    )
    main()

Run commands:

  1. export SENTRY_TRACE="00000000000000000000000000000000-0000000000000000"
  2. export SENTRY_BAGGAGE="sentry-placeholder=asdf"
  3. python main.py

Expected Result

Incoming trace is propagated, per spec

Actual Result

Trace is ignored. Root cause is having separate places where we store trace information (#4032)

Headers in isolation scope (correctly propagated):
sentry-trace 00000000000000000000000000000000-8a27591a41b755dd
baggage sentry-placeholder=asdf

Headers not propagated on outgoing request outside of transaction (but should be):
{
  "args": {}, 
  "headers": {
    "Accept": "*/*", 
    "Accept-Encoding": "gzip, deflate", 
    "Host": "httpbin.org", 
    "User-Agent": "python-httpx/0.28.1", 
    "X-Amzn-Trace-Id": "Root=1-67aa3fa3-0049028051b709cd2be65300"
  }, 
  "origin": "redact", 
  "url": "http://httpbin.org/get"
}


Headers on the transaction (not propagated, but should be):
sentry-trace 7c057f50606e45d6a1682a9580c8c978-ad9c29a5285d0d0c-1
baggage sentry-trace_id=7c057f50606e45d6a1682a9580c8c978,sentry-environment=production,sentry-transaction=main,sentry-sample_rate=1.0,sentry-sampled=true

The transaction headers, not the incoming ones, are propagated:
{
  "args": {}, 
  "headers": {
    "Accept": "*/*", 
    "Accept-Encoding": "gzip, deflate", 
    "Baggage": "sentry-trace_id=7c057f50606e45d6a1682a9580c8c978,sentry-environment=production,sentry-transaction=main,sentry-sample_rate=1.0,sentry-sampled=true", 
    "Host": "httpbin.org", 
    "Sentry-Trace": "7c057f50606e45d6a1682a9580c8c978-bf64a1d873991411-1", 
    "User-Agent": "python-httpx/0.28.1", 
    "X-Amzn-Trace-Id": "Root=1-67aa3fa3-6b6554ad237d7d835df81ecd"
  }, 
  "origin": "redact", 
  "url": "http://httpbin.org/get"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant