Skip to content

Commit

Permalink
Context propagation between Java threads (#4097)
Browse files Browse the repository at this point in the history
Co-authored-by: Phillip Carter <[email protected]>
  • Loading branch information
jeanbisutti and cartermp authored Mar 10, 2024
1 parent bbadab9 commit 28d219b
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions content/en/docs/languages/java/instrumentation.md
Original file line number Diff line number Diff line change
Expand Up @@ -973,6 +973,25 @@ OpenTelemetry provides a text-based approach to propagate context to remote
services using the [W3C Trace Context](https://www.w3.org/TR/trace-context/)
HTTP headers.

### Context propagation between threads

THe following example demonstrates how to propagate the context between threads:

```java
io.opentelemetry.context.Context context = io.opentelemetry.context.Context.current();
Thread thread = new Thread(new Runnable() {
@Override
public void run() {
try (Scope scope = context.makeCurrent()) {
// Code for which you want to propagate the context
}
}
});
thread.start();
```

### Context propagation between HTTP requests

The following presents an example of an outgoing HTTP request using
`HttpURLConnection`.

Expand Down

0 comments on commit 28d219b

Please sign in to comment.