Skip to content

TransactionTracer.SetData is not equivalent to TransactionTracer.Contexts.Trace.SetData #4140

Closed

Description

@Flash0ver

"data" set via TransactionTracer.SetData is not written to "Data" of the Trace-Context, and does not get copied over to SentryTransaction when created from the tracer.
But "data" set via TransactionTracer.Contexts.Trace.SetData is written to "Data" of the Trace-Context, and gets copied over to SentryTransaction when created from the tracer.

However, SentryTransaction.SetData and SentryTransaction.Contexts.Trace.SetData are equivalent setting "Data" of the Trace-Context.
With Spans, both setting "data" via SpanTracer.SetData and SentrySpan.SetData are eventually serialized to spans.data ("Data" does get copied over to SentrySpan when created from a SpanTracer);

Steps to Reproduce

SentrySdk.Init(options =>
{
    options.Dsn = "..";
    options.TracesSampleRate = 1.0;

    options.SetBeforeSendTransaction(transaction =>
    {
        transaction.SetData("setbeforesendtransaction", "transaction-setdata");
        transaction.Contexts.Trace.SetData("setbeforesendtransaction", "transaction-contexts-trace-setdata");
        return transaction;
    });
});

var transaction = SentrySdk.StartTransaction("my-transaction", "start-transaction");
SentrySdk.ConfigureScope(scope => scope.Transaction = transaction);
transaction.SetData("transaction-data-key", "transaction-data-value");
transaction.SetData("transaction-array", new[] {42, 43, 44});
// Do some work.
transaction.Finish();

Expected Result

Image
{
  "contexts": {
    "trace": {
      "data": {
        "setbeforesendtransaction": "transaction-contexts-trace-setdata",
        "transaction-array": [42, 43, 44],
        "transaction-data-key": "transaction-data-value"
      }
    }
  }
}

Actual Result

Image
{
  "contexts": {
    "trace": {
      "data": {
        "setbeforesendtransaction": "transaction-contexts-trace-setdata"
      }
    }
  }
}

Additional Notes

Activity

  1. self-assigned this
    on Apr 25, 2025
  2. added theissue type on Apr 25, 2025
  3. jamescrosswell commented on Apr 27, 2025

    @jamescrosswell
    Collaborator

    Worth reading the conversations in:

    @aritchie might have more context as that was his first PR.

  4. Flash0ver commented on Apr 28, 2025

    @Flash0ver
    ContributorAuthor

    Thanks for the context (on the contexts 😉).
    Opened a PR containing questions as comments whether I took the right approach.

  5. jamescrosswell commented on Apr 29, 2025

    @jamescrosswell
    Collaborator

    btw I think the description for this issue is a bit confusing:

    TransactionTracer.SetData is not serialized to contexts.trace.data
    SentryTransaction.SetData is serialized to contexts.trace.data

    TransactionTracer never gets serialised... it's the in-memory mutable representation of a trace that is used while the trace is active.

    Once the trace is finished, it gets turned into a SentryTransaction, which is essentially a (mostly) immutable DTO used to serialise the finalised transaction information and send it across the wire to Sentry.

    From the code example you provided, it looks like the issue is more about the distinction between transaction.Contexts.Trace.SetData and transaction.SetData.

    From memory, we knew this was inconsistent and intentionally didn't fix it for Transaction because it's likely we're going to get rid of the entire concept of transactions at some point in the near future.

    @bruno-garcia @aritchie have I got that completely backwards? The requirements on the first ticket did my head in as well... I'm really not sure what problem we're trying to solve here.

  6. aritchie commented on Apr 29, 2025

    @aritchie
    Contributor

    @jamescrosswell I think you're correct for that exact reasons you stated. There was a lot of confusion when we did that PR, but we decided to leave it.

  7. Flash0ver commented on Apr 29, 2025

    @Flash0ver
    ContributorAuthor

    @jamescrosswell thanks for the hint. I rephrased the summary of the description.
    @jamescrosswell @aritchie does this mean it works as intended and we should close this?
    Or am I misunderstanding there something?

  8. jamescrosswell commented on Apr 30, 2025

    @jamescrosswell
    Collaborator

    @jamescrosswell @aritchie does this mean it works as intended and we should close this?

    I think it was more, "This isn't a priority since it's throw away work anyway".

    Now that the work is (mostly) done we may as well merge it in. It will give us greater consistency until the Transactions get thrown out and, to be fair, we've been talking about deprecating those for years so your work on this issue may end up adding some value for longer than we think.

  9. changed the title [-]`TransactionTracer.SetData` is not serialized to `contexts.trace.data`[/-] [+]`TransactionTracer.SetData` is not equivalent to `TransactionTracer.Contexts.Trace.SetData`[/+] on Apr 30, 2025
  10. removed theissue type on Aug 6, 2025
  11. added
    .NETPull requests that update .net code
    on Mar 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

.NETPull requests that update .net codeBugSomething isn't workingTraces

Projects

  • Status
    Done

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions