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

[Otel] SpanProcessor panic on shutdown with background context #692

Closed
duongcongtoai opened this issue Aug 8, 2023 · 1 comment · Fixed by #711
Closed

[Otel] SpanProcessor panic on shutdown with background context #692

duongcongtoai opened this issue Aug 8, 2023 · 1 comment · Fixed by #711
Labels
Status: Backlog Topic: OpenTelemetry Issue/PR related to OpenTelemetry integration Type: Bug

Comments

@duongcongtoai
Copy link

duongcongtoai commented Aug 8, 2023

Summary

I setup sentry with Opentelemetry, and on shutdown, the code panic with stack trace

panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x10 pc=0xa700f7]

goroutine 7211 [running]:
github.com/getsentry/sentry-go.(*Hub).stackTop(0xc000126000?)
	/go/pkg/mod/github.com/getsentry/sentry-go@v0.22.0/hub.go:109 +0x37
github.com/getsentry/sentry-go.(*Hub).Client(0x4a139c?)
	/go/pkg/mod/github.com/getsentry/sentry-go@v0.22.0/hub.go:136 +0x19
github.com/getsentry/sentry-go.(*Hub).Flush(0x47ab01?, 0xc0008cad50?)
	/go/pkg/mod/github.com/getsentry/sentry-go@v0.22.0/hub.go:347 +0x1e
github.com/getsentry/sentry-go/otel.flushSpanProcessor({0x146b420?, 0xc000d04b10?})
	/go/pkg/mod/github.com/getsentry/sentry-go/otel@v0.22.0/span_processor.go:108 +0x9a
github.com/getsentry/sentry-go/otel.(*sentrySpanProcessor).ForceFlush(...)
	/go/pkg/mod/github.com/getsentry/sentry-go/otel@v0.22.0/span_processor.go:101
github.com/getsentry/sentry-go/otel.(*sentrySpanProcessor).Shutdown(0x101eee0?, {0x146b420, 0xc000d04b10})
	/go/pkg/mod/github.com/getsentry/sentry-go/otel@v0.22.0/span_processor.go:96 +0x39
go.opentelemetry.io/otel/sdk/trace.(*TracerProvider).Shutdown.func1()
	/go/pkg/mod/go.opentelemetry.io/otel/sdk@v1.13.0/trace/provider.go:259 +0x39
sync.(*Once).doSlow(0xc00058ae80?, 0x4064f1?)
	/usr/local/go/src/sync/once.go:74 +0xc2
sync.(*Once).Do(...)
	/usr/local/go/src/sync/once.go:65
go.opentelemetry.io/otel/sdk/trace.(*TracerProvider).Shutdown(0xc000192600, {0x146b420, 0xc000d04b10})
	/go/pkg/mod/go.opentelemetry.io/otel/sdk@v1.13.0/trace/provider.go:258 +0x285

How i init client

	batchProcessor := sdktrace.NewBatchSpanProcessor(exporter)
	sampler := sdktrace.ParentBased(sdktrace.TraceIDRatioBased(opts.SampleRate))
	propagator := propagation.NewCompositeTextMapPropagator(
		propagation.TraceContext{},
		b3.New(b3.WithInjectEncoding(b3.B3SingleHeader|b3.B3MultipleHeader)), // For Istio compatibility
	)
	tp := sdktrace.NewTracerProvider(
		sdktrace.WithSampler(sampler),
		sdktrace.WithSpanProcessor(batchProcessor),
		sdktrace.WithResource(resource.NewWithAttributes(
			semconv.SchemaURL,
			semconv.ServiceNameKey.String(opts.TracerName),
			semconv.ServiceVersionKey.String(opts.TracerVersion),
			attribute.String(environmentLabel, opts.Environment),
		)),
	)
	
        tp.RegisterSpanProcessor(sentryotel.NewSentrySpanProcessor())
	
	otel.SetTracerProvider(tp)
	otel.SetTextMapPropagator(propagator)

How i shutdown (ctx is background)


			if tp, ok := tp.(*sdktrace.TracerProvider); ok && tp != nil {
				return tp.Shutdown(ctx)
			}

This code panic because in the context there is no hub assigned, and the spanprocessor try to call stackTop on a nil hub, do i have to explicitly assign a hub into the main context?

Environment

SDK

  • sentry-go version: 0.22.0
  • Go version: 1.20
  • Using Go Modules? [yes]

Additional context

@tonyo
Copy link
Member

tonyo commented Aug 8, 2023

Thanks for reporting, we'll look into it.

@tonyo tonyo added the Topic: OpenTelemetry Issue/PR related to OpenTelemetry integration label Sep 4, 2023
@tonyo tonyo closed this as completed in #711 Sep 7, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Status: Backlog Topic: OpenTelemetry Issue/PR related to OpenTelemetry integration Type: Bug
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants