sentry-go icon indicating copy to clipboard operation
sentry-go copied to clipboard

[OTel] A transaction, not a span, is created when its parent span is already finished.

Open kamatama41 opened this issue 2 years ago • 0 comments

Summary

A new transaction is created if its parent span is already finished with OpenTelemetry integration.

Steps To Reproduce

func TestOtelTrace(t *testing.T) {
	if err := sentry.Init(sentry.ClientOptions{
		Dsn:              "https://[email protected]/0",
		EnableTracing:    true,
		TracesSampleRate: 1.0,
		Environment:      "test",
		Debug:            true,
	}); err != nil {
		panic("Sentry initialization failed: " + err.Error())
	}
	defer sentry.Flush(2 * time.Second)

	tp := sdktrace.NewTracerProvider(
		sdktrace.WithSpanProcessor(sentryotel.NewSentrySpanProcessor()),
	)
	tracer := tp.Tracer("test_tracer")

	ctx, span := tracer.Start(context.Background(), "test_transaction")
	defer span.End()

	ctx, span2 := tracer.Start(ctx, "test_span_1")
	time.Sleep(time.Second)
	span2.End()
	ctx, span3 := tracer.Start(ctx, "test_span_2")
	time.Sleep(time.Second)
	span3.End()
}

Run the test then test_span_2 became a transaction. スクリーンショット 2023-07-17 16 28 46

Expected Behavior

I would like test_span_2 to be a span. Using sentry-go directly works as expected.

func TestSentryTrace(t *testing.T) {
	if err := sentry.Init(sentry.ClientOptions{
		Dsn:              "https://[email protected]/0",
		EnableTracing:    true,
		TracesSampleRate: 1.0,
		Environment:      "test",
		Debug:            true,
	}); err != nil {
		panic("Sentry initialization failed: " + err.Error())
	}
	defer sentry.Flush(2 * time.Second)

	ctx := context.Background()
	span := sentry.StartTransaction(ctx, "test_transaction")
	defer span.Finish()

	span2 := sentry.StartSpan(span.Context(), "test_span_1")
	time.Sleep(time.Second)
	span2.Finish()
	span3 := sentry.StartSpan(span2.Context(), "test_span_2")
	time.Sleep(time.Second)
	span3.Finish()
}
スクリーンショット 2023-07-17 16 11 55

SDK

  • sentry-go version: v0.22.0
  • Go version: 1.20
  • Using Go Modules? [yes]

Sentry

  • Using hosted Sentry in sentry.io? [yes]
  • Using your own Sentry installation? Version:
  • Anything particular to your environment that could be related to this issue?

Additional context

kamatama41 avatar Jul 17 '23 07:07 kamatama41