mirror of
https://github.com/gotenberg/gotenberg.git
synced 2026-08-08 08:32:16 +01:00
fix(webhook): preserve trace context across async detach via WithoutCancel
This commit is contained in:
@@ -5,9 +5,37 @@ import (
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"go.opentelemetry.io/otel/trace"
|
||||
|
||||
"github.com/gotenberg/gotenberg/v8/pkg/modules/api"
|
||||
)
|
||||
|
||||
func TestDetachAsyncContext_PreservesTraceContext(t *testing.T) {
|
||||
traceID, _ := trace.TraceIDFromHex("0123456789abcdef0123456789abcdef")
|
||||
spanID, _ := trace.SpanIDFromHex("0123456789abcdef")
|
||||
sc := trace.NewSpanContext(trace.SpanContextConfig{
|
||||
TraceID: traceID,
|
||||
SpanID: spanID,
|
||||
TraceFlags: trace.FlagsSampled,
|
||||
Remote: true,
|
||||
})
|
||||
|
||||
reqCtx, reqCancel := context.WithDeadline(
|
||||
trace.ContextWithSpanContext(context.Background(), sc),
|
||||
time.Now().Add(2*time.Hour),
|
||||
)
|
||||
defer reqCancel()
|
||||
|
||||
ctx := &api.Context{Context: reqCtx}
|
||||
cancel := detachAsyncContext(ctx, func() {})
|
||||
defer cancel()
|
||||
|
||||
got := trace.SpanContextFromContext(ctx.Context)
|
||||
if got.TraceID() != sc.TraceID() {
|
||||
t.Errorf("expected the detached context to keep trace id %s, got %s", sc.TraceID(), got.TraceID())
|
||||
}
|
||||
}
|
||||
|
||||
func TestDetachAsyncContext_PreservesDeadline(t *testing.T) {
|
||||
deadline := time.Now().Add(2 * time.Hour)
|
||||
reqCtx, reqCancel := context.WithDeadline(context.Background(), deadline)
|
||||
|
||||
Reference in New Issue
Block a user