-
Notifications
You must be signed in to change notification settings - Fork 249
Add OpenTelemetry v2 plugin #3089
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| description = '''Temporal Java SDK OpenTelemetry v2 Module''' | ||
|
|
||
| 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" | ||
|
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}" | ||
| } | ||
20 changes: 20 additions & 0 deletions
20
...v2/src/main/java/io/temporal/opentelemetry/v2/OpenTelemetryActivityClientInterceptor.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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); | ||
| } | ||
| } |
20 changes: 20 additions & 0 deletions
20
...lemetry-v2/src/main/java/io/temporal/opentelemetry/v2/OpenTelemetryClientInterceptor.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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); | ||
| } | ||
| } |
19 changes: 19 additions & 0 deletions
19
...ry-v2/src/main/java/io/temporal/opentelemetry/v2/OpenTelemetryNexusClientInterceptor.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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); | ||
| } | ||
| } |
72 changes: 72 additions & 0 deletions
72
...oral-opentelemetry-v2/src/main/java/io/temporal/opentelemetry/v2/OpenTelemetryPlugin.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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. | ||
|
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)); | ||
| } | ||
| } | ||
| } | ||
20 changes: 20 additions & 0 deletions
20
...v2/src/main/java/io/temporal/opentelemetry/v2/OpenTelemetryScheduleClientInterceptor.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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); | ||
| } | ||
| } |
35 changes: 35 additions & 0 deletions
35
...lemetry-v2/src/main/java/io/temporal/opentelemetry/v2/OpenTelemetryWorkerInterceptor.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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); | ||
| } | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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 👍 / 👎.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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, theContextStorageProvidercaveat, the 48-bit entropy caveat, the observable-instrument caveat from theReplaySafeMeterJavadoc, and the@Experimentalstatus are all absent; and there are no Maven coordinates or a stated pinned OpenTelemetry version. I have left the README finding on #3091 directly.