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 caused by otelhttp when no Meter Provider is configured. #5190

Open
strideynet opened this issue Mar 1, 2024 · 1 comment
Open
Labels
area: instrumentation Related to an instrumentation package bug Something isn't working instrumentation: otelhttp

Comments

@strideynet
Copy link

strideynet commented Mar 1, 2024

Description

When calling otelhttp.NewTransport() multiple times, memory is leaked.

image

Supposedly this was resolved by open-telemetry/opentelemetry-go#4820 but I do not think this fixes the issue when no meter provider has been configured and the default global delegating meter provider is in place.

Related: #4226
Introduced by: #4707

Environment

go version go1.22.0 darwin/arm64
	go.opentelemetry.io/contrib/instrumentation/github.com/aws/aws-sdk-go-v2/otelaws v0.49.0
	go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.49.0
	go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.49.0
	go.opentelemetry.io/otel v1.24.0
	go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.24.0
	go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc v1.24.0
	go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp v1.24.0
	go.opentelemetry.io/otel/metric v1.24.0
	go.opentelemetry.io/otel/sdk v1.24.0
	go.opentelemetry.io/otel/trace v1.24.0
	go.opentelemetry.io/proto/otlp v1.1.0

Steps To Reproduce

package bench

import (
	"testing"

	"go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp"
	"go.opentelemetry.io/otel"
	"go.opentelemetry.io/otel/metric/noop"
)

func BenchmarkWithNoMeterProviderSet(b *testing.B) {
	b.ReportAllocs()
	for i := 0; i < b.N; i++ {
		otelhttp.NewTransport(nil)
	}
}

func BenchmarkWithNoopMeterProviderSet(b *testing.B) {
	b.ReportAllocs()
	otel.SetMeterProvider(noop.MeterProvider{})
	for i := 0; i < b.N; i++ {
		otelhttp.NewTransport(nil)
	}
}

Run each of these with test.memprofile and analyze the inuse heap objects/space difference between them.

Alternatively, write an application which calls otelhttp.NewTransport and analyze heap usage.

Expected behavior

Calling otelhttp.NewTransport() repeatedly doesn't leak memory

Workaround

Call otel.SetMeterProvider(noop.MeterProvider{}) at the start of your application.

@tsuna
Copy link

tsuna commented Mar 28, 2024

We also ran into this issue at Arista.

mattmoor pushed a commit to chainguard-dev/terraform-infra-common that referenced this issue Apr 27, 2024
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: otelhttp
Projects
None yet
Development

No branches or pull requests

2 participants