opentelemetry-dotnet: Unable to log baggages via a processor
Bug Report
List of packages below,
<PackageReference Include="OpenTelemetry" Version="1.2.0-rc3" />
<PackageReference Include="OpenTelemetry.Exporter.Console" Version="1.2.0-rc3" />
<PackageReference Include="OpenTelemetry.Extensions.Hosting" Version="1.0.0-rc9" />
<PackageReference Include="OpenTelemetry.Instrumentation.AspNetCore" Version="1.0.0-rc9" />
<PackageReference Include="OpenTelemetry.Instrumentation.Http" Version="1.0.0-rc9" />
Runtime version: net6.0
Symptom
I’m trying to use a custom processor like the following to see the baggages that are being propagated. However in this processor Baggage.Current
is not present to process the baggages.
public class TelemetryBaggageLogger : BaseProcessor<Activity>
{
private readonly ILogger<TelemetryBaggageLogger> _logger;
public TelemetryBaggageLogger(ILogger<TelemetryBaggageLogger> logger)
{
_logger = logger ?? throw new ArgumentNullException(nameof(logger));
}
public override void OnStart(Activity activity)
{
_logger.LogInformation("-------------------> Logging Baggages In BaseProcessor:OnStart <-------------------");
IDictionaryEnumerator baggageEnumerator = Baggage.Current.GetEnumerator();
while (baggageEnumerator.MoveNext())
{
_logger.LogInformation($"OnStart->Received baggage {baggageEnumerator.Key}:{baggageEnumerator.Value}");
}
}
public override void OnEnd(Activity activity)
{
_logger.LogInformation("-------------------> Logging Baggages In BaseProcessor:OnEnd <-------------------");
IDictionaryEnumerator baggageEnumerator = Baggage.Current.GetEnumerator();
while (baggageEnumerator.MoveNext())
{
_logger.LogInformation($"OnEnd->Received baggage {baggageEnumerator.Key}:{baggageEnumerator.Value}");
}
}
}
I inject the processor as the following in the downstream (destination) service.
.AddProcessor(new TelemetryBaggageLogger(logger))
However, I can see the baggages propagating if I log the baggage information in the controller of the downstream service but not the processor.
To Reproduce
Complete code can be found in the project.
It’s a simple set of services, Library
-> Catalog
. Library (source service) calls the Catalog API (downstream service) with a set of baggages.
Baggage.SetBaggage("test.baggage1", "bag1");
Baggage.SetBaggage("test.baggage2", "bag2");
To run the project, use docker-compose -f docker-compose.yml -f docker-compose.override.yml up
To start propagating use curl, curl -iv http://localhost:8002/api/Orders/books
About this issue
- Original URL
- State: closed
- Created 2 years ago
- Comments: 18 (12 by maintainers)
@paulbatum There is nothing wrong in your code or the Baggage API or the SDK. The misbehaving component is the Asp.Net Core instrumentation library. Will get back once we dig into this a bit more.
Just replying to myself,
Activity.Current
does seem to be valid inProcessor.OnEnd
! Looking at options for how we could fix this.