Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update spring native example and show AutoConfigurationCustomizerProvider #373

Merged
merged 1 commit into from
Apr 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion spring-native/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ The example uses the following elements:
the [OTLP receiver](https://github.com/open-telemetry/opentelemetry-collector/tree/main/receiver/otlpreceiver)
and exporting to the standard output with
the [logging exporter](https://github.com/open-telemetry/opentelemetry-collector/tree/main/exporter/loggingexporter).
- A spring configuration to suppress spans for the `/actuator` endpoint

# Description of the instrumentation set-up

Expand Down Expand Up @@ -147,4 +148,4 @@ spring-native-collector-1 | -> db.name: Str(db)
spring-native-collector-1 | -> db.connection_string: Str(h2:mem:)
spring-native-collector-1 | -> db.statement: Str(create table test_table (id bigint not null, primary key (id)))
spring-native-collector-1 | -> db.system: Str(h2)
```
```
4 changes: 4 additions & 0 deletions spring-native/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,12 @@ dependencies {
implementation(platform(SpringBootPlugin.BOM_COORDINATES))
implementation(platform("io.opentelemetry:opentelemetry-bom:1.36.0"))
implementation(platform("io.opentelemetry.instrumentation:opentelemetry-instrumentation-bom-alpha:2.2.0-alpha"))
implementation("org.springframework.boot:spring-boot-starter-actuator")
implementation("org.springframework.boot:spring-boot-starter-web")
implementation("org.springframework.boot:spring-boot-starter-data-jdbc")
implementation("com.h2database:h2")
implementation("io.opentelemetry.instrumentation:opentelemetry-spring-boot-starter")

// for otelCustomizer in Application.java
implementation("io.opentelemetry.contrib:opentelemetry-samplers:1.33.0-alpha")
}
2 changes: 1 addition & 1 deletion spring-native/collector-spring-native-config.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
receivers:
otlp:
protocols:
grpc:
http:
exporters:
logging:
verbosity: detailed
Expand Down
6 changes: 2 additions & 4 deletions spring-native/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
version: '3'
version: '3.8'
services:
app:
image: otel-native-graalvm
environment:
OTEL_SERVICE_NAME: "graal-native-example-app"
OTEL_EXPORTER_OTLP_ENDPOINT: "http://collector:4317"
# Logs are disabled by default
OTEL_LOGS_EXPORTER: "otlp"
OTEL_EXPORTER_OTLP_ENDPOINT: "http://collector:4318"
ports:
- "8080:8080"
depends_on:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,27 @@
package io.opentelemetry.example.graal;

import io.opentelemetry.api.trace.SpanKind;
import io.opentelemetry.contrib.sampler.RuleBasedRoutingSampler;
import io.opentelemetry.sdk.autoconfigure.spi.AutoConfigurationCustomizerProvider;
import io.opentelemetry.semconv.SemanticAttributes;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Bean;

@SpringBootApplication
public class Application {

public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}

@Bean
public AutoConfigurationCustomizerProvider otelCustomizer() {
return p ->
p.addSamplerCustomizer(
(fallback, c) ->
RuleBasedRoutingSampler.builder(SpanKind.SERVER, fallback)
.drop(SemanticAttributes.URL_PATH, "^/actuator")
.build());
}
}
3 changes: 2 additions & 1 deletion spring-native/src/main/resources/application.properties
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
spring.datasource.url=jdbc:otel:h2:mem:db
spring.datasource.driver-class-name=io.opentelemetry.instrumentation.jdbc.OpenTelemetryDriver
spring.datasource.driver-class-name=io.opentelemetry.instrumentation.jdbc.OpenTelemetryDriver
management.endpoints.web.exposure.include=*