Remove Binary format and related members. (#891)
This commit is contained in:
parent
bd6c6fc91f
commit
26a4070d90
|
|
@ -17,7 +17,6 @@
|
||||||
package io.opentelemetry.correlationcontext;
|
package io.opentelemetry.correlationcontext;
|
||||||
|
|
||||||
import io.opentelemetry.context.Scope;
|
import io.opentelemetry.context.Scope;
|
||||||
import io.opentelemetry.context.propagation.BinaryFormat;
|
|
||||||
import io.opentelemetry.context.propagation.HttpTextFormat;
|
import io.opentelemetry.context.propagation.HttpTextFormat;
|
||||||
import javax.annotation.concurrent.ThreadSafe;
|
import javax.annotation.concurrent.ThreadSafe;
|
||||||
|
|
||||||
|
|
@ -65,45 +64,6 @@ public interface CorrelationContextManager {
|
||||||
*/
|
*/
|
||||||
Scope withContext(CorrelationContext distContext);
|
Scope withContext(CorrelationContext distContext);
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns the {@link BinaryFormat} for this implementation.
|
|
||||||
*
|
|
||||||
* <p>Example of usage on the client:
|
|
||||||
*
|
|
||||||
* <pre>{@code
|
|
||||||
* private static final CorrelationContextManager contextManager =
|
|
||||||
* OpenTelemetry.getCorrelationContextManager();
|
|
||||||
* private static final BinaryFormat binaryFormat = contextManager.getBinaryFormat();
|
|
||||||
*
|
|
||||||
* Request createRequest() {
|
|
||||||
* Request req = new Request();
|
|
||||||
* byte[] ctxBuffer = binaryFormat.toByteArray(contextManager.getCurrentContext());
|
|
||||||
* request.addMetadata("distributedContext", ctxBuffer);
|
|
||||||
* return request;
|
|
||||||
* }
|
|
||||||
* }</pre>
|
|
||||||
*
|
|
||||||
* <p>Example of usage on the server:
|
|
||||||
*
|
|
||||||
* <pre>{@code
|
|
||||||
* private static final CorrelationContextManager contextManager =
|
|
||||||
* OpenTelemetry.getCorrelationContextManager();
|
|
||||||
* private static final BinaryFormat binaryFormat = contextManager.getBinaryFormat();
|
|
||||||
*
|
|
||||||
* void onRequestReceived(Request request) {
|
|
||||||
* byte[] ctxBuffer = request.getMetadata("distributedContext");
|
|
||||||
* CorrelationContext distContext = textFormat.fromByteArray(ctxBuffer);
|
|
||||||
* try (Scope s = contextManager.withContext(distContext)) {
|
|
||||||
* // Handle request and send response back.
|
|
||||||
* }
|
|
||||||
* }
|
|
||||||
* }</pre>
|
|
||||||
*
|
|
||||||
* @return the {@code BinaryFormat} for this implementation.
|
|
||||||
* @since 0.1.0
|
|
||||||
*/
|
|
||||||
BinaryFormat<CorrelationContext> getBinaryFormat();
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the {@link HttpTextFormat} for this implementation.
|
* Returns the {@link HttpTextFormat} for this implementation.
|
||||||
*
|
*
|
||||||
|
|
|
||||||
|
|
@ -17,7 +17,6 @@
|
||||||
package io.opentelemetry.correlationcontext;
|
package io.opentelemetry.correlationcontext;
|
||||||
|
|
||||||
import io.opentelemetry.context.Scope;
|
import io.opentelemetry.context.Scope;
|
||||||
import io.opentelemetry.context.propagation.BinaryFormat;
|
|
||||||
import io.opentelemetry.context.propagation.HttpTextFormat;
|
import io.opentelemetry.context.propagation.HttpTextFormat;
|
||||||
import io.opentelemetry.correlationcontext.unsafe.ContextUtils;
|
import io.opentelemetry.correlationcontext.unsafe.ContextUtils;
|
||||||
import io.opentelemetry.internal.Utils;
|
import io.opentelemetry.internal.Utils;
|
||||||
|
|
@ -35,7 +34,6 @@ import javax.annotation.concurrent.ThreadSafe;
|
||||||
public final class DefaultCorrelationContextManager implements CorrelationContextManager {
|
public final class DefaultCorrelationContextManager implements CorrelationContextManager {
|
||||||
private static final DefaultCorrelationContextManager INSTANCE =
|
private static final DefaultCorrelationContextManager INSTANCE =
|
||||||
new DefaultCorrelationContextManager();
|
new DefaultCorrelationContextManager();
|
||||||
private static final BinaryFormat<CorrelationContext> BINARY_FORMAT = new NoopBinaryFormat();
|
|
||||||
private static final HttpTextFormat<CorrelationContext> HTTP_TEXT_FORMAT =
|
private static final HttpTextFormat<CorrelationContext> HTTP_TEXT_FORMAT =
|
||||||
new NoopHttpTextFormat();
|
new NoopHttpTextFormat();
|
||||||
|
|
||||||
|
|
@ -66,11 +64,6 @@ public final class DefaultCorrelationContextManager implements CorrelationContex
|
||||||
return ContextUtils.withCorrelationContext(distContext);
|
return ContextUtils.withCorrelationContext(distContext);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public BinaryFormat<CorrelationContext> getBinaryFormat() {
|
|
||||||
return BINARY_FORMAT;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public HttpTextFormat<CorrelationContext> getHttpTextFormat() {
|
public HttpTextFormat<CorrelationContext> getHttpTextFormat() {
|
||||||
return HTTP_TEXT_FORMAT;
|
return HTTP_TEXT_FORMAT;
|
||||||
|
|
@ -110,23 +103,6 @@ public final class DefaultCorrelationContextManager implements CorrelationContex
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Immutable
|
|
||||||
private static final class NoopBinaryFormat implements BinaryFormat<CorrelationContext> {
|
|
||||||
static final byte[] EMPTY_BYTE_ARRAY = {};
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public byte[] toByteArray(CorrelationContext distContext) {
|
|
||||||
Utils.checkNotNull(distContext, "distContext");
|
|
||||||
return EMPTY_BYTE_ARRAY;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public CorrelationContext fromByteArray(byte[] bytes) {
|
|
||||||
Utils.checkNotNull(bytes, "bytes");
|
|
||||||
return EmptyCorrelationContext.getInstance();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Immutable
|
@Immutable
|
||||||
private static final class NoopHttpTextFormat implements HttpTextFormat<CorrelationContext> {
|
private static final class NoopHttpTextFormat implements HttpTextFormat<CorrelationContext> {
|
||||||
@Override
|
@Override
|
||||||
|
|
|
||||||
|
|
@ -17,10 +17,8 @@
|
||||||
package io.opentelemetry.trace;
|
package io.opentelemetry.trace;
|
||||||
|
|
||||||
import io.opentelemetry.context.Scope;
|
import io.opentelemetry.context.Scope;
|
||||||
import io.opentelemetry.context.propagation.BinaryFormat;
|
|
||||||
import io.opentelemetry.context.propagation.HttpTextFormat;
|
import io.opentelemetry.context.propagation.HttpTextFormat;
|
||||||
import io.opentelemetry.internal.Utils;
|
import io.opentelemetry.internal.Utils;
|
||||||
import io.opentelemetry.trace.propagation.BinaryTraceContext;
|
|
||||||
import io.opentelemetry.trace.propagation.HttpTraceContext;
|
import io.opentelemetry.trace.propagation.HttpTraceContext;
|
||||||
import io.opentelemetry.trace.unsafe.ContextUtils;
|
import io.opentelemetry.trace.unsafe.ContextUtils;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
@ -34,7 +32,6 @@ import javax.annotation.concurrent.ThreadSafe;
|
||||||
@ThreadSafe
|
@ThreadSafe
|
||||||
public final class DefaultTracer implements Tracer {
|
public final class DefaultTracer implements Tracer {
|
||||||
private static final DefaultTracer INSTANCE = new DefaultTracer();
|
private static final DefaultTracer INSTANCE = new DefaultTracer();
|
||||||
private static final BinaryFormat<SpanContext> BINARY_FORMAT = new BinaryTraceContext();
|
|
||||||
private static final HttpTextFormat<SpanContext> HTTP_TEXT_FORMAT = new HttpTraceContext();
|
private static final HttpTextFormat<SpanContext> HTTP_TEXT_FORMAT = new HttpTraceContext();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -62,11 +59,6 @@ public final class DefaultTracer implements Tracer {
|
||||||
return NoopSpanBuilder.create(this, spanName);
|
return NoopSpanBuilder.create(this, spanName);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public BinaryFormat<SpanContext> getBinaryFormat() {
|
|
||||||
return BINARY_FORMAT;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public HttpTextFormat<SpanContext> getHttpTextFormat() {
|
public HttpTextFormat<SpanContext> getHttpTextFormat() {
|
||||||
return HTTP_TEXT_FORMAT;
|
return HTTP_TEXT_FORMAT;
|
||||||
|
|
|
||||||
|
|
@ -18,7 +18,6 @@ package io.opentelemetry.trace;
|
||||||
|
|
||||||
import com.google.errorprone.annotations.MustBeClosed;
|
import com.google.errorprone.annotations.MustBeClosed;
|
||||||
import io.opentelemetry.context.Scope;
|
import io.opentelemetry.context.Scope;
|
||||||
import io.opentelemetry.context.propagation.BinaryFormat;
|
|
||||||
import io.opentelemetry.context.propagation.HttpTextFormat;
|
import io.opentelemetry.context.propagation.HttpTextFormat;
|
||||||
import io.opentelemetry.trace.propagation.HttpTraceContext;
|
import io.opentelemetry.trace.propagation.HttpTraceContext;
|
||||||
import javax.annotation.concurrent.ThreadSafe;
|
import javax.annotation.concurrent.ThreadSafe;
|
||||||
|
|
@ -154,56 +153,6 @@ public interface Tracer {
|
||||||
*/
|
*/
|
||||||
Span.Builder spanBuilder(String spanName);
|
Span.Builder spanBuilder(String spanName);
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns the {@link BinaryFormat} for this tracer implementation.
|
|
||||||
*
|
|
||||||
* <p>If no tracer implementation is provided, this defaults to the W3C Trace Context binary
|
|
||||||
* format. For more details see <a href="https://w3c.github.io/trace-context-binary/">W3C Trace
|
|
||||||
* Context binary protocol</a>.
|
|
||||||
*
|
|
||||||
* <p>Example of usage on the client:
|
|
||||||
*
|
|
||||||
* <pre>{@code
|
|
||||||
* private static final Tracer tracer = OpenTelemetry.getTracer();
|
|
||||||
* private static final BinaryFormat binaryFormat = tracer.getBinaryFormat();
|
|
||||||
* void onSendRequest() {
|
|
||||||
* Span span = tracer.spanBuilder("MyRequest").setSpanKind(Span.Kind.CLIENT).startSpan();
|
|
||||||
* try (Scope ss = tracer.withSpan(span)) {
|
|
||||||
* byte[] binaryValue = binaryFormat.toByteArray(tracer.getCurrentContext().context());
|
|
||||||
* // Send the request including the binaryValue and wait for the response.
|
|
||||||
* } finally {
|
|
||||||
* span.end();
|
|
||||||
* }
|
|
||||||
* }
|
|
||||||
* }</pre>
|
|
||||||
*
|
|
||||||
* <p>Example of usage on the server:
|
|
||||||
*
|
|
||||||
* <pre>{@code
|
|
||||||
* private static final Tracer tracer = OpenTelemetry.getTracer();
|
|
||||||
* private static final BinaryFormat binaryFormat = tracer.getBinaryFormat();
|
|
||||||
* void onRequestReceived() {
|
|
||||||
* // Get the binaryValue from the request.
|
|
||||||
* SpanContext spanContext = SpanContext.INVALID;
|
|
||||||
* if (binaryValue != null) {
|
|
||||||
* spanContext = binaryFormat.fromByteArray(binaryValue);
|
|
||||||
* }
|
|
||||||
* Span span = tracer.spanBuilder("MyRequest")
|
|
||||||
* .setParent(spanContext)
|
|
||||||
* .setSpanKind(Span.Kind.SERVER).startSpan();
|
|
||||||
* try (Scope ss = tracer.withSpan(span)) {
|
|
||||||
* // Handle request and send response back.
|
|
||||||
* } finally {
|
|
||||||
* span.end();
|
|
||||||
* }
|
|
||||||
* }
|
|
||||||
* }</pre>
|
|
||||||
*
|
|
||||||
* @return the {@code BinaryFormat} for this implementation.
|
|
||||||
* @since 0.1.0
|
|
||||||
*/
|
|
||||||
BinaryFormat<SpanContext> getBinaryFormat();
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the {@link HttpTextFormat} for this tracer implementation.
|
* Returns the {@link HttpTextFormat} for this tracer implementation.
|
||||||
*
|
*
|
||||||
|
|
|
||||||
|
|
@ -1,151 +0,0 @@
|
||||||
/*
|
|
||||||
* Copyright 2019, OpenTelemetry Authors
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package io.opentelemetry.trace.propagation;
|
|
||||||
|
|
||||||
import io.opentelemetry.context.propagation.BinaryFormat;
|
|
||||||
import io.opentelemetry.internal.Utils;
|
|
||||||
import io.opentelemetry.trace.SpanContext;
|
|
||||||
import io.opentelemetry.trace.SpanId;
|
|
||||||
import io.opentelemetry.trace.TraceFlags;
|
|
||||||
import io.opentelemetry.trace.TraceId;
|
|
||||||
import io.opentelemetry.trace.TraceState;
|
|
||||||
import javax.annotation.concurrent.Immutable;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Implementation of the binary propagation protocol on {@link SpanContext}.
|
|
||||||
*
|
|
||||||
* <p>Format:
|
|
||||||
*
|
|
||||||
* <ul>
|
|
||||||
* <li>Binary value: <version_id><version_format>
|
|
||||||
* <li>version_id: 1-byte representing the version id.
|
|
||||||
* <li>For version_id = 0:
|
|
||||||
* <ul>
|
|
||||||
* <li>version_format: <field><field>
|
|
||||||
* <li>field_format: <field_id><field_format>
|
|
||||||
* <li>Fields:
|
|
||||||
* <ul>
|
|
||||||
* <li>TraceId: (field_id = 0, len = 16, default = "0000000000000000") -
|
|
||||||
* 16-byte array representing the trace_id.
|
|
||||||
* <li>SpanId: (field_id = 1, len = 8, default = "00000000") - 8-byte array
|
|
||||||
* representing the span_id.
|
|
||||||
* <li>TraceFlags: (field_id = 2, len = 1, default = "0") - 1-byte array
|
|
||||||
* representing the trace_options.
|
|
||||||
* </ul>
|
|
||||||
* <li>Fields MUST be encoded using the field id order (smaller to higher).
|
|
||||||
* <li>Valid value example:
|
|
||||||
* <ul>
|
|
||||||
* <li>{0, 0, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 1, 97,
|
|
||||||
* 98, 99, 100, 101, 102, 103, 104, 2, 1}
|
|
||||||
* <li>version_id = 0;
|
|
||||||
* <li>trace_id = {64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79}
|
|
||||||
* <li>span_id = {97, 98, 99, 100, 101, 102, 103, 104};
|
|
||||||
* <li>trace_options = {1};
|
|
||||||
* </ul>
|
|
||||||
* </ul>
|
|
||||||
* </ul>
|
|
||||||
*/
|
|
||||||
@Immutable
|
|
||||||
public final class BinaryTraceContext implements BinaryFormat<SpanContext> {
|
|
||||||
|
|
||||||
private static final TraceState TRACE_STATE_DEFAULT = TraceState.builder().build();
|
|
||||||
private static final byte VERSION_ID = 0;
|
|
||||||
private static final int VERSION_ID_OFFSET = 0;
|
|
||||||
// The version_id/field_id size in bytes.
|
|
||||||
private static final byte ID_SIZE = 1;
|
|
||||||
private static final byte TRACE_ID_FIELD_ID = 0;
|
|
||||||
|
|
||||||
// TODO: clarify if offsets are correct here. While the specification suggests you should stop
|
|
||||||
// parsing when you hit an unknown field, it does not suggest that fields must be declared in
|
|
||||||
// ID order. Rather it only groups by data type order, in this case Trace Context
|
|
||||||
// https://github.com/census-instrumentation/opencensus-specs/blob/master/encodings/BinaryEncoding.md#deserialization-rules
|
|
||||||
static final int TRACE_ID_FIELD_ID_OFFSET = VERSION_ID_OFFSET + ID_SIZE;
|
|
||||||
|
|
||||||
private static final int TRACE_ID_OFFSET = TRACE_ID_FIELD_ID_OFFSET + ID_SIZE;
|
|
||||||
private static final byte SPAN_ID_FIELD_ID = 1;
|
|
||||||
|
|
||||||
static final int SPAN_ID_FIELD_ID_OFFSET = TRACE_ID_OFFSET + TraceId.getSize();
|
|
||||||
|
|
||||||
private static final int SPAN_ID_OFFSET = SPAN_ID_FIELD_ID_OFFSET + ID_SIZE;
|
|
||||||
private static final byte TRACE_OPTION_FIELD_ID = 2;
|
|
||||||
|
|
||||||
static final int TRACE_OPTION_FIELD_ID_OFFSET = SPAN_ID_OFFSET + SpanId.getSize();
|
|
||||||
|
|
||||||
private static final int TRACE_OPTIONS_OFFSET = TRACE_OPTION_FIELD_ID_OFFSET + ID_SIZE;
|
|
||||||
/** Version, Trace and Span IDs are required fields. */
|
|
||||||
private static final int REQUIRED_FORMAT_LENGTH =
|
|
||||||
3 * ID_SIZE + TraceId.getSize() + SpanId.getSize();
|
|
||||||
/** Use {@link TraceFlags#getDefault()} unless its optional field is present. */
|
|
||||||
private static final int ALL_FORMAT_LENGTH =
|
|
||||||
REQUIRED_FORMAT_LENGTH + ID_SIZE + TraceFlags.getSize();
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public byte[] toByteArray(SpanContext spanContext) {
|
|
||||||
Utils.checkNotNull(spanContext, "spanContext");
|
|
||||||
byte[] bytes = new byte[ALL_FORMAT_LENGTH];
|
|
||||||
bytes[VERSION_ID_OFFSET] = VERSION_ID;
|
|
||||||
bytes[TRACE_ID_FIELD_ID_OFFSET] = TRACE_ID_FIELD_ID;
|
|
||||||
spanContext.getTraceId().copyBytesTo(bytes, TRACE_ID_OFFSET);
|
|
||||||
bytes[SPAN_ID_FIELD_ID_OFFSET] = SPAN_ID_FIELD_ID;
|
|
||||||
spanContext.getSpanId().copyBytesTo(bytes, SPAN_ID_OFFSET);
|
|
||||||
bytes[TRACE_OPTION_FIELD_ID_OFFSET] = TRACE_OPTION_FIELD_ID;
|
|
||||||
spanContext.getTraceFlags().copyBytesTo(bytes, TRACE_OPTIONS_OFFSET);
|
|
||||||
return bytes;
|
|
||||||
}
|
|
||||||
|
|
||||||
// TODO: consider throwing checked exception in API signature
|
|
||||||
@Override
|
|
||||||
public SpanContext fromByteArray(byte[] bytes) {
|
|
||||||
Utils.checkNotNull(bytes, "bytes");
|
|
||||||
if (bytes.length == 0 || bytes[0] != VERSION_ID) {
|
|
||||||
throw new IllegalArgumentException("Unsupported version.");
|
|
||||||
}
|
|
||||||
if (bytes.length < REQUIRED_FORMAT_LENGTH) {
|
|
||||||
throw new IllegalArgumentException("Invalid input: truncated");
|
|
||||||
}
|
|
||||||
// TODO: the following logic assumes that fields are written in ID order. The spec does not say
|
|
||||||
// that. If it decides not to, this logic would need to be more like a loop
|
|
||||||
TraceId traceId;
|
|
||||||
SpanId spanId;
|
|
||||||
TraceFlags traceFlags = TraceFlags.getDefault();
|
|
||||||
int pos = 1;
|
|
||||||
if (bytes[pos] == TRACE_ID_FIELD_ID) {
|
|
||||||
traceId = TraceId.fromBytes(bytes, pos + ID_SIZE);
|
|
||||||
pos += ID_SIZE + TraceId.getSize();
|
|
||||||
} else {
|
|
||||||
// TODO: update the spec to suggest that the trace ID is not actually optional
|
|
||||||
throw new IllegalArgumentException("Invalid input: expected trace ID at offset " + pos);
|
|
||||||
}
|
|
||||||
if (bytes[pos] == SPAN_ID_FIELD_ID) {
|
|
||||||
spanId = SpanId.fromBytes(bytes, pos + ID_SIZE);
|
|
||||||
pos += ID_SIZE + SpanId.getSize();
|
|
||||||
} else {
|
|
||||||
// TODO: update the spec to suggest that the span ID is not actually optional.
|
|
||||||
throw new IllegalArgumentException("Invalid input: expected span ID at offset " + pos);
|
|
||||||
}
|
|
||||||
// Check to see if we are long enough to include an options field, and also that the next field
|
|
||||||
// is an options field. Per spec we simply stop parsing at first unknown field instead of
|
|
||||||
// failing.
|
|
||||||
if (bytes.length > pos && bytes[pos] == TRACE_OPTION_FIELD_ID) {
|
|
||||||
if (bytes.length < ALL_FORMAT_LENGTH) {
|
|
||||||
throw new IllegalArgumentException("Invalid input: truncated");
|
|
||||||
}
|
|
||||||
traceFlags = TraceFlags.fromByte(bytes[pos + ID_SIZE]);
|
|
||||||
}
|
|
||||||
return SpanContext.createFromRemoteParent(traceId, spanId, traceFlags, TRACE_STATE_DEFAULT);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -20,7 +20,6 @@ import static com.google.common.truth.Truth.assertThat;
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.Assert.assertTrue;
|
||||||
|
|
||||||
import io.opentelemetry.context.Scope;
|
import io.opentelemetry.context.Scope;
|
||||||
import io.opentelemetry.context.propagation.BinaryFormat;
|
|
||||||
import io.opentelemetry.context.propagation.HttpTextFormat;
|
import io.opentelemetry.context.propagation.HttpTextFormat;
|
||||||
import io.opentelemetry.correlationcontext.CorrelationContext;
|
import io.opentelemetry.correlationcontext.CorrelationContext;
|
||||||
import io.opentelemetry.correlationcontext.CorrelationContextManager;
|
import io.opentelemetry.correlationcontext.CorrelationContextManager;
|
||||||
|
|
@ -268,12 +267,6 @@ public class OpenTelemetryTest {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nullable
|
|
||||||
@Override
|
|
||||||
public BinaryFormat<SpanContext> getBinaryFormat() {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
@Override
|
@Override
|
||||||
public HttpTextFormat<SpanContext> getHttpTextFormat() {
|
public HttpTextFormat<SpanContext> getHttpTextFormat() {
|
||||||
|
|
@ -406,12 +399,6 @@ public class OpenTelemetryTest {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nullable
|
|
||||||
@Override
|
|
||||||
public BinaryFormat<CorrelationContext> getBinaryFormat() {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
@Override
|
@Override
|
||||||
public HttpTextFormat<CorrelationContext> getHttpTextFormat() {
|
public HttpTextFormat<CorrelationContext> getHttpTextFormat() {
|
||||||
|
|
|
||||||
|
|
@ -19,7 +19,6 @@ package io.opentelemetry.trace;
|
||||||
import static com.google.common.truth.Truth.assertThat;
|
import static com.google.common.truth.Truth.assertThat;
|
||||||
|
|
||||||
import io.opentelemetry.context.Scope;
|
import io.opentelemetry.context.Scope;
|
||||||
import io.opentelemetry.trace.propagation.BinaryTraceContext;
|
|
||||||
import io.opentelemetry.trace.propagation.HttpTraceContext;
|
import io.opentelemetry.trace.propagation.HttpTraceContext;
|
||||||
import org.junit.Rule;
|
import org.junit.Rule;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
@ -79,11 +78,6 @@ public class DefaultTracerTest {
|
||||||
assertThat(defaultTracer.getHttpTextFormat()).isInstanceOf(HttpTraceContext.class);
|
assertThat(defaultTracer.getHttpTextFormat()).isInstanceOf(HttpTraceContext.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
|
||||||
public void defaultBinaryFormat() {
|
|
||||||
assertThat(defaultTracer.getBinaryFormat()).isInstanceOf(BinaryTraceContext.class);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testInProcessContext() {
|
public void testInProcessContext() {
|
||||||
Span span = defaultTracer.spanBuilder(SPAN_NAME).startSpan();
|
Span span = defaultTracer.spanBuilder(SPAN_NAME).startSpan();
|
||||||
|
|
|
||||||
|
|
@ -1,204 +0,0 @@
|
||||||
/*
|
|
||||||
* Copyright 2019, OpenTelemetry Authors
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package io.opentelemetry.trace.propagation;
|
|
||||||
|
|
||||||
import static com.google.common.truth.Truth.assertThat;
|
|
||||||
|
|
||||||
import io.opentelemetry.context.propagation.BinaryFormat;
|
|
||||||
import io.opentelemetry.trace.DefaultSpan;
|
|
||||||
import io.opentelemetry.trace.SpanContext;
|
|
||||||
import io.opentelemetry.trace.SpanId;
|
|
||||||
import io.opentelemetry.trace.TraceFlags;
|
|
||||||
import io.opentelemetry.trace.TraceId;
|
|
||||||
import io.opentelemetry.trace.TraceState;
|
|
||||||
import org.junit.Rule;
|
|
||||||
import org.junit.Test;
|
|
||||||
import org.junit.rules.ExpectedException;
|
|
||||||
import org.junit.runner.RunWith;
|
|
||||||
import org.junit.runners.JUnit4;
|
|
||||||
|
|
||||||
/** Tests for {@link io.opentelemetry.trace.propagation.BinaryTraceContext}. */
|
|
||||||
@RunWith(JUnit4.class)
|
|
||||||
public class BinaryTraceContextTest {
|
|
||||||
|
|
||||||
private static final byte[] TRACE_ID_BYTES =
|
|
||||||
new byte[] {64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79};
|
|
||||||
private static final TraceId TRACE_ID = TraceId.fromBytes(TRACE_ID_BYTES, 0);
|
|
||||||
private static final byte[] SPAN_ID_BYTES = new byte[] {97, 98, 99, 100, 101, 102, 103, 104};
|
|
||||||
private static final SpanId SPAN_ID = SpanId.fromBytes(SPAN_ID_BYTES, 0);
|
|
||||||
private static final byte TRACE_OPTIONS_BYTES = 1;
|
|
||||||
private static final TraceFlags TRACE_OPTIONS = TraceFlags.fromByte(TRACE_OPTIONS_BYTES);
|
|
||||||
private static final byte[] EXAMPLE_BYTES =
|
|
||||||
new byte[] {
|
|
||||||
0, 0, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 1, 97, 98, 99, 100,
|
|
||||||
101, 102, 103, 104, 2, 1
|
|
||||||
};
|
|
||||||
private static final SpanContext INVALID_SPAN_CONTEXT = DefaultSpan.getInvalid().getContext();
|
|
||||||
@Rule public ExpectedException thrown = ExpectedException.none();
|
|
||||||
private final BinaryFormat<SpanContext> binaryFormat = new BinaryTraceContext();
|
|
||||||
|
|
||||||
private void testSpanContextConversion(SpanContext spanContext) {
|
|
||||||
SpanContext propagatedBinarySpanContext =
|
|
||||||
binaryFormat.fromByteArray(binaryFormat.toByteArray(spanContext));
|
|
||||||
|
|
||||||
assertThat(propagatedBinarySpanContext.getTraceId()).isEqualTo(spanContext.getTraceId());
|
|
||||||
assertThat(propagatedBinarySpanContext.getSpanId()).isEqualTo(spanContext.getSpanId());
|
|
||||||
assertThat(propagatedBinarySpanContext.getTraceFlags()).isEqualTo(spanContext.getTraceFlags());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void propagate_SpanContextTracingEnabled() {
|
|
||||||
testSpanContextConversion(
|
|
||||||
SpanContext.create(
|
|
||||||
TRACE_ID,
|
|
||||||
SPAN_ID,
|
|
||||||
TraceFlags.builder().setIsSampled(true).build(),
|
|
||||||
TraceState.getDefault()));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void propagate_SpanContextNoTracing() {
|
|
||||||
testSpanContextConversion(
|
|
||||||
SpanContext.create(TRACE_ID, SPAN_ID, TraceFlags.getDefault(), TraceState.getDefault()));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void toBinaryValue_NullSpanContext() {
|
|
||||||
thrown.expect(NullPointerException.class);
|
|
||||||
thrown.expectMessage("spanContext");
|
|
||||||
binaryFormat.toByteArray(null);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void toBinaryValue_InvalidSpanContext() {
|
|
||||||
assertThat(binaryFormat.toByteArray(INVALID_SPAN_CONTEXT))
|
|
||||||
.isEqualTo(
|
|
||||||
new byte[] {
|
|
||||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void fromBinaryValue_BinaryExampleValue() {
|
|
||||||
assertThat(binaryFormat.fromByteArray(EXAMPLE_BYTES))
|
|
||||||
.isEqualTo(
|
|
||||||
SpanContext.createFromRemoteParent(
|
|
||||||
TRACE_ID, SPAN_ID, TRACE_OPTIONS, TraceState.getDefault()));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void fromBinaryValue_NullInput() {
|
|
||||||
thrown.expect(NullPointerException.class);
|
|
||||||
thrown.expectMessage("bytes");
|
|
||||||
binaryFormat.fromByteArray(null);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void fromBinaryValue_EmptyInput() {
|
|
||||||
thrown.expect(IllegalArgumentException.class);
|
|
||||||
thrown.expectMessage("Unsupported version.");
|
|
||||||
binaryFormat.fromByteArray(new byte[0]);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void fromBinaryValue_UnsupportedVersionId() {
|
|
||||||
thrown.expect(IllegalArgumentException.class);
|
|
||||||
thrown.expectMessage("Unsupported version.");
|
|
||||||
binaryFormat.fromByteArray(
|
|
||||||
new byte[] {
|
|
||||||
66, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 97, 98, 99, 100, 101,
|
|
||||||
102, 103, 104, 1
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void fromBinaryValue_UnsupportedFieldIdFirst() {
|
|
||||||
thrown.expect(IllegalArgumentException.class);
|
|
||||||
thrown.expectMessage(
|
|
||||||
"Invalid input: expected trace ID at offset "
|
|
||||||
+ BinaryTraceContext.TRACE_ID_FIELD_ID_OFFSET);
|
|
||||||
binaryFormat.fromByteArray(
|
|
||||||
new byte[] {
|
|
||||||
0, 4, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 1, 97, 98, 99, 100,
|
|
||||||
101, 102, 103, 104, 2, 1
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void fromBinaryValue_UnsupportedFieldIdSecond() {
|
|
||||||
thrown.expect(IllegalArgumentException.class);
|
|
||||||
thrown.expectMessage(
|
|
||||||
"Invalid input: expected span ID at offset " + BinaryTraceContext.SPAN_ID_FIELD_ID_OFFSET);
|
|
||||||
binaryFormat.fromByteArray(
|
|
||||||
new byte[] {
|
|
||||||
0, 0, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 3, 97, 98, 99, 100,
|
|
||||||
101, 102, 103, 104, 2, 1
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void fromBinaryValue_UnsupportedFieldIdThird_skipped() {
|
|
||||||
assertThat(
|
|
||||||
binaryFormat
|
|
||||||
.fromByteArray(
|
|
||||||
new byte[] {
|
|
||||||
0, 0, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 1, 97,
|
|
||||||
98, 99, 100, 101, 102, 103, 104, 0, 1
|
|
||||||
})
|
|
||||||
.isValid())
|
|
||||||
.isTrue();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void fromBinaryValue_ShorterTraceId() {
|
|
||||||
thrown.expect(IllegalArgumentException.class);
|
|
||||||
thrown.expectMessage("Invalid input: truncated");
|
|
||||||
binaryFormat.fromByteArray(
|
|
||||||
new byte[] {0, 0, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76});
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void fromBinaryValue_ShorterSpanId() {
|
|
||||||
thrown.expect(IllegalArgumentException.class);
|
|
||||||
thrown.expectMessage("Invalid input: truncated");
|
|
||||||
binaryFormat.fromByteArray(new byte[] {0, 1, 97, 98, 99, 100, 101, 102, 103});
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void fromBinaryValue_ShorterTraceFlags() {
|
|
||||||
thrown.expect(IllegalArgumentException.class);
|
|
||||||
thrown.expectMessage("Invalid input: truncated");
|
|
||||||
binaryFormat.fromByteArray(
|
|
||||||
new byte[] {
|
|
||||||
0, 0, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 1, 97, 98, 99, 100,
|
|
||||||
101, 102, 103, 104, 2
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void fromBinaryValue_MissingTraceFlagsOk() {
|
|
||||||
SpanContext extracted =
|
|
||||||
binaryFormat.fromByteArray(
|
|
||||||
new byte[] {
|
|
||||||
0, 0, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 1, 97, 98, 99,
|
|
||||||
100, 101, 102, 103, 104
|
|
||||||
});
|
|
||||||
|
|
||||||
assertThat(extracted.isValid()).isTrue();
|
|
||||||
assertThat(extracted.getTraceFlags()).isEqualTo(TraceFlags.getDefault());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,49 +0,0 @@
|
||||||
/*
|
|
||||||
* Copyright 2019, OpenTelemetry Authors
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package io.opentelemetry.context.propagation;
|
|
||||||
|
|
||||||
import javax.annotation.concurrent.ThreadSafe;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Formatter to serializing and deserializing a value with into a binary format.
|
|
||||||
*
|
|
||||||
* @since 0.1.0
|
|
||||||
*/
|
|
||||||
@ThreadSafe
|
|
||||||
public interface BinaryFormat<V> {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Serializes the {@code value} into the on-the-wire representation.
|
|
||||||
*
|
|
||||||
* @param value the value to serialize.
|
|
||||||
* @return the on-the-wire representation of a {@code value}.
|
|
||||||
* @since 0.1.0
|
|
||||||
*/
|
|
||||||
byte[] toByteArray(V value);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Creates a value from the given on-the-wire encoded representation.
|
|
||||||
*
|
|
||||||
* <p>If the value could not be parsed, the underlying implementation will decide to return ether
|
|
||||||
* an empty value, an invalid value, or a valid value.
|
|
||||||
*
|
|
||||||
* @param bytes on-the-wire representation of the value.
|
|
||||||
* @return a value deserialized from {@code bytes}.
|
|
||||||
* @since 0.1.0
|
|
||||||
*/
|
|
||||||
V fromByteArray(byte[] bytes);
|
|
||||||
}
|
|
||||||
|
|
@ -17,10 +17,8 @@
|
||||||
package io.opentelemetry.opentracingshim;
|
package io.opentelemetry.opentracingshim;
|
||||||
|
|
||||||
import io.opentelemetry.context.propagation.HttpTextFormat;
|
import io.opentelemetry.context.propagation.HttpTextFormat;
|
||||||
import io.opentracing.propagation.Binary;
|
|
||||||
import io.opentracing.propagation.TextMapExtract;
|
import io.opentracing.propagation.TextMapExtract;
|
||||||
import io.opentracing.propagation.TextMapInject;
|
import io.opentracing.propagation.TextMapInject;
|
||||||
import java.nio.ByteBuffer;
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import javax.annotation.Nullable;
|
import javax.annotation.Nullable;
|
||||||
|
|
@ -79,19 +77,4 @@ final class Propagation extends BaseShimObject {
|
||||||
return carrier.get(key);
|
return carrier.get(key);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void injectBinaryFormat(SpanContextShim context, Binary carrier) {
|
|
||||||
byte[] contextBuff = tracer().getBinaryFormat().toByteArray(context.getSpanContext());
|
|
||||||
ByteBuffer byteBuff = carrier.injectionBuffer(contextBuff.length);
|
|
||||||
byteBuff.put(contextBuff);
|
|
||||||
}
|
|
||||||
|
|
||||||
public SpanContextShim extractBinaryFormat(Binary carrier) {
|
|
||||||
|
|
||||||
ByteBuffer byteBuff = carrier.extractionBuffer();
|
|
||||||
byte[] buff = new byte[byteBuff.remaining()];
|
|
||||||
byteBuff.get(buff);
|
|
||||||
|
|
||||||
return new SpanContextShim(telemetryInfo, tracer().getBinaryFormat().fromByteArray(buff));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -21,7 +21,6 @@ import io.opentracing.ScopeManager;
|
||||||
import io.opentracing.Span;
|
import io.opentracing.Span;
|
||||||
import io.opentracing.SpanContext;
|
import io.opentracing.SpanContext;
|
||||||
import io.opentracing.Tracer;
|
import io.opentracing.Tracer;
|
||||||
import io.opentracing.propagation.Binary;
|
|
||||||
import io.opentracing.propagation.Format;
|
import io.opentracing.propagation.Format;
|
||||||
import io.opentracing.propagation.TextMapExtract;
|
import io.opentracing.propagation.TextMapExtract;
|
||||||
import io.opentracing.propagation.TextMapInject;
|
import io.opentracing.propagation.TextMapInject;
|
||||||
|
|
@ -73,8 +72,6 @@ final class TracerShim extends BaseShimObject implements Tracer {
|
||||||
|| format == Format.Builtin.TEXT_MAP_INJECT
|
|| format == Format.Builtin.TEXT_MAP_INJECT
|
||||||
|| format == Format.Builtin.HTTP_HEADERS) {
|
|| format == Format.Builtin.HTTP_HEADERS) {
|
||||||
propagation.injectTextFormat(contextShim, (TextMapInject) carrier);
|
propagation.injectTextFormat(contextShim, (TextMapInject) carrier);
|
||||||
} else if (format == Format.Builtin.BINARY) {
|
|
||||||
propagation.injectBinaryFormat(contextShim, (Binary) carrier);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -86,8 +83,6 @@ final class TracerShim extends BaseShimObject implements Tracer {
|
||||||
|| format == Format.Builtin.TEXT_MAP_EXTRACT
|
|| format == Format.Builtin.TEXT_MAP_EXTRACT
|
||||||
|| format == Format.Builtin.HTTP_HEADERS) {
|
|| format == Format.Builtin.HTTP_HEADERS) {
|
||||||
return propagation.extractTextFormat((TextMapExtract) carrier);
|
return propagation.extractTextFormat((TextMapExtract) carrier);
|
||||||
} else if (format == Format.Builtin.BINARY) {
|
|
||||||
return propagation.extractBinaryFormat((Binary) carrier);
|
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
logger.log(
|
logger.log(
|
||||||
|
|
|
||||||
|
|
@ -17,7 +17,6 @@
|
||||||
package io.opentelemetry.sdk.correlationcontext;
|
package io.opentelemetry.sdk.correlationcontext;
|
||||||
|
|
||||||
import io.opentelemetry.context.Scope;
|
import io.opentelemetry.context.Scope;
|
||||||
import io.opentelemetry.context.propagation.BinaryFormat;
|
|
||||||
import io.opentelemetry.context.propagation.HttpTextFormat;
|
import io.opentelemetry.context.propagation.HttpTextFormat;
|
||||||
import io.opentelemetry.correlationcontext.CorrelationContext;
|
import io.opentelemetry.correlationcontext.CorrelationContext;
|
||||||
import io.opentelemetry.correlationcontext.CorrelationContextManager;
|
import io.opentelemetry.correlationcontext.CorrelationContextManager;
|
||||||
|
|
@ -44,12 +43,6 @@ public class CorrelationContextManagerSdk implements CorrelationContextManager {
|
||||||
return ContextUtils.withCorrelationContext(distContext);
|
return ContextUtils.withCorrelationContext(distContext);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public BinaryFormat<CorrelationContext> getBinaryFormat() {
|
|
||||||
// TODO: Implement this.
|
|
||||||
return DefaultCorrelationContextManager.getInstance().getBinaryFormat();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public HttpTextFormat<CorrelationContext> getHttpTextFormat() {
|
public HttpTextFormat<CorrelationContext> getHttpTextFormat() {
|
||||||
// TODO: Implement this.
|
// TODO: Implement this.
|
||||||
|
|
|
||||||
|
|
@ -17,20 +17,17 @@
|
||||||
package io.opentelemetry.sdk.trace;
|
package io.opentelemetry.sdk.trace;
|
||||||
|
|
||||||
import io.opentelemetry.context.Scope;
|
import io.opentelemetry.context.Scope;
|
||||||
import io.opentelemetry.context.propagation.BinaryFormat;
|
|
||||||
import io.opentelemetry.context.propagation.HttpTextFormat;
|
import io.opentelemetry.context.propagation.HttpTextFormat;
|
||||||
import io.opentelemetry.sdk.common.InstrumentationLibraryInfo;
|
import io.opentelemetry.sdk.common.InstrumentationLibraryInfo;
|
||||||
import io.opentelemetry.trace.DefaultTracer;
|
import io.opentelemetry.trace.DefaultTracer;
|
||||||
import io.opentelemetry.trace.Span;
|
import io.opentelemetry.trace.Span;
|
||||||
import io.opentelemetry.trace.SpanContext;
|
import io.opentelemetry.trace.SpanContext;
|
||||||
import io.opentelemetry.trace.Tracer;
|
import io.opentelemetry.trace.Tracer;
|
||||||
import io.opentelemetry.trace.propagation.BinaryTraceContext;
|
|
||||||
import io.opentelemetry.trace.propagation.HttpTraceContext;
|
import io.opentelemetry.trace.propagation.HttpTraceContext;
|
||||||
import io.opentelemetry.trace.unsafe.ContextUtils;
|
import io.opentelemetry.trace.unsafe.ContextUtils;
|
||||||
|
|
||||||
/** {@link TracerSdk} is SDK implementation of {@link Tracer}. */
|
/** {@link TracerSdk} is SDK implementation of {@link Tracer}. */
|
||||||
public final class TracerSdk implements Tracer {
|
public final class TracerSdk implements Tracer {
|
||||||
private static final BinaryFormat<SpanContext> BINARY_FORMAT = new BinaryTraceContext();
|
|
||||||
private static final HttpTextFormat<SpanContext> HTTP_TEXT_FORMAT = new HttpTraceContext();
|
private static final HttpTextFormat<SpanContext> HTTP_TEXT_FORMAT = new HttpTraceContext();
|
||||||
private final TracerSharedState sharedState;
|
private final TracerSharedState sharedState;
|
||||||
private final InstrumentationLibraryInfo instrumentationLibraryInfo;
|
private final InstrumentationLibraryInfo instrumentationLibraryInfo;
|
||||||
|
|
@ -65,11 +62,6 @@ public final class TracerSdk implements Tracer {
|
||||||
sharedState.getClock());
|
sharedState.getClock());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public BinaryFormat<SpanContext> getBinaryFormat() {
|
|
||||||
return BINARY_FORMAT;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public HttpTextFormat<SpanContext> getHttpTextFormat() {
|
public HttpTextFormat<SpanContext> getHttpTextFormat() {
|
||||||
return HTTP_TEXT_FORMAT;
|
return HTTP_TEXT_FORMAT;
|
||||||
|
|
|
||||||
|
|
@ -23,7 +23,6 @@ import io.opentelemetry.context.Scope;
|
||||||
import io.opentelemetry.sdk.common.InstrumentationLibraryInfo;
|
import io.opentelemetry.sdk.common.InstrumentationLibraryInfo;
|
||||||
import io.opentelemetry.trace.DefaultSpan;
|
import io.opentelemetry.trace.DefaultSpan;
|
||||||
import io.opentelemetry.trace.Span;
|
import io.opentelemetry.trace.Span;
|
||||||
import io.opentelemetry.trace.propagation.BinaryTraceContext;
|
|
||||||
import io.opentelemetry.trace.propagation.HttpTraceContext;
|
import io.opentelemetry.trace.propagation.HttpTraceContext;
|
||||||
import io.opentelemetry.trace.unsafe.ContextUtils;
|
import io.opentelemetry.trace.unsafe.ContextUtils;
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
|
|
@ -72,11 +71,6 @@ public class TracerSdkTest {
|
||||||
assertThat(tracer.getHttpTextFormat()).isInstanceOf(HttpTraceContext.class);
|
assertThat(tracer.getHttpTextFormat()).isInstanceOf(HttpTraceContext.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
|
||||||
public void defaultBinaryFormat() {
|
|
||||||
assertThat(tracer.getBinaryFormat()).isInstanceOf(BinaryTraceContext.class);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void getCurrentSpan() {
|
public void getCurrentSpan() {
|
||||||
assertThat(tracer.getCurrentSpan()).isInstanceOf(DefaultSpan.class);
|
assertThat(tracer.getCurrentSpan()).isInstanceOf(DefaultSpan.class);
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue