Repository navigation
feat: add unified OTel plugin factory #873
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
Merged
zhongkechen
merged 6 commits into
aws:main
from
zhongkechen:feat/unified-otel-factory-872
Nov 4, 2026
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
1bbb680
feat: add unified OTel plugin factory
zhongkechen 7f2c3a1
test: trim unified OTel registration coverage
zhongkechen b086e24
fix: name OTel entry points in exclusive-group conflicts
zhongkechen bf917b2
test: verify the correct OTel MDC key
zhongkechen bde233b
Merge branch 'main' into feat/unified-otel-factory-872
zhongkechen 3067d6c
refactor: share OTel provider delegation and clarify registration docs
zhongkechen 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
43 changes: 43 additions & 0 deletions
43
...lugin/src/main/java/software/amazon/lambda/durable/otel/DelegatingOtelPluginProvider.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,43 @@ | ||
| // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
| package software.amazon.lambda.durable.otel; | ||
|
|
||
| import software.amazon.lambda.durable.plugin.DurableExecutionPlugin; | ||
| import software.amazon.lambda.durable.plugin.DurableExecutionPluginFactory; | ||
| import software.amazon.lambda.durable.plugin.DurableExecutionPluginProvider; | ||
| import software.amazon.lambda.durable.plugin.InvocationInfo; | ||
|
|
||
| /** Delegates a named ServiceLoader entry to its view's per-invocation factory. */ | ||
| final class DelegatingOtelPluginProvider implements DurableExecutionPluginProvider { | ||
| private final String name; | ||
| private final DurableExecutionPluginFactory factory; | ||
|
|
||
| DelegatingOtelPluginProvider(String name, DurableExecutionPluginFactory factory) { | ||
| this.name = name; | ||
| this.factory = factory; | ||
| } | ||
|
|
||
| @Override | ||
| public String getName() { | ||
| return name; | ||
| } | ||
|
|
||
| @Override | ||
| public DurableExecutionPlugin createPlugin(InvocationInfo invocationInfo) { | ||
| return factory.createPlugin(invocationInfo); | ||
| } | ||
|
|
||
| @Override | ||
| public String getExclusiveGroup() { | ||
| return factory.getExclusiveGroup(); | ||
| } | ||
|
|
||
| /** | ||
| * Names the selected entry and the view it loads, so an exclusive-group conflict reports the | ||
| * {@code DURABLE_EXECUTION_PLUGINS} value the operator set rather than an object identity hash. | ||
| */ | ||
| @Override | ||
| public String toString() { | ||
| return getName() + " (" + factory + ")"; | ||
| } | ||
| } |
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
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
87 changes: 87 additions & 0 deletions
87
otel-plugin/src/main/java/software/amazon/lambda/durable/otel/OtelPlugin.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,87 @@ | ||
| // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
| package software.amazon.lambda.durable.otel; | ||
|
|
||
| import static java.util.Objects.requireNonNull; | ||
|
|
||
| import io.opentelemetry.sdk.trace.SdkTracerProviderBuilder; | ||
| import software.amazon.lambda.durable.plugin.DurableExecutionPluginFactory; | ||
|
|
||
| /** | ||
| * Selects the OpenTelemetry view to register with a durable handler. Execution mode is the default; invocation mode | ||
| * places durable operations under their Lambda invocation instead of the Workflow span. | ||
| * | ||
| * <pre>{@code | ||
| * DurableConfig.builder().withPlugins(OtelPlugin.factory()).build(); | ||
| * DurableConfig.builder().withPlugins(OtelPlugin.factory(OtelPlugin.Mode.INVOCATION)).build(); | ||
| * }</pre> | ||
| * | ||
| * <p>Each call returns a new factory of the selected view's type, carrying that view's configuration and | ||
| * exclusive-group metadata; the returned factory then creates a fresh plugin for every invocation. Calls are not | ||
| * memoized, so registering two of them puts two factories in one exclusive group and | ||
| * {@code DurableConfig.builder().build()} rejects the configuration. The existing execution and invocation factory APIs | ||
| * remain supported. Default configuration uses the global provider configured by ADOT or the application; exporters and | ||
| * provider setup remain the application's responsibility. | ||
| * | ||
| * <p>{@link #factory()} covers the zero-configuration default. Every call that passes configuration or a provider | ||
| * builder names its {@link Mode}, so the selected view is explicit wherever it is not the bare default. | ||
| */ | ||
| public final class OtelPlugin { | ||
| private OtelPlugin() {} | ||
|
|
||
| /** The hierarchy used for durable operation spans. */ | ||
| public enum Mode { | ||
| /** Durable operations are children of the Workflow span. */ | ||
| EXECUTION, | ||
| /** Durable operations are children of their Invocation span. */ | ||
| INVOCATION | ||
| } | ||
|
|
||
| /** @return an execution-view factory using the global provider and default configuration */ | ||
| public static DurableExecutionPluginFactory factory() { | ||
| return factory(Mode.EXECUTION); | ||
| } | ||
|
|
||
| /** | ||
| * @param mode the view to select; must not be null | ||
| * @return a factory using the global provider and default configuration | ||
| */ | ||
| public static DurableExecutionPluginFactory factory(Mode mode) { | ||
| return factory(mode, OtelPluginConfig.defaults()); | ||
| } | ||
|
|
||
| /** | ||
| * @param mode the view to select; must not be null | ||
| * @param config configuration passed to the selected factory | ||
| * @return a factory using the global provider | ||
| */ | ||
| public static DurableExecutionPluginFactory factory(Mode mode, OtelPluginConfig config) { | ||
| return switch (requireNonNull(mode, "mode must not be null")) { | ||
| case EXECUTION -> ExecutionOtelPlugin.factory(config); | ||
| case INVOCATION -> InvocationOtelPlugin.factory(config); | ||
| }; | ||
| } | ||
|
|
||
| /** | ||
| * @param mode the view to select; must not be null | ||
| * @param tracerProviderBuilder application-owned provider builder | ||
| * @return a factory using default configuration | ||
| */ | ||
| public static DurableExecutionPluginFactory factory(Mode mode, SdkTracerProviderBuilder tracerProviderBuilder) { | ||
| return factory(mode, tracerProviderBuilder, OtelPluginConfig.defaults()); | ||
| } | ||
|
|
||
| /** | ||
| * @param mode the view to select; must not be null | ||
| * @param tracerProviderBuilder application-owned provider builder | ||
| * @param config configuration passed to the selected factory | ||
| * @return the selected factory, retaining its registration metadata and per-invocation lifecycle | ||
| */ | ||
| public static DurableExecutionPluginFactory factory( | ||
| Mode mode, SdkTracerProviderBuilder tracerProviderBuilder, OtelPluginConfig config) { | ||
| return switch (requireNonNull(mode, "mode must not be null")) { | ||
| case EXECUTION -> ExecutionOtelPlugin.factory(tracerProviderBuilder, config); | ||
| case INVOCATION -> InvocationOtelPlugin.factory(tracerProviderBuilder, config); | ||
| }; | ||
| } | ||
| } |
39 changes: 39 additions & 0 deletions
39
otel-plugin/src/main/java/software/amazon/lambda/durable/otel/OtelPluginProvider.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,39 @@ | ||
| // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
| package software.amazon.lambda.durable.otel; | ||
|
|
||
| import software.amazon.lambda.durable.plugin.DurableExecutionPlugin; | ||
| import software.amazon.lambda.durable.plugin.DurableExecutionPluginProvider; | ||
| import software.amazon.lambda.durable.plugin.InvocationInfo; | ||
|
|
||
| /** | ||
| * Loads the default execution view when {@code DURABLE_EXECUTION_PLUGINS} contains {@code otel}. | ||
| * | ||
| * <p>{@code otel} and {@code otel-execution} load the same view through separate providers, so listing both puts two | ||
| * factories in the {@code durable-otel-view} exclusive group and configuration is rejected at startup. Set exactly one | ||
| * OTel entry name. | ||
| */ | ||
| public final class OtelPluginProvider implements DurableExecutionPluginProvider { | ||
| private final DurableExecutionPluginProvider delegate = | ||
| new DelegatingOtelPluginProvider("otel", OtelPlugin.factory()); | ||
|
|
||
| @Override | ||
| public String getName() { | ||
| return delegate.getName(); | ||
| } | ||
|
|
||
| @Override | ||
| public DurableExecutionPlugin createPlugin(InvocationInfo invocationInfo) { | ||
| return delegate.createPlugin(invocationInfo); | ||
| } | ||
|
|
||
| @Override | ||
| public String getExclusiveGroup() { | ||
| return delegate.getExclusiveGroup(); | ||
| } | ||
|
|
||
| @Override | ||
| public String toString() { | ||
| return delegate.toString(); | ||
| } | ||
| } | ||
1 change: 1 addition & 0 deletions
1
...es/META-INF/services/software.amazon.lambda.durable.plugin.DurableExecutionPluginProvider
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 |
|---|---|---|
| @@ -1,2 +1,3 @@ | ||
| software.amazon.lambda.durable.otel.InvocationOtelPluginProvider | ||
| software.amazon.lambda.durable.otel.ExecutionOtelPluginProvider | ||
| software.amazon.lambda.durable.otel.OtelPluginProvider |
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.
Uh oh!
There was an error while loading. Please reload this page.