Skip to content

Commit

Permalink
disable high cardinality attributes
Browse files Browse the repository at this point in the history
  • Loading branch information
mackjmr committed Sep 8, 2023
1 parent adca3d4 commit e10483a
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions src/productcatalogservice/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"github.com/sirupsen/logrus"
"go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc"
"go.opentelemetry.io/contrib/instrumentation/runtime"
"go.opentelemetry.io/otel/sdk/instrumentation"
sdkmetric "go.opentelemetry.io/otel/sdk/metric"
healthpb "google.golang.org/grpc/health/grpc_health_v1"

Expand Down Expand Up @@ -98,11 +99,34 @@ func initMeterProvider() *sdkmetric.MeterProvider {
mp := sdkmetric.NewMeterProvider(
sdkmetric.WithReader(sdkmetric.NewPeriodicReader(exporter)),
sdkmetric.WithResource(initResource()),
sdkmetric.WithView(
sdkmetric.NewView(
sdkmetric.Instrument{Scope: instrumentation.Scope{Name: "go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc"}},
sdkmetric.Stream{
AttributeFilter: allowedAttr(
"http.method",
"http.status_code",
"http.target",
),
},
),
),
)
otel.SetMeterProvider(mp)
return mp
}

func allowedAttr(v ...string) attribute.Filter {
m := make(map[string]struct{}, len(v))
for _, s := range v {
m[s] = struct{}{}
}
return func(kv attribute.KeyValue) bool {
_, ok := m[string(kv.Key)]
return ok
}
}

func main() {
tp := initTracerProvider()
defer func() {
Expand Down

0 comments on commit e10483a

Please sign in to comment.