From e3243bd44479992a2dbfee7fe6d88619421b47af Mon Sep 17 00:00:00 2001 From: SylvainJuge <763082+SylvainJuge@users.noreply.github.com> Date: Mon, 2 Sep 2024 16:07:28 +0200 Subject: [PATCH] span stacktraces config (without aligning with upstream) (#369) --- README.md | 5 ++++- .../co/elastic/otel/SpanStackTraceProcessorAutoConfig.java | 3 ++- docs/configure.md | 2 +- inferred-spans/README.md | 3 +-- .../example/javaagent/smoketest/AgentFeaturesSmokeTest.java | 2 +- 5 files changed, 9 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 971688bc..f9419bfd 100644 --- a/README.md +++ b/README.md @@ -69,7 +69,10 @@ The agent captures the stacktraces of spans to help identify code paths that tri The stacktrace is stored in the [`code.stacktrace`](https://opentelemetry.io/docs/specs/semconv/attributes-registry/code/) attribute. -The minimum span duration can be configured with `elastic.otel.span.stack.trace.min.duration` (in milliseconds, defaults to 5ms). +The minimum span duration can be configured with `elastic.otel.java.span-stacktrace.min.duration` (defaults to `5ms`). + +Implementation has been contributed upstream in the [opentelemetry-java-contrib](https://github.com/open-telemetry/opentelemetry-java-contrib) repository, +in the [`span-stacktrace`](https://github.com/open-telemetry/opentelemetry-java-contrib/tree/main/span-stacktrace) folder. ### Runtime metrics diff --git a/custom/src/main/java/co/elastic/otel/SpanStackTraceProcessorAutoConfig.java b/custom/src/main/java/co/elastic/otel/SpanStackTraceProcessorAutoConfig.java index 0b291bc2..9c0bbf7b 100644 --- a/custom/src/main/java/co/elastic/otel/SpanStackTraceProcessorAutoConfig.java +++ b/custom/src/main/java/co/elastic/otel/SpanStackTraceProcessorAutoConfig.java @@ -29,7 +29,8 @@ @AutoService(ChainingSpanProcessorAutoConfiguration.class) public class SpanStackTraceProcessorAutoConfig implements ChainingSpanProcessorAutoConfiguration { - static final String MIN_DURATION_CONFIG_OPTION = "elastic.otel.span.stack.trace.min.duration"; + // TODO replace this with upstream config once it's stable + static final String MIN_DURATION_CONFIG_OPTION = "elastic.otel.java.span-stacktrace.min.duration"; @Override public void registerSpanProcessors( diff --git a/docs/configure.md b/docs/configure.md index 8f6b1e7b..ad0285c9 100644 --- a/docs/configure.md +++ b/docs/configure.md @@ -91,7 +91,6 @@ EDOT Java includes several OpenTelemetry extensions from the [OpenTelemetry Java |---|---|---| | `OTEL_SERVICE_NAME` | [Resource providers](https://github.com/open-telemetry/opentelemetry-java-contrib/tree/main/resource-providers) | This can be [set as usual](https://opentelemetry.io/docs/languages/sdk-configuration/general/#otel_service_name), but if not set the value will be inferred when the EDOT Java agent is running in various application servers. | | `OTEL_INFERRED_SPANS_*` | [Inferred Spans](https://github.com/open-telemetry/opentelemetry-java-contrib/tree/main/inferred-spans) | Generates additional spans using profiling instead of instrumentation. | -| `OTEL_SPAN_STACK_TRACE_MIN_DURATION` | [Span stacktrace capture](https://github.com/open-telemetry/opentelemetry-java-contrib/tree/main/span-stacktrace) | Define the minimum duration (in milliseconds) for attaching stack traces to spans. Defaults to 5ms. | ### Configuration options that are _only_ available in EDOT Java @@ -110,6 +109,7 @@ _Currently there are no additional `OTEL_` options waiting to be contributed ups | Option(s) | Extension | Description | |---|---|---| | `ELASTIC_OTEL_UNIVERSAL_PROFILING_INTEGRATION_*` | [Universal profiling integration](https://github.com/elastic/elastic-otel-java/tree/main/universal-profiling-integration) | Correlates traces with profiling data from the Elastic universal profiler. | +| `ELASTIC_OTEL_JAVA_SPAN_STACKTRACE_MIN_DURATION` | [Span stacktrace capture](https://github.com/open-telemetry/opentelemetry-java-contrib/tree/main/span-stacktrace) | Define the minimum duration for attaching stack traces to spans. Defaults to 5ms. | ## Authentication methods diff --git a/inferred-spans/README.md b/inferred-spans/README.md index 33f28c15..51140848 100644 --- a/inferred-spans/README.md +++ b/inferred-spans/README.md @@ -56,8 +56,7 @@ SdkTracerProvider tracerProvider = SdkTracerProvider.builder() .addSpanProcessor(BatchSpanProcessor.builder(OtlpGrpcSpanExporter.builder() .setEndpoint("https://.apm.europe-west3.gcp.cloud.es.io:443") .addHeader("Authorization", "Bearer >") - .build())) - .build(); + .build())).build(); inferredSpans.setTracerProvider(tracerProvider); ``` diff --git a/smoke-tests/src/test/java/com/example/javaagent/smoketest/AgentFeaturesSmokeTest.java b/smoke-tests/src/test/java/com/example/javaagent/smoketest/AgentFeaturesSmokeTest.java index 44b77383..96af1e10 100644 --- a/smoke-tests/src/test/java/com/example/javaagent/smoketest/AgentFeaturesSmokeTest.java +++ b/smoke-tests/src/test/java/com/example/javaagent/smoketest/AgentFeaturesSmokeTest.java @@ -33,7 +33,7 @@ class AgentFeaturesSmokeTest extends TestAppSmokeTest { @BeforeAll public static void start() { startTestApp( - (container) -> container.addEnv("ELASTIC_OTEL_SPAN_STACK_TRACE_MIN_DURATION", "0ms")); + (container) -> container.addEnv("ELASTIC_OTEL_JAVA_SPAN_STACKTRACE_MIN_DURATION", "0ms")); } @AfterAll