Summary
Create a bridge to automatically capture telemetry from .NET's DiagnosticSource events. Many .NET libraries (HttpClient, SqlClient, etc.) emit diagnostic events that can be converted to OpenTelemetry spans.
Background
.NET has a built-in DiagnosticSource system that libraries use to emit events:
HttpClient emits request/response events
SqlClient emits query events
- Many other libraries participate
Currently this data is lost unless explicitly subscribed to.
Proposed API
var config = new TelemetryConfiguration
{
// Enable automatic DiagnosticSource bridging
EnableDiagnosticSourceBridge = true,
// Or selectively enable specific sources
DiagnosticSources = new[]
{
"HttpHandlerDiagnosticListener",
"SqlClientDiagnosticListener"
}
};
// Or configure at runtime
VsixTelemetry.SubscribeToDiagnosticSource("MyCustomSource");
VsixTelemetry.SubscribeToDiagnosticSource("HttpHandlerDiagnosticListener",
filter: evt => evt.Name.StartsWith("System.Net.Http"));
Events to Bridge
HttpClient
System.Net.Http.HttpRequestOut.Start → Span start
System.Net.Http.HttpRequestOut.Stop → Span end with status
- Add: URL, method, status code, duration
SqlClient (if used)
System.Data.SqlClient.WriteCommandBefore → Span start
System.Data.SqlClient.WriteCommandAfter → Span end
- Add: Database, command type, (sanitized) query
Implementation Notes
- Use
DiagnosticListener.AllListeners to discover sources
- Implement
IObserver<DiagnosticListener> for subscription
- Map diagnostic events to OpenTelemetry span operations
- Handle event payload extraction via reflection or known types
- Consider performance impact of reflection
Summary
Create a bridge to automatically capture telemetry from .NET's
DiagnosticSourceevents. Many .NET libraries (HttpClient, SqlClient, etc.) emit diagnostic events that can be converted to OpenTelemetry spans.Background
.NET has a built-in
DiagnosticSourcesystem that libraries use to emit events:HttpClientemits request/response eventsSqlClientemits query eventsCurrently this data is lost unless explicitly subscribed to.
Proposed API
Events to Bridge
HttpClient
System.Net.Http.HttpRequestOut.Start→ Span startSystem.Net.Http.HttpRequestOut.Stop→ Span end with statusSqlClient (if used)
System.Data.SqlClient.WriteCommandBefore→ Span startSystem.Data.SqlClient.WriteCommandAfter→ Span endImplementation Notes
DiagnosticListener.AllListenersto discover sourcesIObserver<DiagnosticListener>for subscription