-
-
Notifications
You must be signed in to change notification settings - Fork 226
Description
Take the following snippet:
var tran = sentryTrace is not null
&& SentryTraceHeader.Parse(sentryTrace) is { } trace
? SentrySdk.StartTransaction("AppStart", "activity.load", trace)
: SentrySdk.StartTransaction("AppStart", "activity.load");
I marked this issue as a bug because we're crashing apps in case of a very "normal" (albeit not common) looking usage of the SDK.
One issue here is that if the service starting the trace had a DIsabled Sentry SDK, you could get all zeros here.
Repro: SDK starting the trace has a disabled DSN and does span.GetTraceHeader()
| public virtual SentryTraceHeader GetTraceHeader() => SentryTraceHeader.Empty; |
So sentryTrace is not null or empty. And SentryTraceHeader.Parse successfully parses it.
But trying to start a trace, crashes my app.

So to use this API properly, one has to:
var tran = sentryTrace is not null
&& SentryTraceHeader.Parse(sentryTrace) is { } trace
&& trace.TraceId != SentryId.Empty
? SentrySdk.StartTransaction("AppStart", "activity.load", trace)
: SentrySdk.StartTransaction("AppStart", "activity.load");
Some ideas:
StartTransactionbecomes more lenient. It shouldn't crash! So if the id provided is invalid. Just start a new oneSentryTraceHeader.Parsereturns null if the parsed trace header is all0's
I rather we go with 1. And I'd also argue we should change the API to take a trace that is nullable.
So using the API becomes a LOT easier:
var tran = SentrySdk.StartTransaction("AppStart", "activity.load", SentryTraceHeader.Parse(sentryTrace))
Alternatively, we could take a string overload for sentryTrace. But we need to consider that having 3 string parameters in a row and other overloads might make the API confusing. (for example, see this case)
Metadata
Metadata
Assignees
Labels
Projects
Status