-
Notifications
You must be signed in to change notification settings - Fork 568
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: add custom attributes to the stats handler #5133
otelgrpc: add custom attributes to the stats handler #5133
Conversation
ce0e777
to
aac80ca
Compare
aac80ca
to
a508d4d
Compare
eacf0ac
to
d594e0c
Compare
d594e0c
to
99ea5ca
Compare
Friendly ping @dashpole @hanyuancheung |
This looks like it does a lot more than just add a labeler. Would you mind doing general refactoring in its own PR? |
e4f7d19
to
c82b0f0
Compare
Sure. I have simplified this PR by adding only the labeler. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can you add tests?
instrumentation/google.golang.org/grpc/otelgrpc/stats_handler.go
Outdated
Show resolved
Hide resolved
26b7c36
to
3d28af9
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you test the span from the stats handler as well?
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #5133 +/- ##
=====================================
Coverage 65.5% 65.6%
=====================================
Files 203 203
Lines 12936 12946 +10
=====================================
+ Hits 8484 8494 +10
Misses 4198 4198
Partials 254 254
|
2d79ff4
to
a6b8d67
Compare
@dashpole PTAL |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I thought we were going to use a context-based pattern (similar to the otelhttp.Labeler) to support this? Am I misremembering?
Yes, sorry, I forgot to comment this last change. My first idea was to follow the That's why I changed the approach. The behaviour differs from that of WDYT @dashpole ? |
A few thoughts/ideas:
|
Static attributes could be useful for tagging different servers running on the same service but on different ports, e.g. public, internal, backoffice, legacy...
These attributes are already being tagged in the spans/metrics.
The HandleRPC(begin) -> Interceptors(pre) -> handler logic -> Interceptors(post) -> HandleRPC(end). The problem is that despite modifying the context in an interceptor, the interceptor does not propagate it outwards, so it never reaches the end of the HandleRPC. |
Hi, I've ended up here after trying to figure out how to attach custom (static) labels to otelgrpc stats. Just wanted to add our concrete use case if it's helpful to demonstrate the need. We've got a central cluster that talks to the same service on multiple remote clusters, and I'd like to be able to label and differentiate remote clusters so I can examine their latency metrics separately. From what I've been able to determine poking around the codebases, attaching a different client handler with a different set of static labels/attributes on it to each of our outbound grpc client connections would let us distinguish between the connections after everything rolls up to the client latency metric. The only other way I can see to achieve that is to have different MeterProviders with different labels, but then I believe they would conflict on the metric names if I were to try and publish the metrics through the same exporter (the otel prometheus exporter in this case). |
I think this change is a good idea. @hanyuancheung any thoughts? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please add a changelog entry
65ac7d6
to
4249103
Compare
985c8c4
to
7d7a5b3
Compare
7d7a5b3
to
f622caa
Compare
This release is the last to support [Go 1.21]. The next release will require at least [Go 1.22]. ### Added - Add the `WithSpanAttributes` and `WithMetricAttributes` methods to set custom attributes to the stats handler in `go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc`. (#5133) - The `go.opentelemetry.io/contrib/bridges/otelzap` module. This module provides an OpenTelemetry logging bridge for `go.uber.org/zap`. (#5191) - Support for the `OTEL_HTTP_CLIENT_COMPATIBILITY_MODE=http/dup` environment variable in `go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp` to emit attributes for both the v1.20.0 and v1.26.0 semantic conventions. (#5401) - The `go.opentelemetry.io/contrib/bridges/otelzerolog` module. This module provides an OpenTelemetry logging bridge for `github.com/rs/zerolog`. (#5405) - Add `WithGinFilter` filter parameter in `go.opentelemetry.io/contrib/instrumentation/github.com/gin-gonic/gin/otelgin` to allow filtering requests with `*gin.Context`. (#5743) - Support for stdoutlog exporter in `go.opentelemetry.io/contrib/config`. (#5850) - Add macOS ARM64 platform to the compatibility testing suite. (#5868) - Add new runtime metrics to `go.opentelemetry.io/contrib/instrumentation/runtime`, which are still disabled by default. (#5870) - Add the `WithMetricsAttributesFn` option to allow setting dynamic, per-request metric attributes in `go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp`. (#5876) - The `go.opentelemetry.io/contrib/config` package supports configuring `with_resource_constant_labels` for the prometheus exporter. (#5890) - Support [Go 1.23]. (#6017) ### Removed - The deprecated `go.opentelemetry.io/contrib/processors/baggagecopy` package is removed. (#5853) ### Fixed - Race condition when reading the HTTP body and writing the response in `go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp`. (#5916) [Go 1.23]: https://go.dev/doc/go1.23 [Go 1.22]: https://go.dev/doc/go1.22 [Go 1.21]: https://go.dev/doc/go1.21
Fixes #3894