16
16
17
17
package org .springframework .boot .actuate .autoconfigure .tracing .otlp ;
18
18
19
+ import java .util .List ;
19
20
import java .util .function .Supplier ;
20
21
21
22
import io .opentelemetry .api .metrics .MeterProvider ;
23
+ import io .opentelemetry .exporter .internal .compression .GzipCompressor ;
22
24
import io .opentelemetry .exporter .otlp .http .trace .OtlpHttpSpanExporter ;
23
25
import io .opentelemetry .exporter .otlp .http .trace .OtlpHttpSpanExporterBuilder ;
24
26
import io .opentelemetry .exporter .otlp .trace .OtlpGrpcSpanExporter ;
25
27
import io .opentelemetry .exporter .otlp .trace .OtlpGrpcSpanExporterBuilder ;
26
28
import io .opentelemetry .sdk .trace .export .SpanExporter ;
27
29
import okhttp3 .HttpUrl ;
30
+ import org .assertj .core .api .InstanceOfAssertFactories ;
28
31
import org .junit .jupiter .api .Test ;
29
32
30
33
import org .springframework .boot .actuate .autoconfigure .tracing .otlp .OtlpTracingConfigurations .ConnectionDetails .PropertiesOtlpTracingConnectionDetails ;
@@ -70,6 +73,27 @@ void shouldSupplyBeans() {
70
73
.hasSingleBean (SpanExporter .class ));
71
74
}
72
75
76
+ @ Test
77
+ void shouldCustomizeHttpTransportWithProperties () {
78
+ this .contextRunner
79
+ .withPropertyValues ("management.otlp.tracing.endpoint=http://localhost:4317/v1/traces" ,
80
+ "management.otlp.tracing.timeout=10m" , "management.otlp.tracing.connect-timeout=20m" ,
81
+ "management.otlp.tracing.compression=GZIP" , "management.otlp.tracing.headers.spring=boot" )
82
+ .run ((context ) -> {
83
+ assertThat (context ).hasSingleBean (OtlpHttpSpanExporter .class ).hasSingleBean (SpanExporter .class );
84
+ OtlpHttpSpanExporter exporter = context .getBean (OtlpHttpSpanExporter .class );
85
+ assertThat (exporter ).extracting ("delegate.httpSender.client" )
86
+ .hasFieldOrPropertyWithValue ("connectTimeoutMillis" , 1200000 )
87
+ .hasFieldOrPropertyWithValue ("callTimeoutMillis" , 600000 );
88
+ assertThat (exporter ).extracting ("delegate.httpSender.compressor" ).isInstanceOf (GzipCompressor .class );
89
+ assertThat (exporter ).extracting ("delegate.httpSender.headerSupplier" )
90
+ .asInstanceOf (InstanceOfAssertFactories .type (Supplier .class ))
91
+ .satisfies ((headerSupplier ) -> assertThat (headerSupplier .get ())
92
+ .asInstanceOf (InstanceOfAssertFactories .map (String .class , List .class ))
93
+ .containsEntry ("spring" , List .of ("boot" )));
94
+ });
95
+ }
96
+
73
97
@ Test
74
98
void shouldSupplyBeansIfGrpcTransportIsEnabled () {
75
99
this .contextRunner
@@ -79,6 +103,28 @@ void shouldSupplyBeansIfGrpcTransportIsEnabled() {
79
103
.hasSingleBean (SpanExporter .class ));
80
104
}
81
105
106
+ @ Test
107
+ void shouldCustomizeGrpcTransportWithProperties () {
108
+ this .contextRunner
109
+ .withPropertyValues ("management.otlp.tracing.endpoint=http://localhost:4317/v1/traces" ,
110
+ "management.otlp.tracing.transport=grpc" , "management.otlp.tracing.timeout=10m" ,
111
+ "management.otlp.tracing.connect-timeout=20m" , "management.otlp.tracing.compression=GZIP" ,
112
+ "management.otlp.tracing.headers.spring=boot" )
113
+ .run ((context ) -> {
114
+ assertThat (context ).hasSingleBean (OtlpGrpcSpanExporter .class ).hasSingleBean (SpanExporter .class );
115
+ OtlpGrpcSpanExporter exporter = context .getBean (OtlpGrpcSpanExporter .class );
116
+ assertThat (exporter ).extracting ("delegate.grpcSender.client" )
117
+ .hasFieldOrPropertyWithValue ("connectTimeoutMillis" , 1200000 )
118
+ .hasFieldOrPropertyWithValue ("callTimeoutMillis" , 600000 );
119
+ assertThat (exporter ).extracting ("delegate.grpcSender.compressor" ).isInstanceOf (GzipCompressor .class );
120
+ assertThat (exporter ).extracting ("delegate.grpcSender.headersSupplier" )
121
+ .asInstanceOf (InstanceOfAssertFactories .type (Supplier .class ))
122
+ .satisfies ((headerSupplier ) -> assertThat (headerSupplier .get ())
123
+ .asInstanceOf (InstanceOfAssertFactories .map (String .class , List .class ))
124
+ .containsEntry ("spring" , List .of ("boot" )));
125
+ });
126
+ }
127
+
82
128
@ Test
83
129
void shouldNotSupplyBeansIfGlobalTracingIsDisabled () {
84
130
this .contextRunner .withPropertyValues ("management.tracing.enabled=false" )
0 commit comments