Skip to content
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

Cleanup opencensus shim #5858

Merged
merged 1 commit into from
Oct 13, 2023
Merged
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 @@ -3,7 +3,7 @@
* SPDX-License-Identifier: Apache-2.0
*/

package io.opentelemetry.opencensusshim.internal.metrics;
package io.opentelemetry.opencensusshim;

import io.opencensus.common.Timestamp;
import io.opencensus.metrics.LabelKey;
Expand Down Expand Up @@ -55,13 +55,8 @@
import java.util.regex.Pattern;
import javax.annotation.Nullable;

/**
* Adapts an OpenCensus metric into the OpenTelemetry metric data API.
*
* <p>This class is internal and is hence not for public use. Its APIs are unstable and can change
* at any time.
*/
public final class MetricAdapter {
/** Adapts an OpenCensus metric into the OpenTelemetry metric data API. */
final class MetricAdapter {
private MetricAdapter() {}

// All OpenCensus metrics come from this shim.
Expand All @@ -81,7 +76,7 @@ private MetricAdapter() {}
* @param otelResource The resource associated with the opentelemetry SDK.
* @param censusMetric The OpenCensus metric to convert.
*/
public static MetricData convert(Resource otelResource, Metric censusMetric) {
static MetricData convert(Resource otelResource, Metric censusMetric) {
// Note: we can't just adapt interfaces, we need to do full copy because OTel data API uses
// auto-value vs. pure interfaces.
switch (censusMetric.getMetricDescriptor().getType()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@

import io.opencensus.metrics.Metrics;
import io.opencensus.metrics.export.MetricProducerManager;
import io.opentelemetry.opencensusshim.internal.metrics.MetricAdapter;
import io.opentelemetry.sdk.metrics.SdkMeterProviderBuilder;
import io.opentelemetry.sdk.metrics.data.MetricData;
import io.opentelemetry.sdk.metrics.export.MetricProducer;
Expand All @@ -26,7 +25,7 @@
public final class OpenCensusMetricProducer implements MetricProducer {
private final MetricProducerManager openCensusMetricStorage;

OpenCensusMetricProducer(MetricProducerManager openCensusMetricStorage) {
private OpenCensusMetricProducer(MetricProducerManager openCensusMetricStorage) {
this.openCensusMetricStorage = openCensusMetricStorage;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ public final class OpenTelemetryContextManager implements ContextManager {
private static final Logger LOGGER =
Logger.getLogger(OpenTelemetryContextManager.class.getName());

@SuppressWarnings("unused") // Loaded via reflection
public OpenTelemetryContextManager() {}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import io.opentelemetry.context.Scope;
import javax.annotation.Nullable;

class OpenTelemetryCtx implements ContextHandle {
final class OpenTelemetryCtx implements ContextHandle {

private final Context context;

Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@
import java.util.concurrent.TimeUnit;
import javax.annotation.Nonnull;

class OpenTelemetryNoRecordEventsSpanImpl extends Span implements io.opentelemetry.api.trace.Span {
final class OpenTelemetryNoRecordEventsSpanImpl extends Span
implements io.opentelemetry.api.trace.Span {
private static final EnumSet<Options> NOT_RECORD_EVENTS_SPAN_OPTIONS =
EnumSet.noneOf(Options.class);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import io.opentelemetry.api.trace.propagation.W3CTraceContextPropagator;
import io.opentelemetry.extension.trace.propagation.B3Propagator;

class OpenTelemetryPropagationComponentImpl extends PropagationComponentImpl {
final class OpenTelemetryPropagationComponentImpl extends PropagationComponentImpl {

private final TextFormat b3Format =
new OpenTelemetryTextFormatImpl(B3Propagator.injectingMultiHeaders());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
import java.util.Random;
import javax.annotation.Nullable;

class OpenTelemetrySpanBuilderImpl extends SpanBuilder {
final class OpenTelemetrySpanBuilderImpl extends SpanBuilder {

private static final Tracer OTEL_TRACER =
GlobalOpenTelemetry.getTracer("io.opentelemetry.opencensusshim", OtelVersion.VERSION);
Expand All @@ -68,6 +68,29 @@ class OpenTelemetrySpanBuilderImpl extends SpanBuilder {
@Nullable private Sampler ocSampler;
@Nullable private SpanKind otelKind;

private OpenTelemetrySpanBuilderImpl(
String name,
@Nullable SpanContext ocRemoteParentSpanContext,
@Nullable Span ocParent,
OpenTelemetrySpanBuilderImpl.Options options) {
this.name = checkNotNull(name, "name");
this.ocParent = ocParent;
this.ocRemoteParentSpanContext = ocRemoteParentSpanContext;
this.options = options;
}

static OpenTelemetrySpanBuilderImpl createWithParent(
String spanName, @Nullable Span parent, OpenTelemetrySpanBuilderImpl.Options options) {
return new OpenTelemetrySpanBuilderImpl(spanName, null, parent, options);
}

static OpenTelemetrySpanBuilderImpl createWithRemoteParent(
String spanName,
@Nullable SpanContext remoteParentSpanContext,
OpenTelemetrySpanBuilderImpl.Options options) {
return new OpenTelemetrySpanBuilderImpl(spanName, remoteParentSpanContext, null, options);
}

@Override
public SpanBuilder setSampler(Sampler sampler) {
this.ocSampler = checkNotNull(sampler, "sampler");
Expand Down Expand Up @@ -155,29 +178,6 @@ public Span startSpan() {
return new OpenTelemetrySpanImpl(otSpan);
}

private OpenTelemetrySpanBuilderImpl(
String name,
@Nullable SpanContext ocRemoteParentSpanContext,
@Nullable Span ocParent,
OpenTelemetrySpanBuilderImpl.Options options) {
this.name = checkNotNull(name, "name");
this.ocParent = ocParent;
this.ocRemoteParentSpanContext = ocRemoteParentSpanContext;
this.options = options;
}

static OpenTelemetrySpanBuilderImpl createWithParent(
String spanName, @Nullable Span parent, OpenTelemetrySpanBuilderImpl.Options options) {
return new OpenTelemetrySpanBuilderImpl(spanName, null, parent, options);
}

static OpenTelemetrySpanBuilderImpl createWithRemoteParent(
String spanName,
@Nullable SpanContext remoteParentSpanContext,
OpenTelemetrySpanBuilderImpl.Options options) {
return new OpenTelemetrySpanBuilderImpl(spanName, remoteParentSpanContext, null, options);
}

private static boolean makeSamplingDecision(
@Nullable SpanContext parent,
@Nullable Boolean hasRemoteParent,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
import java.util.List;
import javax.annotation.Nullable;

class OpenTelemetryTextFormatImpl extends TextFormat {
final class OpenTelemetryTextFormatImpl extends TextFormat {

private final TextMapPropagator propagator;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public final class OpenTelemetryTraceComponentImpl extends TraceComponent {
private final TraceConfig traceConfig = makeTraceConfig();
private final Tracer tracer;

/** Public constructor to be used with reflection loading. */
@SuppressWarnings("unused") // Loaded via reflection
public OpenTelemetryTraceComponentImpl() {
clock = MillisClock.getInstance();
RandomHandler randomHandler = new ThreadLocalRandomHandler();
Expand All @@ -48,7 +48,7 @@ public PropagationComponent getPropagationComponent() {
}

@Override
public final Clock getClock() {
public Clock getClock() {
return clock;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,10 @@
import io.opencensus.trace.config.TraceConfig;
import javax.annotation.Nullable;

class OpenTelemetryTracerImpl extends Tracer {
final class OpenTelemetryTracerImpl extends Tracer {
private final OpenTelemetrySpanBuilderImpl.Options spanBuilderOptions;

public OpenTelemetryTracerImpl(RandomHandler randomHandler, TraceConfig traceConfig) {
OpenTelemetryTracerImpl(RandomHandler randomHandler, TraceConfig traceConfig) {
spanBuilderOptions = new OpenTelemetrySpanBuilderImpl.Options(randomHandler, traceConfig);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@
* implementation in opencensus-impl, however we do not want to depend on opencensus-impl here.
*/
@ThreadSafe
public final class ThreadLocalRandomHandler extends RandomHandler {
final class ThreadLocalRandomHandler extends RandomHandler {

/** Constructs a new {@code ThreadLocalRandomHandler}. */
public ThreadLocalRandomHandler() {}
ThreadLocalRandomHandler() {}

@Override
public Random current() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* SPDX-License-Identifier: Apache-2.0
*/

package io.opentelemetry.opencensusshim.internal.metrics;
package io.opentelemetry.opencensusshim;

import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.assertThat;
import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.attributeEntry;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* SPDX-License-Identifier: Apache-2.0
*/

package io.opentelemetry.opencensusshim.metrics;
package io.opentelemetry.opencensusshim;

import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.assertThat;

Expand All @@ -21,7 +21,6 @@
import io.opencensus.trace.TraceOptions;
import io.opencensus.trace.Tracestate;
import io.opentelemetry.api.common.Attributes;
import io.opentelemetry.opencensusshim.OpenCensusMetricProducer;
import io.opentelemetry.sdk.metrics.export.MetricProducer;
import io.opentelemetry.sdk.resources.Resource;
import java.time.Duration;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* SPDX-License-Identifier: Apache-2.0
*/

package io.opentelemetry.opencensusshim.metrics;
package io.opentelemetry.opencensusshim;

import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.assertThat;

Expand All @@ -12,7 +12,6 @@
import io.opencensus.stats.Stats;
import io.opencensus.stats.StatsRecorder;
import io.opencensus.stats.View;
import io.opentelemetry.opencensusshim.OpenCensusMetricProducer;
import io.opentelemetry.sdk.metrics.SdkMeterProvider;
import io.opentelemetry.sdk.testing.exporter.InMemoryMetricReader;
import java.time.Duration;
Expand Down
Loading