-
Notifications
You must be signed in to change notification settings - Fork 1k
Implement process context sharing OTEP-4719 #8718
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
Draft
jhalliday
wants to merge
3
commits into
open-telemetry:main
Choose a base branch
from
jhalliday:jh-profiling-v
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
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
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,61 @@ | ||
| plugins { | ||
| id("otel.java-conventions") | ||
| // id("otel.publish-conventions") | ||
|
|
||
| // id("otel.animalsniffer-conventions") | ||
| } | ||
|
|
||
| description = "OpenTelemetry - ProcessContext SDK" | ||
| otelJava.moduleName.set("sdk.processcontext") | ||
|
|
||
| dependencies { | ||
| api(project(":sdk:common")) | ||
| api(project(":exporters:common")) // MessageWriter | ||
|
|
||
| annotationProcessor("com.google.auto.value:auto-value") | ||
|
|
||
| implementation(project(":exporters:otlp:common")) | ||
|
|
||
| testImplementation(project(":sdk:testing")) | ||
| testImplementation("io.opentelemetry.proto:opentelemetry-proto") | ||
| testImplementation("com.google.protobuf:protobuf-java-util") | ||
| } | ||
|
|
||
| java { | ||
| sourceSets { | ||
| create("java25") { | ||
| java { | ||
| srcDir("src/main/java25") | ||
| } | ||
| compileClasspath += sourceSets.main.get().output + sourceSets.main.get().compileClasspath | ||
| } | ||
| } | ||
| toolchain { | ||
| languageVersion.set(JavaLanguageVersion.of(25)) | ||
| } | ||
| } | ||
|
|
||
| testing { | ||
| sourceSets { | ||
| create("java25test") { | ||
| java { | ||
| srcDir("src/test/java25") | ||
| } | ||
| compileClasspath += sourceSets.test.get().output + sourceSets.test.get().compileClasspath | ||
| compileClasspath += sourceSets.main.get().output + sourceSets["java25"].output | ||
| } | ||
| } | ||
| } | ||
|
|
||
| tasks.withType<JavaCompile> { | ||
| options.release.set(25) | ||
| } | ||
|
|
||
| tasks.named<Jar>("jar") { | ||
| manifest { | ||
| attributes["Multi-Release"] = "true" | ||
| } | ||
| from(sourceSets.named("java25").get().output) { | ||
| into("META-INF/versions/25") | ||
| } | ||
| } | ||
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 @@ | ||
| otel.release=alpha |
49 changes: 49 additions & 0 deletions
49
...esscontext/src/main/java/io/opentelemetry/sdk/processcontext/ProcessContextMarshaler.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,49 @@ | ||
| /* | ||
| * Copyright The OpenTelemetry Authors | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| */ | ||
|
|
||
| package io.opentelemetry.sdk.processcontext; | ||
|
|
||
| import io.opentelemetry.exporter.internal.marshal.MarshalerUtil; | ||
| import io.opentelemetry.exporter.internal.marshal.MarshalerWithSize; | ||
| import io.opentelemetry.exporter.internal.marshal.Serializer; | ||
| import io.opentelemetry.exporter.internal.otlp.KeyValueMarshaler; | ||
| import io.opentelemetry.exporter.internal.otlp.ResourceMarshaler; | ||
| import io.opentelemetry.proto.processcontext.v1development.internal.ProcessContext; | ||
| import io.opentelemetry.sdk.processcontext.data.ProcessContextData; | ||
| import java.io.IOException; | ||
|
|
||
| final class ProcessContextMarshaler extends MarshalerWithSize { | ||
|
|
||
| private final ResourceMarshaler resourceMarshaler; | ||
| private final KeyValueMarshaler[] attributeMarshalers; | ||
|
|
||
| static ProcessContextMarshaler create(ProcessContextData processContextData) { | ||
| KeyValueMarshaler[] attributeMarshalers = | ||
| KeyValueMarshaler.createForAttributes(processContextData.getAttributes()); | ||
| return new ProcessContextMarshaler( | ||
| ResourceMarshaler.create(processContextData.getResource()), attributeMarshalers); | ||
| } | ||
|
|
||
| private ProcessContextMarshaler( | ||
| ResourceMarshaler resourceMarshaler, KeyValueMarshaler[] attributeMarshalers) { | ||
| super(calculateSize(resourceMarshaler, attributeMarshalers)); | ||
| this.resourceMarshaler = resourceMarshaler; | ||
| this.attributeMarshalers = attributeMarshalers; | ||
| } | ||
|
|
||
| @Override | ||
| protected void writeTo(Serializer output) throws IOException { | ||
| output.serializeMessage(ProcessContext.RESOURCE, resourceMarshaler); | ||
| output.serializeRepeatedMessage(ProcessContext.ATTRIBUTES, attributeMarshalers); | ||
| } | ||
|
|
||
| private static int calculateSize( | ||
| ResourceMarshaler resourceMarshaler, KeyValueMarshaler[] attributeMarshalers) { | ||
| int size = 0; | ||
| size += MarshalerUtil.sizeMessage(ProcessContext.RESOURCE, resourceMarshaler); | ||
| size += MarshalerUtil.sizeRepeatedMessage(ProcessContext.ATTRIBUTES, attributeMarshalers); | ||
| return size; | ||
| } | ||
| } |
29 changes: 29 additions & 0 deletions
29
...esscontext/src/main/java/io/opentelemetry/sdk/processcontext/ProcessContextPublisher.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,29 @@ | ||
| /* | ||
| * Copyright The OpenTelemetry Authors | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| */ | ||
|
|
||
| package io.opentelemetry.sdk.processcontext; | ||
|
|
||
| import io.opentelemetry.sdk.common.Clock; | ||
| import io.opentelemetry.sdk.processcontext.data.ProcessContextData; | ||
| import java.io.IOException; | ||
|
|
||
| /** | ||
| * Exposes process context information to external readers using the shared memory mechanism | ||
| * specified in OTEP-4719. | ||
| * | ||
| * @see <a | ||
| * href="https://github.com/open-telemetry/opentelemetry-specification/blob/main/oteps/profiles/4719-process-ctx.md">OTEP | ||
| * 4719</a> | ||
| */ | ||
| public interface ProcessContextPublisher { | ||
|
jhalliday marked this conversation as resolved.
|
||
|
|
||
| /** | ||
| * Called to publish a {@code ProcessContextData}s. | ||
| * | ||
| * @param processContextData the process Resource descriptor and optional additional metadata. | ||
| * @param clock the time source for the publication. | ||
| */ | ||
| void publish(ProcessContextData processContextData, Clock clock) throws IOException; | ||
| } | ||
22 changes: 22 additions & 0 deletions
22
...t/src/main/java/io/opentelemetry/sdk/processcontext/data/ImmutableProcessContextData.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,22 @@ | ||
| /* | ||
| * Copyright The OpenTelemetry Authors | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| */ | ||
|
|
||
| package io.opentelemetry.sdk.processcontext.data; | ||
|
|
||
| import com.google.auto.value.AutoValue; | ||
| import javax.annotation.concurrent.Immutable; | ||
|
|
||
| /** | ||
| * Auto value implementation of {@link ProcessContextData}, which describes a process context. | ||
| * | ||
| * <p>This class is internal and is hence not for public use. Its APIs are unstable and can change | ||
| * at any time. | ||
| */ | ||
| @Immutable | ||
| @AutoValue | ||
| abstract class ImmutableProcessContextData implements ProcessContextData { | ||
|
|
||
| ImmutableProcessContextData() {} | ||
| } |
37 changes: 37 additions & 0 deletions
37
...esscontext/src/main/java/io/opentelemetry/sdk/processcontext/data/ProcessContextData.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,37 @@ | ||
| /* | ||
| * Copyright The OpenTelemetry Authors | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| */ | ||
|
|
||
| package io.opentelemetry.sdk.processcontext.data; | ||
|
|
||
| import io.opentelemetry.api.common.Attributes; | ||
| import io.opentelemetry.sdk.resources.Resource; | ||
| import javax.annotation.concurrent.Immutable; | ||
|
|
||
| /** | ||
| * Describes a ProcessContext. | ||
| * | ||
| * @see <a | ||
| * href="https://github.com/open-telemetry/opentelemetry-specification/blob/main/oteps/profiles/4719-process-ctx.md#payload-format"> | ||
| * OTEP-4719 Process Context : Payload</a> | ||
| */ | ||
| @Immutable | ||
| public interface ProcessContextData { | ||
|
|
||
| /** | ||
| * Returns a new ProcessContextData encapsulating the given Resource and supplemental Attributes. | ||
| * | ||
| * @return a new ProcessContextData. | ||
| */ | ||
| @SuppressWarnings("AutoValueSubclassLeaked") | ||
| static ProcessContextData create(Resource resource, Attributes attributes) { | ||
| return new AutoValue_ImmutableProcessContextData(resource, attributes); | ||
| } | ||
|
|
||
| /** Returns the resource of this process. */ | ||
| Resource getResource(); | ||
|
|
||
| /** Additional attributes that are not part of the Resource. */ | ||
| Attributes getAttributes(); | ||
|
jhalliday marked this conversation as resolved.
|
||
| } | ||
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.
I don't think we need to have a java 8 and java 25 source set. Here's a commit that merged them together (along with some other minor changes): jack-berg@a1d3f7c
I believe this also fixes the gradle problem where the tests weren't running.
If we end up having a java8 version of context sharing, we can split the module at that point.