Skip to content

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

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

Open
Flash0ver opened this issue Apr 25, 2025 · 6 comments · May be fixed by #4148
Open

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

Flash0ver opened this issue Apr 25, 2025 · 6 comments · May be fixed by #4148
Assignees
Labels
Bug Something isn't working Product: Tracing

Comments

@Flash0ver
Copy link
Member

Flash0ver commented Apr 25, 2025

"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

@jamescrosswell
Copy link
Collaborator

Worth reading the conversations in:

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

@Flash0ver
Copy link
Member Author

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

@jamescrosswell
Copy link
Collaborator

jamescrosswell commented Apr 29, 2025

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.

@aritchie
Copy link
Collaborator

@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.

@Flash0ver
Copy link
Member Author

@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?

@jamescrosswell
Copy link
Collaborator

jamescrosswell commented Apr 30, 2025

@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.

@Flash0ver Flash0ver changed the title TransactionTracer.SetData is not serialized to contexts.trace.data TransactionTracer.SetData is not equivalent to TransactionTracer.Contexts.Trace.SetData Apr 30, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Something isn't working Product: Tracing
Projects
Status: No status
Development

Successfully merging a pull request may close this issue.

4 participants