diff --git a/span-stacktrace/README.md b/span-stacktrace/README.md index b6ed35be..2cffbcb3 100644 --- a/span-stacktrace/README.md +++ b/span-stacktrace/README.md @@ -9,6 +9,37 @@ As a consequence it should only be used when the span duration is known, thus on However, the current SDK API does not allow to modify span attributes on span end, so we have to introduce other components to make it work as expected. +## Usage + +This extension does not support autoconfiguration because it needs to wrap the `SimpleSpanExporter` +or `BatchingSpanProcessor` that invokes the `SpanExporter`. + +As a consequence you have to use [Manual SDK setup](#manual-sdk-setup) +section below to configure it. + +### Manual SDK setup + +Here is an example registration of `StackTraceSpanProcessor` to capture stack trace for all +the spans that have a duration >= 1000 ns. The spans that have an `ignorespan` string attribute +will be ignored. + +```java +InMemorySpanExporter spansExporter = InMemorySpanExporter.create(); +SpanProcessor exportProcessor = SimpleSpanProcessor.create(spansExporter); + +Predicate filterPredicate = readableSpan -> { + if(readableSpan.getAttribute(AttributeKey.stringKey("ignorespan")) != null){ + return false; + } + return true; +}; +SdkTracerProvider tracerProvider = SdkTracerProvider.builder() + .addSpanProcessor(new StackTraceSpanProcessor(exportProcessor, 1000, filterPredicate)) + .build(); + +OpenTelemetrySdk sdk = OpenTelemetrySdk.builder().setTracerProvider(tracerProvider).build(); +``` + ## Component owners - [Jack Shirazi](https://github.com/jackshirazi), Elastic