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

Memory leak of spans with grpc server stats handler #6446

Open
atoulme opened this issue Dec 13, 2024 · 9 comments
Open

Memory leak of spans with grpc server stats handler #6446

atoulme opened this issue Dec 13, 2024 · 9 comments
Assignees
Labels
area: instrumentation Related to an instrumentation package bug Something isn't working instrumentation: otelgrpc

Comments

@atoulme
Copy link

atoulme commented Dec 13, 2024

Description

See open-telemetry/opentelemetry-collector#11875 for original filing.

The gRPC server stats handler set by the OTLP receiver exposes a leak of spans over a long period of time.

From review of the code, it is possible the spans are not always closed by the stats_handler.go.

The span.End() call is made upon receiving the *stats.End event:

It seems in light of the leak, given the pprof dumps provided in the original report, that the event is not always received.

@dmathieu
Copy link
Member

cc @dashpole as code owner.

@dashpole dashpole changed the title Memory leak of spans with grpc server interceptor Memory leak of spans with grpc server stats handler Dec 13, 2024
@dashpole
Copy link
Contributor

Updated the title and description. Looks like you are using the stats handler, rather than the interceptor.

@dashpole dashpole self-assigned this Dec 13, 2024
@atoulme
Copy link
Author

atoulme commented Jan 17, 2025

Is there a workaround we can apply to deactivate or not trace the stats handler?

@vianamjr
Copy link
Contributor

vianamjr commented Jan 28, 2025

I noticed something similar by just start using it with sentry. (We where using pure otlp with grpc collector - jaeger).

Since I started sentry and added:

import (
         ....
         sentryotel "github.com/getsentry/sentry-go/otel"
        ....
)

....

	tp := oteltrace.NewTracerProvider(
		oteltrace.WithSpanProcessor(sentryotel.NewSentrySpanProcessor()),
	)

	// set the global tracer.
	otel.SetTracerProvider(tp)
	otel.SetTextMapPropagator(sentryotel.NewSentryPropagator())

....

Also I noticed it going up even without any call (we have health check call, that I filtered out)

The leak seems to start. Not sure where to fix it, maybe sentry is missing something?

Also reported in: getsentry/sentry-go#959

The memory profile (objects):

Image

@vianamjr
Copy link
Contributor

I did some more investigation and it's on filtered calls. Is start a span, but never ends. (using sentry processor)

@vianamjr
Copy link
Contributor

@dashpole
Copy link
Contributor

@atoulme Do you know if you are using filters at all? #6695 may have fixed your issue

@vianamjr
Copy link
Contributor

vianamjr commented Jan 31, 2025

I deployed 7 apps using (the merged version), no leak 🙌

@atoulme
Copy link
Author

atoulme commented Jan 31, 2025

@dashpole I am not the original reporter, it looks like the fix would apply to the original reporter, so this might be it.

@github-project-automation github-project-automation bot moved this to Needs triage in Go: Triage Jan 31, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: instrumentation Related to an instrumentation package bug Something isn't working instrumentation: otelgrpc
Projects
Status: Needs triage
Development

No branches or pull requests

4 participants