def test_adds_tracestate_to_transaction_when_getting_trace_context( sentry_init): sentry_init( dsn= "https://[email protected]/12312012", environment="dogpark", release="off.leash.park", ) transaction = Transaction( name="/interactions/other-dogs/new-dog", op="greeting.sniff", ) # no inherited tracestate, and none created in Transaction constructor assert transaction._sentry_tracestate is None transaction.get_trace_context() assert transaction._sentry_tracestate is not None
def test_tracestate_is_immutable_once_set(sentry_init, monkeypatch, set_by): monkeypatch.setattr( sentry_sdk.tracing, "compute_tracestate_entry", mock.Mock(return_value="sentry=doGsaREgReaT"), ) sentry_init( dsn= "https://[email protected]/12312012", environment="dogpark", release="off.leash.park", ) # for each scenario, get to the point where tracestate has been set if set_by == "inheritance": transaction = Transaction( name="/interactions/other-dogs/new-dog", op="greeting.sniff", sentry_tracestate=("sentry=doGsaREgReaT"), ) else: transaction = Transaction( name="/interactions/other-dogs/new-dog", op="greeting.sniff", ) if set_by == "to_tracestate": transaction.to_tracestate() if set_by == "get_trace_context": transaction.get_trace_context() assert transaction._sentry_tracestate == "sentry=doGsaREgReaT" # user data would be included in tracestate if it were recomputed at this point sentry_sdk.set_user({"id": 12312013, "segment": "bigs"}) # value hasn't changed assert transaction._sentry_tracestate == "sentry=doGsaREgReaT"