open-telemetry / open-telemetry/opentelemetry-java-examples
Missing examples with reactive programming (reactor)
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 355
- Forks
- 160
- Avg merge
- 1d 8m
- Merged PRs (30d)
- 19
Description
Hi,
Examples provided in Manual span creation and baggage propagation are only available with imperative programming. Is it possible to extend those examples to reactive programming ?
Zero-code instrumentation with opentelemetry agent specifies compatibility with reactor library https://github.com/open-telemetry/opentelemetry-java-instrumentation/blob/main/docs/supported-libraries.md#libraries--frameworks, however I didn't find any examples here or in https://opentelemetry.io/docs/ on how to do manual instrumentation on reactive code with reactor.
I would like to execute following actions in reactor operators
- Create span and make it current
- Inject attribute to current span
- Inject baggage and make it current
As for now, I can only "guess" how I should do in reactive programming, by "translating" imperative examples I have found with reactor equivalents.
For example I translate following imperative code
public String imperativeFoo() {
try (Scope scope1 = tracer.spanBuilder("foo").startSpan().makeCurrent()) {
Span.current().setAttribute("fooAttribute", "fooAttributeValue");
Baggage baggage = Baggage.current().toBuilder()
.put("fooBaggage", "fooBaggageValue")
.build();
try (Scope scope2 = baggage.makeCurrent()) {
return bar();
}
}
}
private String bar() {
// returns "bar:fooBaggageValue"
return "bar:" + Baggage.current().getEntryValue("fooBaggage");
}
into
public Mono<String> reactiveFoo() {
return Mono.using(
() -> tracer.spanBuilder("foo").startSpan().makeCurrent(),
scope1 ->
Mono.fromSupplier(() -> Baggage.current().toBuilder().put("fooBaggage", "fooBaggageValue").build())
.doOnNext(baggage -> Span.current().setAttribute("fooAttribute", "fooAttributeValue"))
.flatMap(baggage ->
Mono.using(
baggage::makeCurrent,
scope2 -> Mono.fromSupplier(this::bar))));
}
private String bar() {
// returns "bar:fooBaggageValue"
return "bar:" + Baggage.current().getEntryValue("fooBaggage");
}
But is it the right way to do it ? If yes, could you please add this example to the documentation ?
Did I miss some other documentation on it somewhere ?
Thanks
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the examples in the manual-tracing directory and compare them with the Reactor compatibility noted in supported-libraries.md and the OpenTelemetry documentation. Verify whether the proposed Mono-based scope and baggage handling is correct, then add a reactive manual-instrumentation example if the repository has a suitable documentation location. Done means the example clearly demonstrates the three requested actions and its behavior is documented.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java
- Domain
- documentation
- Issue type
- Documentation
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100