Skip to content
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

Closes #854 #855

Merged
merged 3 commits into from
Jul 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions tracing.go
Original file line number Diff line number Diff line change
Expand Up @@ -962,6 +962,7 @@ func SpanFromContext(ctx context.Context) *Span {
func StartTransaction(ctx context.Context, name string, options ...SpanOption) *Span {
currentTransaction, exists := ctx.Value(spanContextKey{}).(*Span)
if exists {
currentTransaction.ctx = ctx
return currentTransaction
}

Expand Down
21 changes: 21 additions & 0 deletions tracing_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,27 @@ func TestStartTransaction(t *testing.T) {
}
}

func TestStartTransaction_with_context(t *testing.T) {
t.Run("get transaction from context", func(t *testing.T) {
tr := StartTransaction(context.TODO(), "")
ctx := tr.Context()
existingTr := StartTransaction(ctx, "")
if existingTr != tr {
t.Fatalf("existing transaction not found")
}
})

t.Run("get transaction with latest context", func(t *testing.T) {
tr := StartTransaction(context.TODO(), "")
ctx := context.WithValue(tr.Context(), testContextKey{}, testContextValue{})
existingTr := StartTransaction(ctx, "")
_, keyExists := existingTr.Context().Value(testContextKey{}).(testContextValue)
if !keyExists {
t.Fatalf("key not found in context")
}
})
}

func TestSetTag(t *testing.T) {
ctx := NewTestContext(ClientOptions{
EnableTracing: true,
Expand Down
Loading