Skip to content

Commit d5c1492

Browse files
authored
update spring native example and show AutoConfigurationCustomizerProvider (#373)
1 parent 5a173df commit d5c1492

File tree

6 files changed

+26
-7
lines changed

6 files changed

+26
-7
lines changed

spring-native/README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ The example uses the following elements:
1111
the [OTLP receiver](https://github.com/open-telemetry/opentelemetry-collector/tree/main/receiver/otlpreceiver)
1212
and exporting to the standard output with
1313
the [logging exporter](https://github.com/open-telemetry/opentelemetry-collector/tree/main/exporter/loggingexporter).
14+
- A spring configuration to suppress spans for the `/actuator` endpoint
1415

1516
# Description of the instrumentation set-up
1617

@@ -147,4 +148,4 @@ spring-native-collector-1 | -> db.name: Str(db)
147148
spring-native-collector-1 | -> db.connection_string: Str(h2:mem:)
148149
spring-native-collector-1 | -> db.statement: Str(create table test_table (id bigint not null, primary key (id)))
149150
spring-native-collector-1 | -> db.system: Str(h2)
150-
```
151+
```

spring-native/build.gradle.kts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,12 @@ dependencies {
1313
implementation(platform(SpringBootPlugin.BOM_COORDINATES))
1414
implementation(platform("io.opentelemetry:opentelemetry-bom:1.36.0"))
1515
implementation(platform("io.opentelemetry.instrumentation:opentelemetry-instrumentation-bom-alpha:2.2.0-alpha"))
16+
implementation("org.springframework.boot:spring-boot-starter-actuator")
1617
implementation("org.springframework.boot:spring-boot-starter-web")
1718
implementation("org.springframework.boot:spring-boot-starter-data-jdbc")
1819
implementation("com.h2database:h2")
1920
implementation("io.opentelemetry.instrumentation:opentelemetry-spring-boot-starter")
21+
22+
// for otelCustomizer in Application.java
23+
implementation("io.opentelemetry.contrib:opentelemetry-samplers:1.33.0-alpha")
2024
}

spring-native/collector-spring-native-config.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
receivers:
22
otlp:
33
protocols:
4-
grpc:
4+
http:
55
exporters:
66
logging:
77
verbosity: detailed

spring-native/docker-compose.yml

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
1-
version: '3'
1+
version: '3.8'
22
services:
33
app:
44
image: otel-native-graalvm
55
environment:
66
OTEL_SERVICE_NAME: "graal-native-example-app"
7-
OTEL_EXPORTER_OTLP_ENDPOINT: "http://collector:4317"
8-
# Logs are disabled by default
9-
OTEL_LOGS_EXPORTER: "otlp"
7+
OTEL_EXPORTER_OTLP_ENDPOINT: "http://collector:4318"
108
ports:
119
- "8080:8080"
1210
depends_on:
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,27 @@
11
package io.opentelemetry.example.graal;
22

3+
import io.opentelemetry.api.trace.SpanKind;
4+
import io.opentelemetry.contrib.sampler.RuleBasedRoutingSampler;
5+
import io.opentelemetry.sdk.autoconfigure.spi.AutoConfigurationCustomizerProvider;
6+
import io.opentelemetry.semconv.SemanticAttributes;
37
import org.springframework.boot.SpringApplication;
48
import org.springframework.boot.autoconfigure.SpringBootApplication;
9+
import org.springframework.context.annotation.Bean;
510

611
@SpringBootApplication
712
public class Application {
813

914
public static void main(String[] args) {
1015
SpringApplication.run(Application.class, args);
1116
}
17+
18+
@Bean
19+
public AutoConfigurationCustomizerProvider otelCustomizer() {
20+
return p ->
21+
p.addSamplerCustomizer(
22+
(fallback, c) ->
23+
RuleBasedRoutingSampler.builder(SpanKind.SERVER, fallback)
24+
.drop(SemanticAttributes.URL_PATH, "^/actuator")
25+
.build());
26+
}
1227
}
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
spring.datasource.url=jdbc:otel:h2:mem:db
2-
spring.datasource.driver-class-name=io.opentelemetry.instrumentation.jdbc.OpenTelemetryDriver
2+
spring.datasource.driver-class-name=io.opentelemetry.instrumentation.jdbc.OpenTelemetryDriver
3+
management.endpoints.web.exposure.include=*

0 commit comments

Comments
 (0)