document span stacktrace (#1301)

This commit is contained in:
SylvainJuge 2024-05-14 21:09:23 +02:00 committed by GitHub
parent 64285c24ef
commit 4a6a3e0d71
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 31 additions and 0 deletions

View File

@ -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<ReadableSpan> 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