Problem Statement
When manually instrumenting a transaction, it's advised to add it to the current scope:
SentrySdk.ConfigureScope(scope => scope.Transaction = transaction);
This is in the docs: https://docs.sentry.io/platforms/dotnet/performance/instrumentation/custom-instrumentation/
And samples:
|
// This starts a new transaction and attaches it to the scope. |
|
var transaction = SentrySdk.StartTransaction("Program Main", "function"); |
|
SentrySdk.ConfigureScope(scope => scope.Transaction = transaction); |
Adding the transaction to the scope is required for methods like SentrySDK.GetSpan() to work - which is useful for then calling methods like StartChild() to instrument a specific portion of the app. If the transaction is not set on the scope, then GetSpan() returns null.
It's very easy to forget to do this. It would be better if it happened automatically when starting a transaction, instead of having to call a separate API.
Solution Brainstorm
When calling StartTransaction, if there's an active scope that doesn't already have a transaction set, that we could set it on the scope at that time.
We should be careful that any existing code that is setting it manually doesn't break, by only setting it when null, and only clearing it if we were the one to set it.
Possible breaking change
Since this is a possible breaking change, we could phase it in via some kind of SentryOptions.AutoSetScopeTransactions property or something, which defaults to false initially but which we could change to default to true in some future major release.
Problem Statement
When manually instrumenting a transaction, it's advised to add it to the current scope:
This is in the docs: https://docs.sentry.io/platforms/dotnet/performance/instrumentation/custom-instrumentation/
And samples:
sentry-dotnet/samples/Sentry.Samples.Console.Basic/Program.cs
Lines 38 to 40 in a674815
Adding the transaction to the scope is required for methods like
SentrySDK.GetSpan()to work - which is useful for then calling methods likeStartChild()to instrument a specific portion of the app. If the transaction is not set on the scope, thenGetSpan()returnsnull.It's very easy to forget to do this. It would be better if it happened automatically when starting a transaction, instead of having to call a separate API.
Solution Brainstorm
When calling
StartTransaction, if there's an active scope that doesn't already have a transaction set, that we could set it on the scope at that time.We should be careful that any existing code that is setting it manually doesn't break, by only setting it when null, and only clearing it if we were the one to set it.
Possible breaking change
Since this is a possible breaking change, we could phase it in via some kind of
SentryOptions.AutoSetScopeTransactionsproperty or something, which defaults tofalseinitially but which we could change to default totruein some future major release.