Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions contrib/temporal-opentelemetry-v2/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
description = '''Temporal Java SDK OpenTelemetry v2 Module'''

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Document how to install and configure the new module

This introduces a separately published, user-facing artifact without a README or usage guide, unlike the existing OpenTelemetry module. In particular, users are not shown the dependency declaration, how to construct and register ReplaySafeOpenTelemetry, how to attach the plugin, or how provider ownership and shutdown work, leaving the new module difficult to adopt safely.

AGENTS.md reference: AGENTS.md:L53-L57

Useful? React with 👍 / 👎.

@patbeqo patbeqo Sep 17, 2026

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A follow up PR on this stack will include the README.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Recommend closing this thread here in favor of the README that #3091 adds, with these gaps filled there: the Setup sample wires only a span exporter, so the Metrics and Logs sections export nothing as written; there is no mention of ReplaySafeOpenTelemetry.close() or of any flush path; the ordering constraint that the global must be set before building the plugin, setHeaderKey, setPropagators, the ContextStorageProvider caveat, the 48-bit entropy caveat, the observable-instrument caveat from the ReplaySafeMeter Javadoc, and the @Experimental status are all absent; and there are no Maven coordinates or a stated pinned OpenTelemetry version. I have left the README finding on #3091 directly.


ext {
otelVersion = '1.66.0'
}

