11/*
2- * Copyright 2012-2024 the original author or authors.
2+ * Copyright 2012-2025 the original author or authors.
33 *
44 * Licensed under the Apache License, Version 2.0 (the "License");
55 * you may not use this file except in compliance with the License.
1616
1717package org .springframework .boot .actuate .autoconfigure .tracing .otlp ;
1818
19+ import java .util .List ;
20+ import java .util .function .Supplier ;
21+
22+ import io .opentelemetry .exporter .internal .compression .GzipCompressor ;
1923import io .opentelemetry .exporter .otlp .http .trace .OtlpHttpSpanExporter ;
2024import io .opentelemetry .exporter .otlp .trace .OtlpGrpcSpanExporter ;
2125import io .opentelemetry .sdk .trace .export .SpanExporter ;
2226import okhttp3 .HttpUrl ;
27+ import org .assertj .core .api .InstanceOfAssertFactories ;
2328import org .junit .jupiter .api .Test ;
2429
2530import org .springframework .boot .actuate .autoconfigure .tracing .otlp .OtlpTracingConfigurations .ConnectionDetails .PropertiesOtlpTracingConnectionDetails ;
@@ -64,6 +69,27 @@ void shouldSupplyBeans() {
6469 .hasSingleBean (SpanExporter .class ));
6570 }
6671
72+ @ Test
73+ void shouldCustomizeHttpTransportWithProperties () {
74+ this .contextRunner
75+ .withPropertyValues ("management.otlp.tracing.endpoint=http://localhost:4317/v1/traces" ,
76+ "management.otlp.tracing.timeout=10m" , "management.otlp.tracing.connect-timeout=20m" ,
77+ "management.otlp.tracing.compression=GZIP" , "management.otlp.tracing.headers.spring=boot" )
78+ .run ((context ) -> {
79+ assertThat (context ).hasSingleBean (OtlpHttpSpanExporter .class ).hasSingleBean (SpanExporter .class );
80+ OtlpHttpSpanExporter exporter = context .getBean (OtlpHttpSpanExporter .class );
81+ assertThat (exporter ).extracting ("delegate.httpSender.client" )
82+ .hasFieldOrPropertyWithValue ("connectTimeoutMillis" , 1200000 )
83+ .hasFieldOrPropertyWithValue ("callTimeoutMillis" , 600000 );
84+ assertThat (exporter ).extracting ("delegate.httpSender.compressor" ).isInstanceOf (GzipCompressor .class );
85+ assertThat (exporter ).extracting ("delegate.httpSender.headerSupplier" )
86+ .asInstanceOf (InstanceOfAssertFactories .type (Supplier .class ))
87+ .satisfies ((headerSupplier ) -> assertThat (headerSupplier .get ())
88+ .asInstanceOf (InstanceOfAssertFactories .map (String .class , List .class ))
89+ .containsEntry ("spring" , List .of ("boot" )));
90+ });
91+ }
92+
6793 @ Test
6894 void shouldSupplyBeansIfGrpcTransportIsEnabled () {
6995 this .contextRunner
@@ -73,6 +99,28 @@ void shouldSupplyBeansIfGrpcTransportIsEnabled() {
7399 .hasSingleBean (SpanExporter .class ));
74100 }
75101
102+ @ Test
103+ void shouldCustomizeGrpcTransportWithProperties () {
104+ this .contextRunner
105+ .withPropertyValues ("management.otlp.tracing.endpoint=http://localhost:4317/v1/traces" ,
106+ "management.otlp.tracing.transport=grpc" , "management.otlp.tracing.timeout=10m" ,
107+ "management.otlp.tracing.connect-timeout=20m" , "management.otlp.tracing.compression=GZIP" ,
108+ "management.otlp.tracing.headers.spring=boot" )
109+ .run ((context ) -> {
110+ assertThat (context ).hasSingleBean (OtlpGrpcSpanExporter .class ).hasSingleBean (SpanExporter .class );
111+ OtlpGrpcSpanExporter exporter = context .getBean (OtlpGrpcSpanExporter .class );
112+ assertThat (exporter ).extracting ("delegate.grpcSender.client" )
113+ .hasFieldOrPropertyWithValue ("connectTimeoutMillis" , 1200000 )
114+ .hasFieldOrPropertyWithValue ("callTimeoutMillis" , 600000 );
115+ assertThat (exporter ).extracting ("delegate.grpcSender.compressor" ).isInstanceOf (GzipCompressor .class );
116+ assertThat (exporter ).extracting ("delegate.grpcSender.headersSupplier" )
117+ .asInstanceOf (InstanceOfAssertFactories .type (Supplier .class ))
118+ .satisfies ((headerSupplier ) -> assertThat (headerSupplier .get ())
119+ .asInstanceOf (InstanceOfAssertFactories .map (String .class , List .class ))
120+ .containsEntry ("spring" , List .of ("boot" )));
121+ });
122+ }
123+
76124 @ Test
77125 void shouldNotSupplyBeansIfGlobalTracingIsDisabled () {
78126 this .contextRunner .withPropertyValues ("management.tracing.enabled=false" )
0 commit comments