@@ -13,9 +13,9 @@ public static void AddOpentelemetry(this WebApplicationBuilder builder)
1313 var otelConfig = builder . Configuration . GetSection ( "OpenTelemetry" ) ;
1414 var otlpEndpoint = otelConfig [ "OtlpEndpoint" ] ;
1515
16- if ( string . IsNullOrEmpty ( otlpEndpoint ) )
16+ if ( ! Uri . TryCreate ( otlpEndpoint , UriKind . Absolute , out var validatedUri ) )
1717 {
18- Console . WriteLine ( " OpenTelemetry OtlpEndpoint is not configured . Skipping OpenTelemetry setup.") ;
18+ Console . WriteLine ( $ "Invalid OpenTelemetry OTLP endpoint URI: { otlpEndpoint } . Skipping OpenTelemetry setup.") ;
1919 return ;
2020 }
2121
@@ -38,7 +38,7 @@ public static void AddOpentelemetry(this WebApplicationBuilder builder)
3838
3939 options . AddOtlpExporter ( otlpOptions =>
4040 {
41- otlpOptions . Endpoint = new Uri ( otlpEndpoint ) ;
41+ otlpOptions . Endpoint = validatedUri ;
4242 otlpOptions . Headers = headers ;
4343 } ) ;
4444 } ) ;
@@ -57,7 +57,7 @@ public static void AddOpentelemetry(this WebApplicationBuilder builder)
5757 {
5858 providerBuilder . AddOtlpExporter ( otlpOptions =>
5959 {
60- otlpOptions . Endpoint = new Uri ( otlpEndpoint ) ;
60+ otlpOptions . Endpoint = validatedUri ;
6161 otlpOptions . Headers = headers ;
6262 } ) ;
6363 } )
@@ -68,7 +68,7 @@ public static void AddOpentelemetry(this WebApplicationBuilder builder)
6868 . AddHttpClientInstrumentation ( )
6969 . AddOtlpExporter ( otlpOptions =>
7070 {
71- otlpOptions . Endpoint = new Uri ( otlpEndpoint ) ;
71+ otlpOptions . Endpoint = validatedUri ;
7272 otlpOptions . Headers = headers ;
7373 } ) ;
7474 } ) ;
0 commit comments