-
Notifications
You must be signed in to change notification settings - Fork 154
add Spring declarative config example #911
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
Draft
zeitlinger
wants to merge
3
commits into
open-telemetry:main
Choose a base branch
from
zeitlinger:spring-declarative-config
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from 2 commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| TODO |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| import org.gradle.kotlin.dsl.named | ||
| import org.springframework.boot.gradle.plugin.SpringBootPlugin | ||
| import org.springframework.boot.gradle.tasks.bundling.BootJar | ||
|
|
||
| plugins { | ||
| id("java") | ||
| id("org.springframework.boot") version "3.5.7" | ||
| } | ||
|
|
||
| description = "OpenTelemetry Example for Spring Boot with Declarative Configuration" | ||
|
|
||
| java { | ||
| toolchain { | ||
| languageVersion.set(JavaLanguageVersion.of(17)) | ||
| } | ||
| } | ||
|
|
||
| dependencies { | ||
| implementation(platform(SpringBootPlugin.BOM_COORDINATES)) | ||
| implementation(platform("io.opentelemetry.instrumentation:opentelemetry-instrumentation-bom:2.22.0")) | ||
| implementation("org.springframework.boot:spring-boot-starter-actuator") | ||
| implementation("org.springframework.boot:spring-boot-starter-web") | ||
| implementation("io.opentelemetry.instrumentation:opentelemetry-spring-boot-starter") | ||
| } | ||
|
|
||
| tasks.named<BootJar>("bootJar") { | ||
| archiveFileName = "spring-declarative-configuration.jar" | ||
| } | ||
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| FROM eclipse-temurin:21.0.9_10-jre@sha256:4332b7939ba5b7fabde48f4da21ebe45a4f8943d5b3319720c321ac577e65fb1 | ||
|
|
||
| WORKDIR /usr/src/app/ | ||
|
|
||
| ADD ./build/libs/spring-declarative-configuration.jar ./app.jar | ||
|
|
||
| EXPOSE 8080 | ||
| ENTRYPOINT [ "java", "-jar", "./app.jar" ] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| version: '3' | ||
| services: | ||
| app: | ||
| build: | ||
| context: ../ | ||
| dockerfile: oats/Dockerfile | ||
| environment: | ||
| OTEL_TRACER_PROVIDER_PROCESSORS_0_BATCH_EXPORTER_OTLP_HTTP_ENDPOINT: http://lgtm:4318/v1/traces | ||
| OTEL_METER_PROVIDER_READERS_0_PERIODIC_EXPORTER_OTLP_HTTP_ENDPOINT: http://lgtm:4318/v1/metrics | ||
| OTEL_LOGGER_PROVIDER_PROCESSORS_0_BATCH_EXPORTER_OTLP_HTTP_ENDPOINT: http://lgtm:4318/v1/logs | ||
| ports: | ||
| - "8080:8080" | ||
| healthcheck: | ||
| test: ["CMD", "curl", "-f", "http://localhost:8080/actuator/health"] | ||
| interval: 10s | ||
| timeout: 5s | ||
| retries: 3 | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| # OATS is an acceptance testing framework for OpenTelemetry - https://github.com/grafana/oats | ||
|
|
||
| docker-compose: | ||
| files: | ||
| - ./docker-compose.yml | ||
| app-service: app | ||
| app-docker-tag: javaagent-declarative-config:latest | ||
| app-docker-port: 8080 | ||
|
|
||
| input: | ||
| # This endpoint should be traced normally | ||
| - path: /api/example | ||
| # This endpoint should NOT be traced (excluded by declarative config) | ||
| # We send the request but don't assert spans for it - the absence of spans | ||
| # for /actuator/health demonstrates the sampling rule is working | ||
| - path: /actuator/health | ||
|
|
||
| expected: | ||
| traces: | ||
| # Verify that /api/example creates a trace with SERVER span | ||
| - traceql: '{ span.http.route = "/api/example" }' | ||
| spans: | ||
| - name: "GET /api/example" | ||
| attributes: | ||
| http.request.method: "GET" | ||
| http.route: "/api/example" |
21 changes: 21 additions & 0 deletions
21
...ative-configuration/src/main/java/io/opentelemetry/examples/fileconfig/ApiController.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| /* | ||
| * Copyright The OpenTelemetry Authors | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| */ | ||
|
|
||
| package io.opentelemetry.examples.fileconfig; | ||
|
|
||
| import org.springframework.http.ResponseEntity; | ||
| import org.springframework.web.bind.annotation.GetMapping; | ||
| import org.springframework.web.bind.annotation.RequestMapping; | ||
| import org.springframework.web.bind.annotation.RestController; | ||
|
|
||
| @RestController | ||
| @RequestMapping("/api") | ||
| public class ApiController { | ||
|
|
||
| @GetMapping("/example") | ||
| public ResponseEntity<String> example() { | ||
| return ResponseEntity.ok("Hello from OpenTelemetry example API!"); | ||
| } | ||
| } |
17 changes: 17 additions & 0 deletions
17
...arative-configuration/src/main/java/io/opentelemetry/examples/fileconfig/Application.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| /* | ||
| * Copyright The OpenTelemetry Authors | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| */ | ||
|
|
||
| package io.opentelemetry.examples.fileconfig; | ||
|
|
||
| import org.springframework.boot.SpringApplication; | ||
| import org.springframework.boot.autoconfigure.SpringBootApplication; | ||
|
|
||
| @SpringBootApplication | ||
| public class Application { | ||
|
|
||
| public static void main(String[] args) { | ||
| SpringApplication.run(Application.class, args); | ||
| } | ||
| } |
59 changes: 59 additions & 0 deletions
59
spring-declarative-configuration/src/main/resources/application.yaml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,59 @@ | ||
| otel: | ||
| # IMPORTANT: | ||
| # 1. The auto-suggested properties are not correct, because they are based on the non-declarative config schema. | ||
| # 2. Use https://github.com/open-telemetry/opentelemetry-configuration for details on schema and examples, but | ||
| # indent all examples by two spaces to fit under the "otel:" root node (for Spring Boot declarative config). | ||
|
|
||
| file_format: "1.0-rc.2" | ||
|
|
||
| resource: | ||
| attributes: | ||
| - name: service.name | ||
| value: spring-boot-declarative-config-example | ||
|
|
||
| propagator: | ||
| composite: | ||
| - tracecontext: | ||
| - baggage: | ||
|
|
||
| tracer_provider: | ||
| processors: | ||
| - batch: | ||
| exporter: | ||
| otlp_http: | ||
| endpoint: http://localhost:4318/v1/traces | ||
|
|
||
| # Configure a console exporter for exploring without a collector/backend | ||
| - batch: | ||
| exporter: | ||
| console: | ||
|
|
||
| # Configure sampling to exclude health check endpoints | ||
| sampler: | ||
| rule_based_routing: | ||
| fallback_sampler: | ||
| always_on: | ||
| # Filter to spans of this span_kind. Must be one of: SERVER, CLIENT, INTERNAL, CONSUMER, PRODUCER. | ||
| span_kind: SERVER # only apply to server spans | ||
| # List of rules describing spans to drop. Spans are dropped if they match one of the rules. | ||
| rules: | ||
| # The action to take when the rule is matches. Must be of: DROP, RECORD_AND_SAMPLE. | ||
| - action: DROP | ||
| # The span attribute to match against. | ||
| attribute: url.path | ||
| # The pattern to compare the span attribute to. | ||
| pattern: /actuator.* | ||
|
|
||
| meter_provider: | ||
| readers: | ||
| - periodic: | ||
| exporter: | ||
| otlp_http: | ||
| endpoint: http://localhost:4318/v1/metrics | ||
|
|
||
| logger_provider: | ||
| processors: | ||
| - batch: | ||
| exporter: | ||
| otlp_http: | ||
| endpoint: http://localhost:4318/v1/logs |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.