-
Notifications
You must be signed in to change notification settings - Fork 974
Remove all shared internal code refs from zipkin exporter #8413
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
jack-berg
wants to merge
3
commits into
open-telemetry:main
Choose a base branch
from
jack-berg:zipkin-shared-internal-code
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.
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
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
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
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
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
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
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
67 changes: 67 additions & 0 deletions
67
exporters/zipkin/src/main/java/io/opentelemetry/exporter/zipkin/internal/ComponentId.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,67 @@ | ||
| /* | ||
| * Copyright The OpenTelemetry Authors | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| */ | ||
|
|
||
| package io.opentelemetry.exporter.zipkin.internal; | ||
|
|
||
| import java.util.Map; | ||
| import java.util.concurrent.ConcurrentHashMap; | ||
| import java.util.concurrent.atomic.AtomicInteger; | ||
| import javax.annotation.Nullable; | ||
|
|
||
| /** | ||
| * The component id used for SDK health metrics. This corresponds to the otel.component.name and | ||
| * otel.component.id semconv attributes. | ||
| * | ||
| * <p>Copied from {@code io.opentelemetry.sdk.common.internal.ComponentId} to avoid shared internal | ||
| * code. | ||
| * | ||
| * <p>This class is internal and is hence not for public use. Its APIs are unstable and can change | ||
| * at any time. | ||
| */ | ||
| public abstract class ComponentId { | ||
|
|
||
| private ComponentId() {} | ||
|
|
||
| public abstract String getTypeName(); | ||
|
|
||
| public abstract String getComponentName(); | ||
|
|
||
| static class Lazy extends ComponentId { | ||
|
|
||
| private static final Map<String, AtomicInteger> nextIdCounters = new ConcurrentHashMap<>(); | ||
|
|
||
| private final String componentType; | ||
| @Nullable private volatile String componentName = null; | ||
|
|
||
| Lazy(String componentType) { | ||
| this.componentType = componentType; | ||
| } | ||
|
|
||
| @Override | ||
| public String getTypeName() { | ||
| return componentType; | ||
| } | ||
|
|
||
| @Override | ||
| public String getComponentName() { | ||
| if (componentName == null) { | ||
| synchronized (this) { | ||
| if (componentName == null) { | ||
| int id = | ||
| nextIdCounters | ||
| .computeIfAbsent(componentType, k -> new AtomicInteger(0)) | ||
| .getAndIncrement(); | ||
| componentName = componentType + "/" + id; | ||
| } | ||
| } | ||
| } | ||
| return componentName; | ||
| } | ||
| } | ||
|
|
||
| public static StandardComponentId generateLazy(StandardComponentId.ExporterType exporterType) { | ||
| return new StandardComponentId(exporterType); | ||
| } | ||
| } |
116 changes: 116 additions & 0 deletions
116
...pkin/src/main/java/io/opentelemetry/exporter/zipkin/internal/ExporterInstrumentation.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,116 @@ | ||
| /* | ||
| * Copyright The OpenTelemetry Authors | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| */ | ||
|
|
||
| package io.opentelemetry.exporter.zipkin.internal; | ||
|
|
||
| import io.opentelemetry.api.common.Attributes; | ||
| import io.opentelemetry.api.common.AttributesBuilder; | ||
| import io.opentelemetry.api.metrics.MeterProvider; | ||
| import io.opentelemetry.sdk.common.InternalTelemetryVersion; | ||
| import java.net.URI; | ||
| import java.util.function.Supplier; | ||
|
|
||
| /** | ||
| * Copied from {@code io.opentelemetry.exporter.internal.ExporterInstrumentation} to avoid shared | ||
| * internal code. | ||
| * | ||
| * <p>This class is internal and is hence not for public use. Its APIs are unstable and can change | ||
| * at any time. | ||
| */ | ||
| public class ExporterInstrumentation { | ||
|
|
||
| private final ExporterMetrics implementation; | ||
|
|
||
| public ExporterInstrumentation( | ||
| InternalTelemetryVersion schema, | ||
| Supplier<MeterProvider> meterProviderSupplier, | ||
| StandardComponentId componentId, | ||
| URI endpoint) { | ||
|
|
||
| Signal signal = componentId.getStandardType().signal(); | ||
| switch (schema) { | ||
| case LEGACY: | ||
| implementation = | ||
| LegacyExporterMetrics.isSupportedType() | ||
| ? new LegacyExporterMetrics(meterProviderSupplier, componentId.getStandardType()) | ||
| : NoopExporterMetrics.INSTANCE; | ||
| break; | ||
| case LATEST: | ||
| implementation = | ||
| new SemConvExporterMetrics( | ||
| meterProviderSupplier, signal, componentId, extractServerAttributes(endpoint)); | ||
| break; | ||
| default: | ||
| throw new IllegalStateException("Unhandled case: " + schema); | ||
| } | ||
| } | ||
|
|
||
| // visible for testing | ||
| static Attributes extractServerAttributes(URI httpEndpoint) { | ||
| AttributesBuilder builder = Attributes.builder(); | ||
| String host = httpEndpoint.getHost(); | ||
| if (host != null) { | ||
| builder.put(SemConvAttributes.SERVER_ADDRESS, host); | ||
| } | ||
| int port = httpEndpoint.getPort(); | ||
| if (port == -1) { | ||
| String scheme = httpEndpoint.getScheme(); | ||
| if ("https".equals(scheme)) { | ||
| port = 443; | ||
| } else if ("http".equals(scheme)) { | ||
| port = 80; | ||
| } | ||
| } | ||
| if (port != -1) { | ||
| builder.put(SemConvAttributes.SERVER_PORT, port); | ||
| } | ||
| return builder.build(); | ||
| } | ||
|
|
||
| public Recording startRecordingExport(int itemCount) { | ||
| return new Recording(implementation.startRecordingExport(itemCount)); | ||
| } | ||
|
|
||
| /** | ||
| * This class is internal and is hence not for public use. Its APIs are unstable and can change at | ||
| * any time. | ||
| */ | ||
| public static class Recording { | ||
|
|
||
| private final ExporterMetrics.Recording delegate; | ||
|
|
||
| private Recording(ExporterMetrics.Recording delegate) { | ||
| this.delegate = delegate; | ||
| } | ||
|
|
||
| /** Callback to notify that the export was successful. */ | ||
| public void finishSuccessful() { | ||
| delegate.finishSuccessful(buildRequestAttributes()); | ||
| } | ||
|
|
||
| /** | ||
| * Callback to notify that the export has failed with the given {@link Throwable} as failure | ||
| * cause. | ||
| * | ||
| * @param failureCause the cause of the failure | ||
| */ | ||
| public void finishFailed(Throwable failureCause) { | ||
| finishFailed(failureCause.getClass().getName()); | ||
| } | ||
|
|
||
| /** | ||
| * Callback to notify that the export has failed. | ||
| * | ||
| * @param errorType a failure reason suitable for the error.type attribute | ||
| */ | ||
| public void finishFailed(String errorType) { | ||
| delegate.finishFailed(errorType, buildRequestAttributes()); | ||
| } | ||
|
|
||
| private static Attributes buildRequestAttributes() { | ||
| return Attributes.empty(); | ||
| } | ||
| } | ||
| } |
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 is the key line that verifies I covered everything. If I missed anything, this test would fail.