Skip to content

Opentelemetry - #1963

Merged
dragoslav merged 5 commits into
masterfrom
opentelemetry
Nov 5, 2026
Merged

dragoslav merged 5 commits into
masterfrom
opentelemetry

Conversation

@dragoslav

Copy link
Copy Markdown
Collaborator

OpenTelemetry tracing

The in-memory runtime emits spans using OpenTelemetry when built through InMemoryBaker.

What is traced

  • Build lifecycle: baker.build
  • Recipe lifecycle: baker.recipe-instance.created
  • Event flow: baker.event.received, baker.event.fired
  • Interaction execution: baker.interaction.<interactionName>

Interaction spans are created as children of the latest event span for the same recipe instance.

Ambient context inside interactions

The interaction span is started on the very thread that invokes your interaction implementation, so
Span.current() and the SLF4J MDC are valid and belong to that invocation, also under heavy concurrency:

public class ValidateOrderImpl implements ValidateOrder {
    @Override
    public ValidateOrderOutcome apply(String recipeInstanceId, String order) {
        Span.current().addEvent("validating"); // the baker.interaction.ValidateOrder span
        log.info("validating"); // MDC contains trace_id, span_id and recipeInstanceId
        return new OrderValid();
    }
}

Baker runs interactions on a shared pool. Before and after every invocation the registered context propagators are
cleared, so a pooled thread can never expose the context of a previous execution. If your interaction spawns its own
threads, propagate the context explicitly (for example with Context.current().wrap(runnable)).

For a CompletableFuture-returning interaction the span is ended when the future completes; for a blocking
interaction it is ended when the method returns.

Common attributes

  • baker.recipe.id
  • baker.recipe.name
  • baker.recipe.instance.id

Depending on the span type, additional attributes are set:

  • baker.event.name
  • baker.interaction.name
  • baker.correlation.id
  • baker.failure.count
  • error.type (for failed interactions)

Injecting a custom tracer

By default, Baker uses GlobalOpenTelemetry.getTracer(...). You can provide your own tracer:

import com.ing.baker.runtime.inmemory.InMemoryBaker
import com.ing.baker.runtime.model.BakerConfig
import io.opentelemetry.api.GlobalOpenTelemetry

val tracer = GlobalOpenTelemetry.getTracer("my-service.baker")
val baker = InMemoryBaker.java(BakerConfig.default(), emptyList(), tracer)

For async Java factory usage:

val tracer = GlobalOpenTelemetry.getTracer("my-service.baker")
val bakerFuture = InMemoryBaker.javaAsync(BakerConfig.default(), emptyList(), tracer)

Where the OpenTelemetry code lives

The OpenTelemetry-specific code is isolated in the baker-interface-otel module:

  • OpenTelemetryContextPropagator — propagates the OTel Context to Baker's interaction pool. It is discovered
    automatically through META-INF/services, so simply having the module on the classpath is enough.
  • OpenTelemetryInteractionInstrumentation — starts, scopes and ends the baker.interaction.<name> span.
  • RecipeInstanceTraceContexts — per-baker mapping of recipe instance to the context the interaction span is parented to.

baker-interface itself stays free of OpenTelemetry. It only exposes the SPIs
com.ing.baker.runtime.model.propagation.ExecutionContextPropagator (propagate any thread-bound context) and
com.ing.baker.runtime.model.InteractionInstrumentation (wrap every interaction invocation), which you can implement
to plug in a different tracing or diagnostics stack.

@dragoslav
dragoslav marked this pull request as ready for review November 5, 2026 08:53
@dragoslav
dragoslav merged commit b9c3239 into master Nov 5, 2026
9 of 16 checks passed
@dragoslav
dragoslav deleted the opentelemetry branch November 5, 2026 10:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants