Skip to content

Commit

Permalink
bug: workaround to stop memory leak in otel (#313)
Browse files Browse the repository at this point in the history
see
open-telemetry/opentelemetry-go-contrib#5190

Signed-off-by: Kenny Leung <kleung@chainguard.dev>
  • Loading branch information
k4leung4 authored Apr 27, 2024
1 parent 62fad2d commit 94b73d8
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions pkg/httpmetrics/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
"go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp"
"go.opentelemetry.io/otel"
"go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp"
"go.opentelemetry.io/otel/metric/noop"
"go.opentelemetry.io/otel/propagation"
"go.opentelemetry.io/otel/sdk/resource"
"go.opentelemetry.io/otel/sdk/trace"
Expand Down Expand Up @@ -94,6 +95,11 @@ var env struct {
}

func init() {
// Set the global metric provider to a no-op so that any metrics created from otelgrpc interceptors
// are disabled to prevent memory leaks.
// See https://github.com/open-telemetry/opentelemetry-go-contrib/issues/4226
otel.SetMeterProvider(noop.MeterProvider{})

if err := envconfig.Process("", &env); err != nil {
slog.Warn("Failed to process environment variables", "error", err)
}
Expand Down

0 comments on commit 94b73d8

Please sign in to comment.