Skip to content

Commit fc433af

Browse files
lbloderadinauer
andauthored
Add documentation on setting SpanKind and capture HttpHeaders with OTEL (#12328)
* wip add docs for capturing http headers as well as manual instrumentation using opentelemetry * Update docs/platforms/java/common/tracing/instrumentation/opentelemetry.mdx Co-authored-by: Alexander Dinauer <[email protected]> --------- Co-authored-by: Alexander Dinauer <[email protected]>
1 parent 88b9d16 commit fc433af

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed

docs/platforms/java/common/tracing/instrumentation/opentelemetry.mdx

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,39 @@ You'll have to configure both OpenTelemetry and Sentry to see transactions in Se
6969

7070
With Sentry’s OpenTelemetry SDK, an OpenTelemetry `Span` becomes a Sentry `Transaction` or `Span`. The first `Span` sent through the Sentry `SpanProcessor` is a `Transaction`, and any child `Span` gets attached to the first `Transaction` upon checking the parent `Span` context. This is true for the OpenTelemetry root `Span` and any top level `Span` in the system. For example, a request sent from frontend to backend will create an OpenTelemetry root `Span` with a corresponding Sentry `Transaction`. The backend request will create a new Sentry `Transaction` for the OpenTelemetry `Span`. The Sentry `Transaction` and `Span` are linked as a trace for navigation and error tracking purposes.
7171

72+
### Manual Instrumentation with OpenTelemetry
73+
74+
If you have the OpenTelemetry SDK in you classpath, you can also instrument your code manually using the OpenTelemetry API as documented [in the OpenTelemetry docs](https://opentelemetry.io/docs/languages/java/api/#span).
75+
76+
A manually created span for HTTP requests needs to declare its `SpanKind` as well as the `HttpAttributes.HTTP_REQUEST_METHOD` attribute, so that `Sentry` can correctly process these:
77+
78+
```java {tabTitle:Java}
79+
Span span = tracer.spanBuilder("myspan")
80+
.setAttribute(HTTP_REQUEST_METHOD, "GET")
81+
.setSpanKind(SpanKind.SERVER)
82+
.startSpan();
83+
```
84+
```kotlin {tabTitle:Kotlin}
85+
val span = tracer.spanBuilder("myspan")
86+
.setAttribute(HTTP_REQUEST_METHOD, "GET")
87+
.setSpanKind(SpanKind.SERVER)
88+
.startSpan()
89+
```
90+
91+
### Capturing HTTP Headers
92+
93+
By default OpenTelemetry does not capture any HTTP headers. This, however, can be configured using system properties or environment variables as per OpenTelemetry's configuration documentation [here](https://opentelemetry.io/docs/zero-code/java/agent/instrumentation/http/#capturing-http-request-and-response-headers). Each variable is a comma-separated list of HTTP header names that should be captured.
94+
95+
#### Client variables
96+
97+
- `OTEL_INSTRUMENTATION_HTTP_CLIENT_CAPTURE_REQUEST_HEADERS`
98+
- `OTEL_INSTRUMENTATION_HTTP_CLIENT_CAPTURE_RESPONSE_HEADERS`
99+
100+
#### Server variables
101+
102+
- `OTEL_INSTRUMENTATION_HTTP_SERVER_CAPTURE_REQUEST_HEADERS`
103+
- `OTEL_INSTRUMENTATION_HTTP_SERVER_CAPTURE_RESPONSE_HEADERS`
104+
72105
## Additional Configuration
73106

74107
If you need more fine grained control over Sentry, take a look at the <PlatformLink to="/configuration/">Configuration page</PlatformLink>. In case you'd like to filter out transactions before sending them to Sentry (to get rid of health checks, for example), you may find the <PlatformLink to="/configuration/filtering/#filtering-transaction-events">Filtering page</PlatformLink> helpful.

0 commit comments

Comments
 (0)