-
Notifications
You must be signed in to change notification settings - Fork 879
Closed
Labels
bugSomething isn't workingSomething isn't workingneeds-triageNew issues which have not been classified or triaged by a community memberNew issues which have not been classified or triaged by a community memberpkg:OpenTelemetry.ApiIssues related to OpenTelemetry.Api NuGet packageIssues related to OpenTelemetry.Api NuGet package
Description
Package
OpenTelemetry.Api
Package Version
| Package Name | Version |
|---|---|
| OpenTelemetry.Api | 1.10.0 |
| OpenTelemetry | 1.10.0 |
| OpenTelemetry.Exporter.OpenTelemetryProtocol | 1.10.0 |
| OpenTelemetry.Extensions.Hosting | 1.10.0 |
| OpenTelemetry.Instrumentation.AspNetCore | 1.10.1 |
| OpenTelemetry.Instrumentation.Http | 1.10.0 |
Runtime Version
net8.0
Description
Baggage allows you to add a key with a value as an attribute to every subsequent child span of the current application context. The documentation of the OpenTelemetry .NET API -> Beggage API states:
Baggage API allows users to add context to metric, traces, and logs. Baggage can be propagated out of proc using Propagators. OpenTelemetry SDK ships a BaggagePropagator and enables it by default.
and
The recommended way to add Baggage is to use the Baggage.SetBaggage() API. OpenTelemetry users should not use the Activity.AddBaggage method.
If I try this feature using the Baggage API this is not possible for a simple ASP.NET Core Web API.
Steps to Reproduce
Program.cs:
using OpenTelemetry;
using OpenTelemetry.Trace;
using System.Net;
using WebApplication1.Controllers;
namespace WebApplication1
{
public class Program
{
public static void Main(string[] arguments)
{
WebApplicationBuilder applicationBuilder = WebApplication.CreateBuilder(arguments);
// Add services to the container.
OpenTelemetryBuilder openTelemetryBuilder = applicationBuilder.Services.AddOpenTelemetry();
openTelemetryBuilder.WithTracing(builder => builder
.AddAspNetCoreInstrumentation()
.AddHttpClientInstrumentation()
.AddOtlpExporter()
);
HttpClient.DefaultProxy = new WebProxy();
applicationBuilder.Services.AddHttpClient(nameof(WeatherForecastController), configure =>
{
configure.BaseAddress = new Uri("http://localhost:5091/");
});
applicationBuilder.Services.AddControllers();
applicationBuilder.Services.AddEndpointsApiExplorer();
applicationBuilder.Services.AddSwaggerGen();
WebApplication application = applicationBuilder.Build();
if (application.Environment.IsDevelopment())
{
application.UseSwagger();
application.UseSwaggerUI();
}
application.UseHttpsRedirection();
application.UseAuthorization();
application.MapControllers();
application.Run();
}
}
}WeatherForecastController.cs:
using Microsoft.AspNetCore.Mvc;
using OpenTelemetry;
namespace WebApplication1.Controllers
{
[ApiController]
[Route("[controller]")]
public class WeatherForecastController(IHttpClientFactory httpClientFactory) : ControllerBase
{
[HttpGet("A", Name = "GetWeatherForecastA")]
public void GetA()
{
Baggage.Current.SetBaggage("MyValue", "HelloWorld-1");
string? myValue = Baggage.Current.GetBaggage("MyValue"); // this call returns null
using HttpClient httpClient = httpClientFactory.CreateClient(nameof(WeatherForecastController));
using HttpResponseMessage httpResponseMessage = httpClient
.GetAsync("/WeatherForecast/B")
.GetAwaiter().GetResult();
httpResponseMessage.EnsureSuccessStatusCode();
}
[HttpGet("B", Name = "GetWeatherForecastB")]
public void GetB()
{
string? myValue = Baggage.Current.GetBaggage("MyValue"); // this call returns null
}
}
}Expected Result
The baggage value should be:
- returned when calling the GetBaggage function
- part of the trace record in otel exporter
- propageted as Header (Correlation-Context or PropagationObject??) of all sub calls via HttpClient
- part in all child spans
Actual Result
Baggage.Current.GetBaggage("MyValue")returns null- The value
MyValueis not part of the trace record - The value will be not propagated via Http Header to sub request calls
- Is not part of the child activity
Additional Context
No response
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
bugSomething isn't workingSomething isn't workingneeds-triageNew issues which have not been classified or triaged by a community memberNew issues which have not been classified or triaged by a community memberpkg:OpenTelemetry.ApiIssues related to OpenTelemetry.Api NuGet packageIssues related to OpenTelemetry.Api NuGet package