You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
StartTransaction function returns currentTransaction with outdated context.
Steps To Reproduce
Create transaction with StartTransaction: tr := sentry.StartTransaction(context.TODO(),...)
Add a new value to its context: ctx := context.WithValue(tc.Context(), "key", "value")
Receive transaction from the context like it is done somewhere down the stack: tr := sentry.StartTransaction(ctx,...)
Check if "key" exists in the transaction context: _, exist := tc.Context().Value("key").(string) // exist == false
Expected Behavior
StartTransaction may create a new transaction or return the one from the context, it is expected that tc.Context() returns the latest provided context, but not the outdated one.
func StartTransaction(ctx context.Context, name string, options ...SpanOption) *Span {
currentTransaction, exists := ctx.Value(spanContextKey{}).(*Span)
if exists {
return currentTransaction
}
...
StartTransaction function returns currentTransaction when it exists in the provided context. And currentTransaction contains a pointer to the context inside, but the older version of the context. It is expected that a newly started transaction will provide access to the modified context through transaction.Context() method.
To resolve the issue we need to update the pointer to the context, stored in currentTransaction
I found it when I used the grpc gateway with implemented interceptors. As the service supports HTTP and grpc the code reuses interceptors for both protocols. Sentry tracing is added in both HTTP middleware and grpc interceptor layers, and when the StartTransaction function is called second type the content for transaction.Context() contains the previous version of the content which was saved at the moment of object creation.
The text was updated successfully, but these errors were encountered:
far4599
changed the title
StartTransaction bring new context when transaction already exist in the context
StartTransaction returns transaction with outdated context, when the transaction already exist
Jul 10, 2024
far4599
changed the title
StartTransaction returns transaction with outdated context, when the transaction already exist
StartTransaction returns transaction with outdated context, when the transaction already exists
Jul 10, 2024
Summary
StartTransaction
function returnscurrentTransaction
with outdated context.Steps To Reproduce
tr := sentry.StartTransaction(context.TODO(),...)
ctx := context.WithValue(tc.Context(), "key", "value")
tr := sentry.StartTransaction(ctx,...)
_, exist := tc.Context().Value("key").(string) // exist == false
Expected Behavior
StartTransaction may create a new transaction or return the one from the context, it is expected that
tc.Context()
returns the latest provided context, but not the outdated one.Additional context
I found a tricky bug here.
StartTransaction
function returnscurrentTransaction
when it exists in the provided context. AndcurrentTransaction
contains a pointer to the context inside, but the older version of the context. It is expected that a newly started transaction will provide access to the modified context throughtransaction.Context()
method.To resolve the issue we need to update the pointer to the context, stored in
currentTransaction
I found it when I used the grpc gateway with implemented interceptors. As the service supports HTTP and grpc the code reuses interceptors for both protocols. Sentry tracing is added in both HTTP middleware and grpc interceptor layers, and when the
StartTransaction
function is called second type the content for transaction.Context() contains the previous version of the content which was saved at the moment of object creation.The text was updated successfully, but these errors were encountered: