1
1
/*
2
- * Copyright 2012-2024 the original author or authors.
2
+ * Copyright 2012-2025 the original author or authors.
3
3
*
4
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
5
* you may not use this file except in compliance with the License.
16
16
17
17
package org .springframework .boot .actuate .autoconfigure .tracing .otlp ;
18
18
19
+ import java .util .List ;
20
+ import java .util .function .Supplier ;
21
+
22
+ import io .opentelemetry .exporter .internal .compression .GzipCompressor ;
19
23
import io .opentelemetry .exporter .otlp .http .trace .OtlpHttpSpanExporter ;
20
24
import io .opentelemetry .exporter .otlp .trace .OtlpGrpcSpanExporter ;
21
25
import io .opentelemetry .sdk .trace .export .SpanExporter ;
22
26
import okhttp3 .HttpUrl ;
27
+ import org .assertj .core .api .InstanceOfAssertFactories ;
23
28
import org .junit .jupiter .api .Test ;
24
29
25
30
import org .springframework .boot .actuate .autoconfigure .tracing .otlp .OtlpTracingConfigurations .ConnectionDetails .PropertiesOtlpTracingConnectionDetails ;
@@ -64,6 +69,27 @@ void shouldSupplyBeans() {
64
69
.hasSingleBean (SpanExporter .class ));
65
70
}
66
71
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
+
67
93
@ Test
68
94
void shouldSupplyBeansIfGrpcTransportIsEnabled () {
69
95
this .contextRunner
@@ -73,6 +99,28 @@ void shouldSupplyBeansIfGrpcTransportIsEnabled() {
73
99
.hasSingleBean (SpanExporter .class ));
74
100
}
75
101
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
+
76
124
@ Test
77
125
void shouldNotSupplyBeansIfGlobalTracingIsDisabled () {
78
126
this .contextRunner .withPropertyValues ("management.tracing.enabled=false" )
0 commit comments