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

Remove BaseShimObject, TelemetryInfo #5087

Merged
merged 1 commit into from
Jan 10, 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

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,14 @@
import io.opentracing.Tracer.SpanBuilder;
import io.opentracing.tag.Tag;

final class NoopSpanBuilderShim extends BaseShimObject implements SpanBuilder {
final class NoopSpanBuilderShim implements SpanBuilder {

private static final Tracer TRACER =
TracerProvider.noop().get("io.opentelemetry.opentracingshim");

private final String spanName;

public NoopSpanBuilderShim(TelemetryInfo telemetryInfo, String spanName) {
super(telemetryInfo);
NoopSpanBuilderShim(String spanName) {
this.spanName = spanName == null ? "" : spanName; // OT is more permissive than OTel.
}

Expand Down Expand Up @@ -71,6 +70,6 @@ public SpanBuilder withStartTimestamp(long microseconds) {

@Override
public Span start() {
return new SpanShim(telemetryInfo, TRACER.spanBuilder(spanName).startSpan());
return new SpanShim(TRACER.spanBuilder(spanName).startSpan());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ public class OpenTracingPropagatorsBuilder {
private TextMapPropagator httpHeadersPropagator =
GlobalOpenTelemetry.getPropagators().getTextMapPropagator();

OpenTracingPropagatorsBuilder() {}

/** Set propagator for {@link io.opentracing.propagation.Format.Builtin#TEXT_MAP} format. */
public OpenTracingPropagatorsBuilder setTextMap(TextMapPropagator textMapPropagator) {
Objects.requireNonNull(textMapPropagator, "textMapPropagator");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public static io.opentracing.Tracer createTracerShim(Tracer tracer) {
*/
public static io.opentracing.Tracer createTracerShim(
Tracer tracer, OpenTracingPropagators propagators) {
return new TracerShim(new TelemetryInfo(tracer, propagators));
return new TracerShim(tracer, propagators);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,19 @@
import java.util.Map;
import javax.annotation.Nullable;

final class Propagation extends BaseShimObject {
final class Propagation {
private static final TextMapSetter SETTER_INSTANCE = new TextMapSetter();
private static final TextMapGetter GETTER_INSTANCE = new TextMapGetter();

Propagation(TelemetryInfo telemetryInfo) {
super(telemetryInfo);
private final OpenTracingPropagators propagators;

Propagation(OpenTracingPropagators propagators) {
this.propagators = propagators;
}

// Visible for testing
OpenTracingPropagators propagators() {
return propagators;
}

<C> void injectTextMap(SpanContextShim contextShim, Format<C> format, TextMapInject carrier) {
Expand All @@ -46,14 +53,14 @@ <C> SpanContextShim extractTextMap(Format<C> format, TextMapExtract carrier) {
return null;
}

return new SpanContextShim(telemetryInfo, span.getSpanContext(), baggage);
return new SpanContextShim(span.getSpanContext(), baggage);
}

private <C> TextMapPropagator getPropagator(Format<C> format) {
if (format == Format.Builtin.HTTP_HEADERS) {
return propagators().httpHeadersPropagator();
return propagators.httpHeadersPropagator();
}
return propagators().textMapPropagator();
return propagators.textMapPropagator();
}

static final class TextMapSetter
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,17 @@

package io.opentelemetry.opentracingshim;

import io.opentelemetry.api.OpenTelemetry;
import io.opentelemetry.context.Context;
import io.opentracing.Scope;
import io.opentracing.ScopeManager;
import io.opentracing.Span;
import javax.annotation.Nullable;

final class ScopeManagerShim extends BaseShimObject implements ScopeManager {
final class ScopeManagerShim implements ScopeManager {
private static final SpanShim NOOP_SPANSHIM =
new SpanShim(
new TelemetryInfo(
OpenTelemetry.noop().getTracer("noop"), OpenTracingPropagators.builder().build()),
io.opentelemetry.api.trace.Span.getInvalid());
new SpanShim(io.opentelemetry.api.trace.Span.getInvalid());

public ScopeManagerShim(TelemetryInfo telemetryInfo) {
super(telemetryInfo);
}
ScopeManagerShim() {}

@Override
@Nullable
Expand All @@ -35,7 +29,7 @@ public Span activeSpan() {
return null;
}

return new SpanShim(telemetryInfo(), io.opentelemetry.api.trace.Span.getInvalid(), baggage);
return new SpanShim(io.opentelemetry.api.trace.Span.getInvalid(), baggage);
}

// If there's a SpanShim for the *actual* active Span, simply return it.
Expand All @@ -44,7 +38,7 @@ public Span activeSpan() {
}

// Span was activated from outside the Shim layer unfortunately.
return new SpanShim(telemetryInfo(), span, baggage);
return new SpanShim(span, baggage);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
final class ScopeShim implements Scope {
final io.opentelemetry.context.Scope scope;

public ScopeShim(io.opentelemetry.context.Scope scope) {
ScopeShim(io.opentelemetry.context.Scope scope) {
this.scope = scope;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import io.opentelemetry.api.common.AttributeKey;
import io.opentelemetry.api.common.Attributes;
import io.opentelemetry.api.trace.StatusCode;
import io.opentelemetry.api.trace.Tracer;
import io.opentelemetry.context.Context;
import io.opentelemetry.semconv.trace.attributes.SemanticAttributes;
import io.opentracing.References;
Expand All @@ -31,19 +32,7 @@
import javax.annotation.Nullable;
import javax.annotation.concurrent.Immutable;

final class SpanBuilderShim extends BaseShimObject implements SpanBuilder {
private final String spanName;

// *All* parents are saved in this list.
private List<SpanParentInfo> allParents = Collections.emptyList();
private boolean ignoreActiveSpan;

@SuppressWarnings("rawtypes")
private final List<AttributeKey> spanBuilderAttributeKeys = new ArrayList<>();

private final List<Object> spanBuilderAttributeValues = new ArrayList<>();
@Nullable private Boolean error;
private long startTimestampMicros;
final class SpanBuilderShim implements SpanBuilder {

private static final Attributes CHILD_OF_ATTR =
Attributes.of(
Expand All @@ -54,8 +43,21 @@ final class SpanBuilderShim extends BaseShimObject implements SpanBuilder {
SemanticAttributes.OPENTRACING_REF_TYPE,
SemanticAttributes.OpentracingRefTypeValues.FOLLOWS_FROM);

public SpanBuilderShim(TelemetryInfo telemetryInfo, String spanName) {
super(telemetryInfo);
private final Tracer tracer;
private final String spanName;

// *All* parents are saved in this list.
private List<SpanParentInfo> allParents = Collections.emptyList();
private boolean ignoreActiveSpan;

private final List<AttributeKey<?>> spanBuilderAttributeKeys = new ArrayList<>();
private final List<Object> spanBuilderAttributeValues = new ArrayList<>();

@Nullable private Boolean error;
private long startTimestampMicros;

SpanBuilderShim(Tracer tracer, String spanName) {
this.tracer = tracer;
this.spanName = spanName;
}

Expand Down Expand Up @@ -188,7 +190,7 @@ public SpanBuilder withStartTimestamp(long microseconds) {
@Override
public Span start() {
Baggage baggage;
io.opentelemetry.api.trace.SpanBuilder builder = tracer().spanBuilder(spanName);
io.opentelemetry.api.trace.SpanBuilder builder = tracer.spanBuilder(spanName);
io.opentelemetry.api.trace.SpanContext mainParent = getMainParent(allParents);

if (ignoreActiveSpan && mainParent == null) {
Expand Down Expand Up @@ -227,13 +229,14 @@ public Span start() {
span.setStatus(error ? StatusCode.ERROR : StatusCode.OK);
}

return new SpanShim(telemetryInfo(), span, baggage);
return new SpanShim(span, baggage);
}

// The first SpanContext with Child Of type in the entire list is used as parent,
// else the first SpanContext is used as parent.
@Nullable
static io.opentelemetry.api.trace.SpanContext getMainParent(List<SpanParentInfo> parents) {
private static io.opentelemetry.api.trace.SpanContext getMainParent(
List<SpanParentInfo> parents) {
if (parents.size() == 0) {
return null;
}
Expand All @@ -249,7 +252,7 @@ static io.opentelemetry.api.trace.SpanContext getMainParent(List<SpanParentInfo>
return mainParent.getSpanContext();
}

static Baggage getAllBaggage(List<SpanParentInfo> parents) {
private static Baggage getAllBaggage(List<SpanParentInfo> parents) {
if (parents.size() == 0) {
return Baggage.empty();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,28 +15,12 @@
import java.util.Map;
import javax.annotation.Nullable;

final class SpanContextShim extends BaseShimObject implements SpanContext {
final class SpanContextShim implements SpanContext {

private final io.opentelemetry.api.trace.SpanContext context;
private final Baggage baggage;

public SpanContextShim(SpanShim spanShim) {
this(
spanShim.telemetryInfo(),
spanShim.getSpan().getSpanContext(),
spanShim.telemetryInfo().emptyBaggage());
}

public SpanContextShim(
TelemetryInfo telemetryInfo, io.opentelemetry.api.trace.SpanContext context) {
this(telemetryInfo, context, telemetryInfo.emptyBaggage());
}

public SpanContextShim(
TelemetryInfo telemetryInfo,
io.opentelemetry.api.trace.SpanContext context,
Baggage baggage) {
super(telemetryInfo);
SpanContextShim(io.opentelemetry.api.trace.SpanContext context, Baggage baggage) {
this.context = context;
this.baggage = baggage;
}
Expand All @@ -45,7 +29,7 @@ SpanContextShim newWithKeyValue(String key, String value) {
BaggageBuilder builder = baggage.toBuilder();
builder.put(key, value, BaggageEntryMetadata.empty());

return new SpanContextShim(telemetryInfo(), context, builder.build());
return new SpanContextShim(context, builder.build());
}

io.opentelemetry.api.trace.SpanContext getSpanContext() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
* and performance reasons, as opposed to keeping a global map
* link OTel's Span and OT Span/SpanContext.
*/
final class SpanShim extends BaseShimObject implements Span, ImplicitContextKeyed {
final class SpanShim implements Span, ImplicitContextKeyed {
private static final String DEFAULT_EVENT_NAME = "log";
private static final String ERROR = "error";
private static final ContextKey<SpanShim> SPAN_SHIM_KEY =
Expand All @@ -43,16 +43,14 @@ final class SpanShim extends BaseShimObject implements Span, ImplicitContextKeye
private final Object spanContextShimLock;
private volatile SpanContextShim spanContextShim;

public SpanShim(TelemetryInfo telemetryInfo, io.opentelemetry.api.trace.Span span) {
this(telemetryInfo, span, Baggage.empty());
SpanShim(io.opentelemetry.api.trace.Span span) {
this(span, Baggage.empty());
}

public SpanShim(
TelemetryInfo telemetryInfo, io.opentelemetry.api.trace.Span span, Baggage baggage) {
super(telemetryInfo);
SpanShim(io.opentelemetry.api.trace.Span span, Baggage baggage) {
this.span = span;
this.spanContextShimLock = new Object();
this.spanContextShim = new SpanContextShim(telemetryInfo, span.getSpanContext(), baggage);
this.spanContextShim = new SpanContextShim(span.getSpanContext(), baggage);
}

io.opentelemetry.api.trace.Span getSpan() {
Expand Down

This file was deleted.

Loading