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

otelgrpc: Remove high cardinality metric attributes #4322

Merged
merged 17 commits into from
Nov 6, 2023
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm

- Use `grpc.StatsHandler` for gRPC instrumentation in `go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc/example`. (#4325)

### Removed

- The `net.sock.peer.*` and `net.peer.*` high cardinality attributes are removed from the metrics generated by `go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc`. (#4322)

## [1.19.0/0.44.0/0.13.0] - 2023-09-12

### Added
Expand Down
25 changes: 13 additions & 12 deletions instrumentation/google.golang.org/grpc/otelgrpc/interceptor.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ func UnaryClientInterceptor(opts ...Option) grpc.UnaryClientInterceptor {
return invoker(ctx, method, req, reply, cc, callOpts...)
}

name, attr := spanInfo(method, cc.Target())
name, attr, _ := telemetryAttributes(method, cc.Target())

startOpts := append([]trace.SpanStartOption{
trace.WithSpanKind(trace.SpanKindClient),
Expand Down Expand Up @@ -278,7 +278,7 @@ func StreamClientInterceptor(opts ...Option) grpc.StreamClientInterceptor {
return streamer(ctx, desc, cc, method, callOpts...)
}

name, attr := spanInfo(method, cc.Target())
name, attr, _ := telemetryAttributes(method, cc.Target())

startOpts := append([]trace.SpanStartOption{
trace.WithSpanKind(trace.SpanKindClient),
Expand Down Expand Up @@ -346,7 +346,7 @@ func UnaryServerInterceptor(opts ...Option) grpc.UnaryServerInterceptor {
}

ctx = extract(ctx, cfg.Propagators)
name, attr := spanInfo(info.FullMethod, peerFromCtx(ctx))
name, attr, metricAttrs := telemetryAttributes(info.FullMethod, peerFromCtx(ctx))

startOpts := append([]trace.SpanStartOption{
trace.WithSpanKind(trace.SpanKindServer),
Expand All @@ -368,7 +368,7 @@ func UnaryServerInterceptor(opts ...Option) grpc.UnaryServerInterceptor {
var statusCode grpc_codes.Code
defer func(t time.Time) {
elapsedTime := time.Since(t) / time.Millisecond
attr = append(attr, semconv.RPCGRPCStatusCodeKey.Int64(int64(statusCode)))
attr := append(metricAttrs, semconv.RPCGRPCStatusCodeKey.Int64(int64(statusCode)))
MadVikingGod marked this conversation as resolved.
Show resolved Hide resolved
o := metric.WithAttributes(attr...)
cfg.rpcServerDuration.Record(ctx, int64(elapsedTime), o)
}(time.Now())
Expand Down Expand Up @@ -469,7 +469,7 @@ func StreamServerInterceptor(opts ...Option) grpc.StreamServerInterceptor {
}

ctx = extract(ctx, cfg.Propagators)
name, attr := spanInfo(info.FullMethod, peerFromCtx(ctx))
name, attr, _ := telemetryAttributes(info.FullMethod, peerFromCtx(ctx))

startOpts := append([]trace.SpanStartOption{
trace.WithSpanKind(trace.SpanKindServer),
Expand Down Expand Up @@ -498,17 +498,18 @@ func StreamServerInterceptor(opts ...Option) grpc.StreamServerInterceptor {
}
}

// spanInfo returns a span name and all appropriate attributes from the gRPC
// method and peer address.
func spanInfo(fullMethod, peerAddress string) (string, []attribute.KeyValue) {
name, mAttrs := internal.ParseFullMethod(fullMethod)
// telemetryAttributes returns a span name and span and metric attributes from
// the gRPC method and peer address.
func telemetryAttributes(fullMethod, peerAddress string) (string, []attribute.KeyValue, []attribute.KeyValue) {
name, methodAttrs := internal.ParseFullMethod(fullMethod)
peerAttrs := peerAttr(peerAddress)

attrs := make([]attribute.KeyValue, 0, 1+len(mAttrs)+len(peerAttrs))
attrs := make([]attribute.KeyValue, 0, 1+len(methodAttrs)+len(peerAttrs))
attrs = append(attrs, RPCSystemGRPC)
attrs = append(attrs, mAttrs...)
attrs = append(attrs, methodAttrs...)
metricAttrs := attrs[:1+len(methodAttrs)]
attrs = append(attrs, peerAttrs...)
return name, attrs
return name, attrs, metricAttrs
}

// peerAttr returns attributes about the peer address.
Expand Down
Loading