dependencies {
api platform("io.opentelemetry:opentelemetry-bom:$otelVersion")

compileOnly project(':temporal-serviceclient')
compileOnly project(':temporal-sdk')
compileOnly "javax.annotation:javax.annotation-api:$annotationApiVersion"

implementation "com.google.guava:guava:$guavaVersion"

api "io.opentelemetry:opentelemetry-api"
api "io.opentelemetry:opentelemetry-sdk-trace"
api "io.opentelemetry:opentelemetry-sdk-metrics"
api "io.opentelemetry:opentelemetry-sdk-logs"
Comment thread
patbeqo marked this conversation as resolved.

testImplementation project(':temporal-sdk')
testImplementation project(':temporal-serviceclient')
testImplementation project(':temporal-testing')
testImplementation "io.opentelemetry:opentelemetry-sdk-testing"
testImplementation "junit:junit:${junitVersion}"

testRuntimeOnly group: 'ch.qos.logback', name: 'logback-classic', version: "${logbackVersion}"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package io.temporal.opentelemetry.v2;

import io.temporal.common.interceptors.ActivityClientCallsInterceptor;
import io.temporal.common.interceptors.ActivityClientInterceptorBase;
import io.temporal.opentelemetry.v2.internal.InterceptorTracer;
import io.temporal.opentelemetry.v2.internal.OpenTelemetryActivityClientCallsInterceptor;

public class OpenTelemetryActivityClientInterceptor extends ActivityClientInterceptorBase {
private final InterceptorTracer tracer;

public OpenTelemetryActivityClientInterceptor(InterceptorTracer tracer) {
this.tracer = tracer;
}

@Override
public ActivityClientCallsInterceptor activityClientCallsInterceptor(
ActivityClientCallsInterceptor next) {
return new OpenTelemetryActivityClientCallsInterceptor(tracer, next);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package io.temporal.opentelemetry.v2;

import io.temporal.common.interceptors.WorkflowClientCallsInterceptor;
import io.temporal.common.interceptors.WorkflowClientInterceptorBase;
import io.temporal.opentelemetry.v2.internal.InterceptorTracer;
import io.temporal.opentelemetry.v2.internal.OpenTelemetryWorkflowClientCallsInterceptor;

public class OpenTelemetryClientInterceptor extends WorkflowClientInterceptorBase {
private final InterceptorTracer tracer;

public OpenTelemetryClientInterceptor(InterceptorTracer tracer) {
this.tracer = tracer;
}

@Override
public WorkflowClientCallsInterceptor workflowClientCallsInterceptor(
WorkflowClientCallsInterceptor next) {
return new OpenTelemetryWorkflowClientCallsInterceptor(tracer, next);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package io.temporal.opentelemetry.v2;

import io.temporal.common.interceptors.NexusClientCallsInterceptor;
import io.temporal.common.interceptors.NexusClientInterceptorBase;
import io.temporal.opentelemetry.v2.internal.InterceptorTracer;
import io.temporal.opentelemetry.v2.internal.OpenTelemetryNexusClientCallsInterceptor;

public class OpenTelemetryNexusClientInterceptor extends NexusClientInterceptorBase {
private final InterceptorTracer tracer;

public OpenTelemetryNexusClientInterceptor(InterceptorTracer tracer) {
this.tracer = tracer;
}

@Override
public NexusClientCallsInterceptor nexusClientCallsInterceptor(NexusClientCallsInterceptor next) {
return new OpenTelemetryNexusClientCallsInterceptor(tracer, next);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
package io.temporal.opentelemetry.v2;

import io.temporal.common.Experimental;
import io.temporal.common.SimplePlugin;
import io.temporal.opentelemetry.v2.internal.InterceptorTracer;
import io.temporal.opentelemetry.v2.internal.OpenTelemetryContextPropagator;

/**
* OpenTelemetry v2 plugin for Temporal clients and workers.
*
* <p>Set it on {@code WorkflowServiceStubsOptions}, {@code WorkflowClientOptions}, or {@code
* WorkerFactoryOptions}. The SDK propagates plugins down that chain.
Comment thread
patbeqo marked this conversation as resolved.
*
* <p>Register a {@link ReplaySafeOpenTelemetry} with {@code GlobalOpenTelemetry.set} before calling
* {@link Builder#build()}.
*/
@Experimental
public final class OpenTelemetryPlugin extends SimplePlugin {
public static final String NAME = "io.temporal.opentelemetry.v2";

private OpenTelemetryPlugin(InterceptorTracer tracer) {
super(
SimplePlugin.newBuilder(NAME)
.addClientInterceptors(new OpenTelemetryClientInterceptor(tracer))
.addScheduleClientInterceptors(new OpenTelemetryScheduleClientInterceptor(tracer))
.addActivityClientInterceptors(new OpenTelemetryActivityClientInterceptor(tracer))
.addNexusClientInterceptors(new OpenTelemetryNexusClientInterceptor(tracer))
.addWorkerInterceptors(new OpenTelemetryWorkerInterceptor(tracer))
.addContextPropagators(new OpenTelemetryContextPropagator()));
}

public static Builder newBuilder() {
return new Builder();
}

/** Every option is optional; an unset one keeps its default. */
public static final class Builder {
private String headerKey = "_tracer-data";
private boolean addTemporalSpans;

private Builder() {}

/**
* The Temporal header key to serialize the span to. Defaults to {@code _tracer-data}, which
* Temporal uses; overriding it breaks trace continuity with workers using the standard key.
*/
public Builder setHeaderKey(String headerKey) {
this.headerKey = headerKey;
return this;
}

/**
* Whether to create spans for Temporal operations such as StartWorkflow, RunWorkflow, and
* RunActivity. Defaults to false: trace context still propagates through Temporal headers, so
* spans created by application code remain connected.
*/
public Builder setAddTemporalSpans(boolean addTemporalSpans) {
this.addTemporalSpans = addTemporalSpans;
return this;
}

public OpenTelemetryPlugin build() {
if (!ReplaySafeOpenTelemetry.isRegisteredGlobally()) {
throw new IllegalStateException(
"the global OpenTelemetry must be a ReplaySafeOpenTelemetry; build one with "
+ "ReplaySafeOpenTelemetry.newBuilder() and register it with "
+ "GlobalOpenTelemetry.set before building this plugin");
}
return new OpenTelemetryPlugin(new InterceptorTracer(headerKey, addTemporalSpans));
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package io.temporal.opentelemetry.v2;

import io.temporal.common.interceptors.ScheduleClientCallsInterceptor;
import io.temporal.common.interceptors.ScheduleClientInterceptorBase;
import io.temporal.opentelemetry.v2.internal.InterceptorTracer;
import io.temporal.opentelemetry.v2.internal.OpenTelemetryScheduleClientCallsInterceptor;

public class OpenTelemetryScheduleClientInterceptor extends ScheduleClientInterceptorBase {
private final InterceptorTracer tracer;

public OpenTelemetryScheduleClientInterceptor(InterceptorTracer tracer) {
this.tracer = tracer;
}

@Override
public ScheduleClientCallsInterceptor scheduleClientCallsInterceptor(
ScheduleClientCallsInterceptor next) {
return new OpenTelemetryScheduleClientCallsInterceptor(tracer, next);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package io.temporal.opentelemetry.v2;

import io.nexusrpc.handler.OperationContext;
import io.temporal.common.interceptors.ActivityInboundCallsInterceptor;
import io.temporal.common.interceptors.NexusOperationInboundCallsInterceptor;
import io.temporal.common.interceptors.WorkerInterceptor;
import io.temporal.common.interceptors.WorkflowInboundCallsInterceptor;
import io.temporal.opentelemetry.v2.internal.InterceptorTracer;
import io.temporal.opentelemetry.v2.internal.OpenTelemetryActivityInboundCallsInterceptor;
import io.temporal.opentelemetry.v2.internal.OpenTelemetryNexusOperationInboundCallsInterceptor;
import io.temporal.opentelemetry.v2.internal.OpenTelemetryWorkflowInboundCallsInterceptor;

public class OpenTelemetryWorkerInterceptor implements WorkerInterceptor {
private final InterceptorTracer tracer;

public OpenTelemetryWorkerInterceptor(InterceptorTracer tracer) {
this.tracer = tracer;
}

@Override
public WorkflowInboundCallsInterceptor interceptWorkflow(WorkflowInboundCallsInterceptor next) {
return new OpenTelemetryWorkflowInboundCallsInterceptor(tracer, next);
}

@Override
public ActivityInboundCallsInterceptor interceptActivity(ActivityInboundCallsInterceptor next) {
return new OpenTelemetryActivityInboundCallsInterceptor(tracer, next);
}

@Override
public NexusOperationInboundCallsInterceptor interceptNexusOperation(
OperationContext context, NexusOperationInboundCallsInterceptor next) {
return new OpenTelemetryNexusOperationInboundCallsInterceptor(tracer, next);
}
}
Loading
Loading