Agent: Integration with `IServiceProvider` [Research]
stevejgordon opened this issue · comments
Steve Gordon commented
The existing OpenTelemetry SDK includes support for integrating with IServiceProvider
. For example, the resource builder can read from a resolved IConfiguration
instance. We should ensure that our distribution behaves nicely with this usage pattern and that we don't prevent any scenarios that depend on the IServiceProvider
mechanisms.
Example:
var builder = WebApplication.CreateBuilder(args);
const string serviceName = "roll-dice";
builder.Logging.AddOpenTelemetry(options =>
{
options
.SetResourceBuilder(
ResourceBuilder.CreateDefault()
.AddService(serviceName))
.AddConsoleExporter();
});
builder.Services.AddOpenTelemetry()
.ConfigureResource(resource => resource.AddService(serviceName))
.WithTracing(tracing => tracing
.AddAspNetCoreInstrumentation()
.AddConsoleExporter())
.WithMetrics(metrics => metrics
.AddAspNetCoreInstrumentation()
.AddConsoleExporter());
var app = builder.Build();