The AddOpenTelemetry method injects its hosted service as the first service in the service collection.
services.Insert(0, ServiceDescriptor.Singleton<IHostedService, TelemetryHostedService>());
This means that the library event listener won't capture any events produced during the OTel initialization process because it will be registered later.
I suggest changing the AddOpenTelemetryEventLogging extension to be based on IOpenTelemetryBuilder instead of IServiceCollection and injecting the OpenTelemetryEventLoggingHostedService before TelemetryHostedService
public static IOpenTelemetryBuilder AddOpenTelemetryEventLogging(
this IOpenTelemetryBuilder builder,
Action<OpenTelemetryEventLoggingOptions>? configure = null)
{
if (configure != null)
builder.Services.Configure(configure);
return builder.Services.Insert(0, ServiceDescriptor.Singleton<IHostedService, OpenTelemetryEventLoggingHostedService>());
}
The usage
services.AddOpenTelemetry()
.AddOpenTelemetryEventLogging() // rename to WithOpenTelemetryEventLogging?
.WithTracing()
.WithMetrics();
The AddOpenTelemetry method injects its hosted service as the first service in the service collection.
This means that the library event listener won't capture any events produced during the OTel initialization process because it will be registered later.
I suggest changing the
AddOpenTelemetryEventLoggingextension to be based onIOpenTelemetryBuilderinstead ofIServiceCollectionand injecting theOpenTelemetryEventLoggingHostedServicebeforeTelemetryHostedServiceThe usage