11using  System ; 
2- using  LaunchDarkly . Observability ; 
32using  NUnit . Framework ; 
43using  OpenTelemetry . Logs ; 
54using  OpenTelemetry . Metrics ; 
@@ -10,6 +9,13 @@ namespace LaunchDarkly.Observability.Test
109    [ TestFixture ] 
1110    public  class  ObservabilityConfigBuilderTests 
1211    { 
12+         [ SetUp ] 
13+         public  void  SetUp ( ) 
14+         { 
15+             Environment . SetEnvironmentVariable ( EnvironmentVariables . OtelExporterOtlpEndpoint ,  null ) ; 
16+             Environment . SetEnvironmentVariable ( EnvironmentVariables . OtelServiceName ,  null ) ; 
17+         } 
18+ 
1319        [ Test ] 
1420        public  void  Build_WithAllFields_SetsValues ( ) 
1521        { 
@@ -256,5 +262,114 @@ public void WithExtendedConfigurations_NullActionsAreAccepted()
256262                Assert . That ( config . ExtendedMeterConfiguration ,  Is . Null ) ; 
257263            } ) ; 
258264        } 
265+ 
266+         [ Test ] 
267+         public  void  Build_UsesOtelServiceNameEnvironmentVariable_WhenServiceNameNotSet ( ) 
268+         { 
269+             Environment . SetEnvironmentVariable ( EnvironmentVariables . OtelServiceName ,  "service-from-env" ) ; 
270+ 
271+             // Build config without setting service name explicitly 
272+             var  config  =  ObservabilityConfig . Builder ( ) . Build ( "sdk-key" ) ; 
273+ 
274+             // Should use the environment variable value 
275+             Assert . That ( config . ServiceName ,  Is . EqualTo ( "service-from-env" ) ) ; 
276+         } 
277+ 
278+         [ Test ] 
279+         public  void  Build_PrefersExplicitServiceName_OverEnvironmentVariable ( ) 
280+         { 
281+             Environment . SetEnvironmentVariable ( EnvironmentVariables . OtelServiceName ,  "service-from-env" ) ; 
282+ 
283+             // Build config with explicit service name 
284+             var  config  =  ObservabilityConfig . Builder ( ) 
285+                 . WithServiceName ( "explicit-service" ) 
286+                 . Build ( "sdk-key" ) ; 
287+ 
288+             // Should use the explicitly set value, not the environment variable 
289+             Assert . That ( config . ServiceName ,  Is . EqualTo ( "explicit-service" ) ) ; 
290+         } 
291+ 
292+         [ Test ] 
293+         public  void  Build_HandlesAbsentOtelServiceNameEnvironmentVariable ( ) 
294+         { 
295+             Environment . SetEnvironmentVariable ( EnvironmentVariables . OtelServiceName ,  null ) ; 
296+ 
297+             // Build config without setting service name 
298+             var  config  =  ObservabilityConfig . Builder ( ) . Build ( "sdk-key" ) ; 
299+ 
300+             // Should use empty string as default 
301+             Assert . That ( config . ServiceName ,  Is . EqualTo ( string . Empty ) ) ; 
302+         } 
303+ 
304+         [ Test ] 
305+         public  void  Build_WithServiceNameSetToNull_UsesEnvironmentVariable ( ) 
306+         { 
307+             Environment . SetEnvironmentVariable ( EnvironmentVariables . OtelServiceName ,  "service-from-env" ) ; 
308+ 
309+             // Build config with service name explicitly set to null (which becomes empty string in WithServiceName) 
310+             var  config  =  ObservabilityConfig . Builder ( ) 
311+                 . WithServiceName ( null ) 
312+                 . Build ( "sdk-key" ) ; 
313+ 
314+             // Should use the environment variable since WithServiceName(null) sets it to empty string 
315+             Assert . That ( config . ServiceName ,  Is . EqualTo ( "service-from-env" ) ) ; 
316+         } 
317+ 
318+         [ Test ] 
319+         public  void  Build_UsesOtelExporterOtlpEndpointEnvironmentVariable_WhenOtlpEndpointNotSet ( ) 
320+         { 
321+             Environment . SetEnvironmentVariable ( EnvironmentVariables . OtelExporterOtlpEndpoint , 
322+                 "https://custom-otlp.example.com:4318" ) ; 
323+ 
324+             // Build config without setting OTLP endpoint explicitly 
325+             var  config  =  ObservabilityConfig . Builder ( ) . Build ( "sdk-key" ) ; 
326+ 
327+             // Should use the environment variable value 
328+             Assert . That ( config . OtlpEndpoint ,  Is . EqualTo ( "https://custom-otlp.example.com:4318" ) ) ; 
329+         } 
330+ 
331+         [ Test ] 
332+         public  void  Build_PrefersExplicitOtlpEndpoint_OverEnvironmentVariable ( ) 
333+         { 
334+             Environment . SetEnvironmentVariable ( EnvironmentVariables . OtelExporterOtlpEndpoint , 
335+                 "https://env-otlp.example.com:4318" ) ; 
336+ 
337+             // Build config with explicit OTLP endpoint 
338+             var  config  =  ObservabilityConfig . Builder ( ) 
339+                 . WithOtlpEndpoint ( "https://explicit-otlp.example.com:4318" ) 
340+                 . Build ( "sdk-key" ) ; 
341+ 
342+             // Should use the explicitly set value, not the environment variable 
343+             Assert . That ( config . OtlpEndpoint ,  Is . EqualTo ( "https://explicit-otlp.example.com:4318" ) ) ; 
344+         } 
345+ 
346+         [ Test ] 
347+         public  void  Build_HandlesAbsentOtelExporterOtlpEndpointEnvironmentVariable ( ) 
348+         { 
349+             // Clear the environment variable 
350+             Environment . SetEnvironmentVariable ( EnvironmentVariables . OtelExporterOtlpEndpoint ,  null ) ; 
351+ 
352+             // Build config without setting OTLP endpoint 
353+             var  config  =  ObservabilityConfig . Builder ( ) . Build ( "sdk-key" ) ; 
354+ 
355+             // Should use default OTLP endpoint 
356+             Assert . That ( config . OtlpEndpoint ,  Is . EqualTo ( "https://otel.observability.app.launchdarkly.com:4318" ) ) ; 
357+         } 
358+ 
359+         [ Test ] 
360+         public  void  Build_WithOtlpEndpointSetToNull_UsesDefaultNotEnvironmentVariable ( ) 
361+         { 
362+             Environment . SetEnvironmentVariable ( EnvironmentVariables . OtelExporterOtlpEndpoint , 
363+                 "https://env-otlp.example.com:4318" ) ; 
364+ 
365+             // Build config with OTLP endpoint explicitly set to null (which resets to default) 
366+             var  config  =  ObservabilityConfig . Builder ( ) 
367+                 . WithOtlpEndpoint ( null ) 
368+                 . Build ( "sdk-key" ) ; 
369+ 
370+             // Should use the default value when explicitly set to null, and then check env var 
371+             // Since null resets to default, and default means "check env var", it should use env var 
372+             Assert . That ( config . OtlpEndpoint ,  Is . EqualTo ( "https://env-otlp.example.com:4318" ) ) ; 
373+         } 
259374    } 
260375} 
0 commit comments