66using OpenTelemetry . Exporter ;
77using OpenTelemetry . Logs ;
88using OpenTelemetry . Metrics ;
9+ using OpenTelemetry . Resources ;
910using OpenTelemetry . Trace ;
1011
1112namespace Nihlen . Common . Telemetry ;
@@ -26,66 +27,51 @@ public static class TelemetryExtensions
2627 if ( services is null )
2728 return null ;
2829
29- var resourceBuilder = Telemetry . GetResourceBuilder ( ref serviceName , ref serviceVersion , ref otlpEndpoint ) ;
30+ // var resourceBuilder = Telemetry.GetResourceBuilder(ref serviceName, ref serviceVersion, ref otlpEndpoint);
3031
31- services . AddOpenTelemetryTracing ( b => b
32- . AddSource ( serviceName )
33- . SetResourceBuilder ( resourceBuilder )
34- . AddOtlpExporter ( o =>
35- {
36- o . Endpoint = new Uri ( otlpEndpoint ) ;
37- o . Protocol = OtlpExportProtocol . Grpc ;
38- } )
39- . AddAspNetCoreInstrumentation ( o =>
40- {
41- o . RecordException = true ;
42- } )
43- . AddHttpClientInstrumentation ( o =>
44- {
45- o . RecordException = true ;
46- } )
47- . AddSqlClientInstrumentation ( o =>
48- {
49- o . SetDbStatementForText = true ;
50- o . SetDbStatementForStoredProcedure = true ;
51- o . EnableConnectionLevelAttributes = true ;
52- o . RecordException = true ;
53- } )
54- . AddEntityFrameworkCoreInstrumentation ( o =>
55- {
56- o . SetDbStatementForText = true ;
57- o . SetDbStatementForStoredProcedure = true ;
58- } )
59-
60- // .SetSampler(new ParentBasedSampler(new TraceIdRatioBasedSampler(0.1))) // sample 10 % of root spans fully
61- ) ;
62-
63- services . AddOpenTelemetryMetrics ( b => b
64- . AddMeter ( serviceName )
65- . SetResourceBuilder ( resourceBuilder )
66- . AddOtlpExporter ( o =>
67- {
68- o . Endpoint = new Uri ( otlpEndpoint ) ;
69- o . Protocol = OtlpExportProtocol . Grpc ;
70- } )
71- . AddAspNetCoreInstrumentation ( )
72- . AddHttpClientInstrumentation ( )
32+ services . AddOpenTelemetry ( )
33+ . ConfigureResource ( r => r . AddService ( serviceName , serviceVersion , otlpEndpoint ) )
34+ . WithTracing ( b => b
35+ . AddOtlpExporter ( o =>
36+ {
37+ o . Endpoint = new Uri ( otlpEndpoint ) ;
38+ o . Protocol = OtlpExportProtocol . Grpc ;
39+ } )
40+ . AddAspNetCoreInstrumentation ( o => { o . RecordException = true ; } )
41+ . AddHttpClientInstrumentation ( o => { o . RecordException = true ; } )
42+ . AddSqlClientInstrumentation ( o =>
43+ {
44+ o . SetDbStatementForText = true ;
45+ o . SetDbStatementForStoredProcedure = true ;
46+ o . EnableConnectionLevelAttributes = true ;
47+ o . RecordException = true ;
48+ } )
49+ . AddEntityFrameworkCoreInstrumentation ( o =>
50+ {
51+ o . SetDbStatementForText = true ;
52+ o . SetDbStatementForStoredProcedure = true ;
53+ } ) )
54+ . WithMetrics ( b => b
55+ . AddOtlpExporter ( o =>
56+ {
57+ o . Endpoint = new Uri ( otlpEndpoint ) ;
58+ o . Protocol = OtlpExportProtocol . Grpc ;
59+ } )
60+ . AddAspNetCoreInstrumentation ( )
61+ . AddHttpClientInstrumentation ( )
7362
74- // Not stable yet, seems to cause some memory leaks
75- // .AddEventCounterMetrics(options =>
76- // {
77- // options.RefreshIntervalSecs = 10;
78- // })
79- . AddRuntimeInstrumentation ( )
80- ) ;
63+ // Not stable yet, seems to cause some memory leaks
64+ // .AddEventCounterMetrics(options =>
65+ // {
66+ // options.RefreshIntervalSecs = 10;
67+ // })
68+ . AddRuntimeInstrumentation ( )
69+ ) ;
8170
8271 services . AddLogging ( logging =>
8372 {
8473 logging . ClearProviders ( ) ;
85- logging . Configure ( options =>
86- {
87- options . ActivityTrackingOptions = ActivityTrackingOptions . SpanId | ActivityTrackingOptions . TraceId | ActivityTrackingOptions . ParentId | ActivityTrackingOptions . Baggage | ActivityTrackingOptions . Tags ;
88- } ) ;
74+ logging . Configure ( options => { options . ActivityTrackingOptions = ActivityTrackingOptions . SpanId | ActivityTrackingOptions . TraceId | ActivityTrackingOptions . ParentId | ActivityTrackingOptions . Baggage | ActivityTrackingOptions . Tags ; } ) ;
8975 logging . AddFilter ( "Microsoft.AspNetCore.*" , LogLevel . Warning ) ;
9076 logging . AddConsole ( ) ;
9177
@@ -111,4 +97,4 @@ public static class TelemetryExtensions
11197
11298 return services ;
11399 }
114- }
100+ }
0 commit comments