Invoke SDK initialization when using OpenTelemetry.Extensions.Hosting#2901
Conversation
| { | ||
| // Extract the PropagationContext of the upstream parent from the message headers. | ||
| var parentContext = Propagator.Extract(default, ea.BasicProperties, this.ExtractTraceContextFromBasicProperties); | ||
| var parentContext = Propagators.DefaultTextMapPropagator.Extract(default, ea.BasicProperties, this.ExtractTraceContextFromBasicProperties); |
There was a problem hiding this comment.
On the first message received, the DefaultTextMapPropagator is the noop instance. By the second message received it has been initialized to the composite propagator that extracts trace context and baggage.
There was a problem hiding this comment.
can we "touch" SDK somewhere super early......
There was a problem hiding this comment.
Resolved this by touching the Sdk class in OpenTelemetry.Extensions.Hosting.
There was a problem hiding this comment.
A gentle touch, and SDK behaves!
Codecov Report
@@ Coverage Diff @@
## main #2901 +/- ##
==========================================
- Coverage 84.20% 84.19% -0.01%
==========================================
Files 252 252
Lines 8893 8895 +2
==========================================
+ Hits 7488 7489 +1
- Misses 1405 1406 +1
|
0ebb2b5 to
48f7957
Compare
cijothomas
left a comment
There was a problem hiding this comment.
would be good to add changelog.md entry too in hosting package?
Yes, I wavered on this, but I think I came up with something that makes sense. |
Fixes #2898
Using the microservice example to demonstrate that the SDK does not get initialized when expected.
The the static constructor on
OpenTelemtry.Sdkdoes not get invoked until after the first message is sent and received in the microservice example:opentelemetry-dotnet/src/OpenTelemetry/Sdk.cs
Lines 30 to 36 in aca7efc
@utpilla