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
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ class NoSharedInternalCodeTest {
"opentelemetry-exporter-logging",
"opentelemetry-exporter-logging-otlp",
"opentelemetry-exporter-prometheus",
"opentelemetry-exporter-zipkin",
Copy link
Copy Markdown
Member Author

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.

"opentelemetry-extension-trace-propagators",
"opentelemetry-opencensus-shim",
"opentelemetry-sdk-common",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,19 @@
* SPDX-License-Identifier: Apache-2.0
*/

package io.opentelemetry.api.internal;
package io.opentelemetry.api.impl;

import io.opentelemetry.context.Context;
import io.opentelemetry.context.ContextKey;
import java.util.Objects;

/**
* This class is internal and is hence not for public use. Its APIs are unstable and can change at
* any time.
* Utility for suppressing instrumentation cycles between exporters which leverage various client
* libraries in their implementations and the otel java agent which instruments those client
* libraries.
*
* <p>This class is not intended for use by application developers. Its API is stable and will not
* be changed or removed in a backwards-incompatible manner.
*/
public final class InstrumentationUtil {
private static final ContextKey<Boolean> SUPPRESS_INSTRUMENTATION_KEY =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;

import io.opentelemetry.api.impl.InstrumentationUtil;
import io.opentelemetry.context.Context;
import org.junit.jupiter.api.Test;

Expand Down
5 changes: 5 additions & 0 deletions docs/apidiffs/current_vs_latest/opentelemetry-api.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
Comparing source compatibility of opentelemetry-api-1.63.0-SNAPSHOT.jar against opentelemetry-api-1.62.0.jar
+++ NEW CLASS: PUBLIC(+) FINAL(+) io.opentelemetry.api.impl.InstrumentationUtil (not serializable)
+++ CLASS FILE FORMAT VERSION: 52.0 <- n.a.
+++ NEW SUPERCLASS: java.lang.Object
+++ NEW METHOD: PUBLIC(+) STATIC(+) boolean shouldSuppressInstrumentation(io.opentelemetry.context.Context)
+++ NEW METHOD: PUBLIC(+) STATIC(+) void suppressInstrumentation(java.lang.Runnable)
*** MODIFIED INTERFACE: PUBLIC ABSTRACT io.opentelemetry.api.logs.LogRecordBuilder (not serializable)
=== CLASS FILE FORMAT VERSION: 52.0 <- 52.0
+++ NEW METHOD: PUBLIC(+) io.opentelemetry.api.logs.LogRecordBuilder setAttribute(java.lang.String, io.opentelemetry.api.common.Value<?>)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
* This class is internal and is hence not for public use. Its APIs are unstable and can change at
* any time.
*
* @deprecated use {@link io.opentelemetry.api.internal.InstrumentationUtil} instead. This class
* should be removed once instrumentation does not refer to it anymore.
* @deprecated use {@link io.opentelemetry.api.impl.InstrumentationUtil} instead. This class should
* be removed once instrumentation does not refer to it anymore.
*/
@Deprecated
public final class InstrumentationUtil {
Expand All @@ -25,7 +25,7 @@ private InstrumentationUtil() {}
* calls.
*/
public static void suppressInstrumentation(Runnable runnable) {
io.opentelemetry.api.internal.InstrumentationUtil.suppressInstrumentation(runnable);
io.opentelemetry.api.impl.InstrumentationUtil.suppressInstrumentation(runnable);
}

/**
Expand All @@ -35,6 +35,6 @@ public static void suppressInstrumentation(Runnable runnable) {
* instrumentation.
*/
public static boolean shouldSuppressInstrumentation(Context context) {
return io.opentelemetry.api.internal.InstrumentationUtil.shouldSuppressInstrumentation(context);
return io.opentelemetry.api.impl.InstrumentationUtil.shouldSuppressInstrumentation(context);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,6 @@ public static boolean isSupportedType(StandardComponentId.ExporterType exporterT
case OTLP_GRPC_SPAN_EXPORTER:
case OTLP_HTTP_SPAN_EXPORTER:
case OTLP_HTTP_JSON_SPAN_EXPORTER:
case ZIPKIN_HTTP_SPAN_EXPORTER:
case ZIPKIN_HTTP_JSON_SPAN_EXPORTER:
case OTLP_GRPC_LOG_EXPORTER:
case OTLP_HTTP_LOG_EXPORTER:
case OTLP_HTTP_JSON_LOG_EXPORTER:
Expand Down Expand Up @@ -100,9 +98,6 @@ private static String getExporterName(StandardComponentId.ExporterType exporterT
case OTLP_HTTP_METRIC_EXPORTER:
case OTLP_HTTP_JSON_METRIC_EXPORTER:
return "otlp";
case ZIPKIN_HTTP_SPAN_EXPORTER:
case ZIPKIN_HTTP_JSON_SPAN_EXPORTER:
return "zipkin";
case OTLP_GRPC_PROFILES_EXPORTER:
throw new IllegalArgumentException("Profiles are not supported");
}
Expand All @@ -118,12 +113,10 @@ private static String getTransportName(StandardComponentId.ExporterType exporter
case OTLP_HTTP_SPAN_EXPORTER:
case OTLP_HTTP_LOG_EXPORTER:
case OTLP_HTTP_METRIC_EXPORTER:
case ZIPKIN_HTTP_SPAN_EXPORTER:
return "http";
case OTLP_HTTP_JSON_SPAN_EXPORTER:
case OTLP_HTTP_JSON_LOG_EXPORTER:
case OTLP_HTTP_JSON_METRIC_EXPORTER:
case ZIPKIN_HTTP_JSON_SPAN_EXPORTER:
return "http-json";
case OTLP_GRPC_PROFILES_EXPORTER:
throw new IllegalArgumentException("Profiles are not supported");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@

package io.opentelemetry.exporter.sender.okhttp.internal;

import io.opentelemetry.api.internal.InstrumentationUtil;
import io.opentelemetry.api.impl.InstrumentationUtil;
import io.opentelemetry.exporter.internal.RetryUtil;
import io.opentelemetry.sdk.common.CompletableResultCode;
import io.opentelemetry.sdk.common.export.Compressor;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

package io.opentelemetry.exporter.sender.okhttp.internal;

import io.opentelemetry.api.internal.InstrumentationUtil;
import io.opentelemetry.api.impl.InstrumentationUtil;
import io.opentelemetry.exporter.internal.RetryUtil;
import io.opentelemetry.sdk.common.CompletableResultCode;
import io.opentelemetry.sdk.common.export.Compressor;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

import static org.junit.jupiter.api.Assertions.assertTrue;

import io.opentelemetry.api.internal.InstrumentationUtil;
import io.opentelemetry.api.impl.InstrumentationUtil;
import io.opentelemetry.context.Context;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.atomic.AtomicBoolean;
Expand Down
1 change: 0 additions & 1 deletion exporters/zipkin/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ dependencies {

api("io.zipkin.reporter2:zipkin-reporter")

implementation(project(":exporters:common"))
implementation(project(":sdk-extensions:autoconfigure-spi"))
compileOnly(project(":api:incubator"))

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@

package io.opentelemetry.exporter.zipkin;

import io.opentelemetry.api.internal.InstrumentationUtil;
import io.opentelemetry.api.impl.InstrumentationUtil;
import io.opentelemetry.api.metrics.MeterProvider;
import io.opentelemetry.exporter.internal.metrics.ExporterInstrumentation;
import io.opentelemetry.exporter.zipkin.internal.ComponentId;
import io.opentelemetry.exporter.zipkin.internal.ExporterInstrumentation;
import io.opentelemetry.exporter.zipkin.internal.StandardComponentId;
import io.opentelemetry.exporter.zipkin.internal.ThrottlingLogger;
import io.opentelemetry.sdk.common.CompletableResultCode;
import io.opentelemetry.sdk.common.InternalTelemetryVersion;
import io.opentelemetry.sdk.common.internal.ComponentId;
import io.opentelemetry.sdk.common.internal.StandardComponentId;
import io.opentelemetry.sdk.common.internal.ThrottlingLogger;
import io.opentelemetry.sdk.trace.data.SpanData;
import io.opentelemetry.sdk.trace.export.SpanExporter;
import java.io.IOException;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@

package io.opentelemetry.exporter.zipkin;

import static io.opentelemetry.api.internal.Utils.checkArgument;
import static java.util.Objects.requireNonNull;

import io.opentelemetry.api.GlobalOpenTelemetry;
Expand Down Expand Up @@ -151,9 +150,10 @@ public ZipkinSpanExporterBuilder setEndpoint(String endpoint) {
*/
public ZipkinSpanExporterBuilder setCompression(String compressionMethod) {
requireNonNull(compressionMethod, "compressionMethod");
checkArgument(
compressionMethod.equals("gzip") || compressionMethod.equals("none"),
"Unsupported compression method. Supported compression methods include: gzip, none.");
if (!compressionMethod.equals("gzip") && !compressionMethod.equals("none")) {
throw new IllegalArgumentException(
"Unsupported compression method. Supported compression methods include: gzip, none.");
}
this.compressionEnabled = compressionMethod.equals("gzip");
return this;
}
Expand All @@ -166,7 +166,9 @@ public ZipkinSpanExporterBuilder setCompression(String compressionMethod) {
*/
public ZipkinSpanExporterBuilder setReadTimeout(long timeout, TimeUnit unit) {
requireNonNull(unit, "unit");
checkArgument(timeout >= 0, "timeout must be non-negative");
if (timeout < 0) {
throw new IllegalArgumentException("timeout must be non-negative");
}
long timeoutMillis = timeout == 0 ? Long.MAX_VALUE : unit.toMillis(timeout);
this.readTimeoutMillis = (int) Math.min(timeoutMillis, Integer.MAX_VALUE);
return this;
Expand Down
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);
}
}
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();
}
}
}
Loading
Loading