opentelemetry-go-contrib
opentelemetry-go-contrib copied to clipboard
[otelgin] support additional span options to otelgin middleware
We have used otelgin in our production environment, and find it may be more easy to reach opentelemetry best practises if we can set additional attributes in span. Like hostname, os, platform and so on.
The committers listed above are authorized under a signed CLA.
- :white_check_mark: login: hjweddie / name: StackoverFrog (d1f55dc683d1acab33b4c913006c5b84583da14c, 41f8f29b4c6452497a3a1e364cb0ce4aa0d983d7)
@hjweddie Can you please sign the CLA?
Codecov Report
Merging #2730 (1f2da05) into main (7def0b3) will increase coverage by
0.0%. The diff coverage is100.0%.
:exclamation: Current head 1f2da05 differs from pull request most recent head f121db1. Consider uploading reports for the commit f121db1 to get more accurate results
Additional details and impacted files
@@ Coverage Diff @@
## main #2730 +/- ##
=====================================
Coverage 69.3% 69.4%
=====================================
Files 145 145
Lines 6729 6717 -12
=====================================
- Hits 4667 4665 -2
+ Misses 1948 1938 -10
Partials 114 114
| Impacted Files | Coverage Δ | |
|---|---|---|
| ...ation/github.com/gin-gonic/gin/otelgin/gintrace.go | 81.2% <100.0%> (+0.4%) |
:arrow_up: |
| ...ntation/github.com/gin-gonic/gin/otelgin/option.go | 100.0% <100.0%> (ø) |
|
| propagators/jaeger/jaeger_propagator.go | 97.1% <0.0%> (-0.2%) |
:arrow_down: |
| ...ion/github.com/aws/aws-sdk-go-v2/otelaws/config.go | 100.0% <0.0%> (ø) |
|
| ...tation/github.com/aws/aws-sdk-go-v2/otelaws/aws.go | 93.9% <0.0%> (+0.3%) |
:arrow_up: |
| ...ion/google.golang.org/grpc/otelgrpc/interceptor.go | 84.2% <0.0%> (+0.6%) |
:arrow_up: |
| ...ation/google.golang.org/grpc/otelgrpc/grpctrace.go | 49.1% <0.0%> (+3.4%) |
:arrow_up: |
@hjweddie Can you please sign the CLA?
okay, signed
WithSpanOptions
I understand that it would be much nice to add a test for checking attributes. But I do not sure how could I test it in unittest, because I do not know how to get span attributes. Do you have any ideas ?
Using the tracetest package, you can configure a test tracer which will record all emitted spans. You can then inspect and assert on them.
See this test as an example: https://github.com/open-telemetry/opentelemetry-go-contrib/blob/fe241f3098fdcd4769aea55c6caf5a2999d853e0/instrumentation/net/http/otelhttp/test/transport_test.go#L40
tracetest package
tracetest package is awesome.
I have changed WithAttributes to WithSpanOptions and add unittest for it.
I thinks it may be nice to use tracetest to enrich test in otelgin, not just assert on trace id and span id. It may be done in another pr
I try to change WithSpanOptions to two funs, WithSpanStartOptions and WithSpanEndOptions. it may be usefull if we can overwrite setting with span end options
Is there anything for mering this pr that I missed ?
@jmacd @MrAlias @Aneurysm9 @evantorrie @XSAM Anyone helps reviewing this pr ?
We have used otelgin in our production environment, and find it may be more easy to reach opentelemetry best practises if we can set additional attributes in span. Like hostname, os, platform and so on.
I'm confused by this. The listed attributes would be resource attributes and not set at span creation time. I'm not aware of any other instrumentation that includes such options. What would they be used for that does not involve setting resource attributes on individual spans rather than on the resource given to the TracerProvider when the SDK is initialized?