From 4873ed47b6af91422e93c43582e98736b3d4d90f Mon Sep 17 00:00:00 2001 From: Carlos Alberto Cortez Date: Thu, 20 Feb 2020 05:17:58 +0100 Subject: [PATCH] Remove Binary format and related members. --- .../CorrelationContextManager.java | 40 ---- .../DefaultCorrelationContextManager.java | 24 --- .../io/opentelemetry/trace/DefaultTracer.java | 8 - .../java/io/opentelemetry/trace/Tracer.java | 51 ----- .../trace/propagation/BinaryTraceContext.java | 151 ------------- .../io/opentelemetry/OpenTelemetryTest.java | 13 -- .../trace/DefaultTracerTest.java | 6 - .../propagation/BinaryTraceContextTest.java | 200 ------------------ .../context/propagation/BinaryFormat.java | 49 ----- .../opentracingshim/Propagation.java | 17 -- .../opentracingshim/TracerShim.java | 5 - .../CorrelationContextManagerSdk.java | 7 - .../io/opentelemetry/sdk/trace/TracerSdk.java | 8 - .../sdk/trace/TracerSdkTest.java | 6 - 14 files changed, 585 deletions(-) delete mode 100644 api/src/main/java/io/opentelemetry/trace/propagation/BinaryTraceContext.java delete mode 100644 api/src/test/java/io/opentelemetry/trace/propagation/BinaryTraceContextTest.java delete mode 100644 context_prop/src/main/java/io/opentelemetry/context/propagation/BinaryFormat.java diff --git a/api/src/main/java/io/opentelemetry/correlationcontext/CorrelationContextManager.java b/api/src/main/java/io/opentelemetry/correlationcontext/CorrelationContextManager.java index a6b4a525c91..e9a43195245 100644 --- a/api/src/main/java/io/opentelemetry/correlationcontext/CorrelationContextManager.java +++ b/api/src/main/java/io/opentelemetry/correlationcontext/CorrelationContextManager.java @@ -17,7 +17,6 @@ package io.opentelemetry.correlationcontext; import io.opentelemetry.context.Scope; -import io.opentelemetry.context.propagation.BinaryFormat; import io.opentelemetry.context.propagation.HttpTextFormat; import javax.annotation.concurrent.ThreadSafe; @@ -65,45 +64,6 @@ public interface CorrelationContextManager { */ Scope withContext(CorrelationContext distContext); - /** - * Returns the {@link BinaryFormat} for this implementation. - * - *

Example of usage on the client: - * - *

{@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;
-   * }
-   * }
- * - *

Example of usage on the server: - * - *

{@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.
-   *   }
-   * }
-   * }
- * - * @return the {@code BinaryFormat} for this implementation. - * @since 0.1.0 - */ - BinaryFormat getBinaryFormat(); - /** * Returns the {@link HttpTextFormat} for this implementation. * diff --git a/api/src/main/java/io/opentelemetry/correlationcontext/DefaultCorrelationContextManager.java b/api/src/main/java/io/opentelemetry/correlationcontext/DefaultCorrelationContextManager.java index f804ba8f74a..e55555f61d8 100644 --- a/api/src/main/java/io/opentelemetry/correlationcontext/DefaultCorrelationContextManager.java +++ b/api/src/main/java/io/opentelemetry/correlationcontext/DefaultCorrelationContextManager.java @@ -17,7 +17,6 @@ package io.opentelemetry.correlationcontext; import io.opentelemetry.context.Scope; -import io.opentelemetry.context.propagation.BinaryFormat; import io.opentelemetry.context.propagation.HttpTextFormat; import io.opentelemetry.correlationcontext.unsafe.ContextUtils; import io.opentelemetry.internal.Utils; @@ -35,7 +34,6 @@ public final class DefaultCorrelationContextManager implements CorrelationContextManager { private static final DefaultCorrelationContextManager INSTANCE = new DefaultCorrelationContextManager(); - private static final BinaryFormat BINARY_FORMAT = new NoopBinaryFormat(); private static final HttpTextFormat HTTP_TEXT_FORMAT = new NoopHttpTextFormat(); @@ -66,11 +64,6 @@ public Scope withContext(CorrelationContext distContext) { return ContextUtils.withCorrelationContext(distContext); } - @Override - public BinaryFormat getBinaryFormat() { - return BINARY_FORMAT; - } - @Override public HttpTextFormat getHttpTextFormat() { return HTTP_TEXT_FORMAT; @@ -110,23 +103,6 @@ public CorrelationContext build() { } } - @Immutable - private static final class NoopBinaryFormat implements BinaryFormat { - 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 private static final class NoopHttpTextFormat implements HttpTextFormat { @Override diff --git a/api/src/main/java/io/opentelemetry/trace/DefaultTracer.java b/api/src/main/java/io/opentelemetry/trace/DefaultTracer.java index 11bab3947e2..295b2a27287 100644 --- a/api/src/main/java/io/opentelemetry/trace/DefaultTracer.java +++ b/api/src/main/java/io/opentelemetry/trace/DefaultTracer.java @@ -17,10 +17,8 @@ package io.opentelemetry.trace; import io.opentelemetry.context.Scope; -import io.opentelemetry.context.propagation.BinaryFormat; import io.opentelemetry.context.propagation.HttpTextFormat; import io.opentelemetry.internal.Utils; -import io.opentelemetry.trace.propagation.BinaryTraceContext; import io.opentelemetry.trace.propagation.HttpTraceContext; import io.opentelemetry.trace.unsafe.ContextUtils; import java.util.Map; @@ -34,7 +32,6 @@ @ThreadSafe public final class DefaultTracer implements Tracer { private static final DefaultTracer INSTANCE = new DefaultTracer(); - private static final BinaryFormat BINARY_FORMAT = new BinaryTraceContext(); private static final HttpTextFormat HTTP_TEXT_FORMAT = new HttpTraceContext(); /** @@ -62,11 +59,6 @@ public Span.Builder spanBuilder(String spanName) { return NoopSpanBuilder.create(this, spanName); } - @Override - public BinaryFormat getBinaryFormat() { - return BINARY_FORMAT; - } - @Override public HttpTextFormat getHttpTextFormat() { return HTTP_TEXT_FORMAT; diff --git a/api/src/main/java/io/opentelemetry/trace/Tracer.java b/api/src/main/java/io/opentelemetry/trace/Tracer.java index a49df4584f6..703cc3c2adf 100644 --- a/api/src/main/java/io/opentelemetry/trace/Tracer.java +++ b/api/src/main/java/io/opentelemetry/trace/Tracer.java @@ -18,7 +18,6 @@ import com.google.errorprone.annotations.MustBeClosed; import io.opentelemetry.context.Scope; -import io.opentelemetry.context.propagation.BinaryFormat; import io.opentelemetry.context.propagation.HttpTextFormat; import io.opentelemetry.trace.propagation.HttpTraceContext; import javax.annotation.concurrent.ThreadSafe; @@ -154,56 +153,6 @@ public interface Tracer { */ Span.Builder spanBuilder(String spanName); - /** - * Returns the {@link BinaryFormat} for this tracer implementation. - * - *

If no tracer implementation is provided, this defaults to the W3C Trace Context binary - * format. For more details see W3C Trace - * Context binary protocol. - * - *

Example of usage on the client: - * - *

{@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();
-   *   }
-   * }
-   * }
- * - *

Example of usage on the server: - * - *

{@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();
-   *   }
-   * }
-   * }
- * - * @return the {@code BinaryFormat} for this implementation. - * @since 0.1.0 - */ - BinaryFormat getBinaryFormat(); - /** * Returns the {@link HttpTextFormat} for this tracer implementation. * diff --git a/api/src/main/java/io/opentelemetry/trace/propagation/BinaryTraceContext.java b/api/src/main/java/io/opentelemetry/trace/propagation/BinaryTraceContext.java deleted file mode 100644 index 2c348634336..00000000000 --- a/api/src/main/java/io/opentelemetry/trace/propagation/BinaryTraceContext.java +++ /dev/null @@ -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}. - * - *

Format: - * - *

    - *
  • Binary value: <version_id><version_format> - *
  • version_id: 1-byte representing the version id. - *
  • For version_id = 0: - *
      - *
    • version_format: <field><field> - *
    • field_format: <field_id><field_format> - *
    • Fields: - *
        - *
      • TraceId: (field_id = 0, len = 16, default = "0000000000000000") - - * 16-byte array representing the trace_id. - *
      • SpanId: (field_id = 1, len = 8, default = "00000000") - 8-byte array - * representing the span_id. - *
      • TraceFlags: (field_id = 2, len = 1, default = "0") - 1-byte array - * representing the trace_options. - *
      - *
    • Fields MUST be encoded using the field id order (smaller to higher). - *
    • Valid value example: - *
        - *
      • {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} - *
      • version_id = 0; - *
      • trace_id = {64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79} - *
      • span_id = {97, 98, 99, 100, 101, 102, 103, 104}; - *
      • trace_options = {1}; - *
      - *
    - *
- */ -@Immutable -public final class BinaryTraceContext implements BinaryFormat { - - 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); - } -} diff --git a/api/src/test/java/io/opentelemetry/OpenTelemetryTest.java b/api/src/test/java/io/opentelemetry/OpenTelemetryTest.java index 2501d69230b..82379198c9b 100644 --- a/api/src/test/java/io/opentelemetry/OpenTelemetryTest.java +++ b/api/src/test/java/io/opentelemetry/OpenTelemetryTest.java @@ -20,7 +20,6 @@ import static org.junit.Assert.assertTrue; import io.opentelemetry.context.Scope; -import io.opentelemetry.context.propagation.BinaryFormat; import io.opentelemetry.context.propagation.HttpTextFormat; import io.opentelemetry.correlationcontext.CorrelationContext; import io.opentelemetry.correlationcontext.CorrelationContextManager; @@ -268,12 +267,6 @@ public Span.Builder spanBuilder(String spanName) { return null; } - @Nullable - @Override - public BinaryFormat getBinaryFormat() { - return null; - } - @Nullable @Override public HttpTextFormat getHttpTextFormat() { @@ -406,12 +399,6 @@ public Scope withContext(CorrelationContext distContext) { return null; } - @Nullable - @Override - public BinaryFormat getBinaryFormat() { - return null; - } - @Nullable @Override public HttpTextFormat getHttpTextFormat() { diff --git a/api/src/test/java/io/opentelemetry/trace/DefaultTracerTest.java b/api/src/test/java/io/opentelemetry/trace/DefaultTracerTest.java index cd1569abaf3..605ddc99927 100644 --- a/api/src/test/java/io/opentelemetry/trace/DefaultTracerTest.java +++ b/api/src/test/java/io/opentelemetry/trace/DefaultTracerTest.java @@ -19,7 +19,6 @@ import static com.google.common.truth.Truth.assertThat; import io.opentelemetry.context.Scope; -import io.opentelemetry.trace.propagation.BinaryTraceContext; import io.opentelemetry.trace.propagation.HttpTraceContext; import org.junit.Rule; import org.junit.Test; @@ -79,11 +78,6 @@ public void defaultHttpTextFormat() { assertThat(defaultTracer.getHttpTextFormat()).isInstanceOf(HttpTraceContext.class); } - @Test - public void defaultBinaryFormat() { - assertThat(defaultTracer.getBinaryFormat()).isInstanceOf(BinaryTraceContext.class); - } - @Test public void testInProcessContext() { Span span = defaultTracer.spanBuilder(SPAN_NAME).startSpan(); diff --git a/api/src/test/java/io/opentelemetry/trace/propagation/BinaryTraceContextTest.java b/api/src/test/java/io/opentelemetry/trace/propagation/BinaryTraceContextTest.java deleted file mode 100644 index 45ec47a25c8..00000000000 --- a/api/src/test/java/io/opentelemetry/trace/propagation/BinaryTraceContextTest.java +++ /dev/null @@ -1,200 +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 expectedException = ExpectedException.none(); - private final BinaryFormat 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(expected = NullPointerException.class) - public void toBinaryValue_NullSpanContext() { - 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(expected = NullPointerException.class) - public void fromBinaryValue_NullInput() { - binaryFormat.fromByteArray(null); - } - - @Test - public void fromBinaryValue_EmptyInput() { - expectedException.expect(IllegalArgumentException.class); - expectedException.expectMessage("Unsupported version."); - binaryFormat.fromByteArray(new byte[0]); - } - - @Test - public void fromBinaryValue_UnsupportedVersionId() { - expectedException.expect(IllegalArgumentException.class); - expectedException.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() { - expectedException.expect(IllegalArgumentException.class); - expectedException.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() { - expectedException.expect(IllegalArgumentException.class); - expectedException.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() { - expectedException.expect(IllegalArgumentException.class); - expectedException.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() { - expectedException.expect(IllegalArgumentException.class); - expectedException.expectMessage("Invalid input: truncated"); - binaryFormat.fromByteArray(new byte[] {0, 1, 97, 98, 99, 100, 101, 102, 103}); - } - - @Test - public void fromBinaryValue_ShorterTraceFlags() { - expectedException.expect(IllegalArgumentException.class); - expectedException.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()); - } -} diff --git a/context_prop/src/main/java/io/opentelemetry/context/propagation/BinaryFormat.java b/context_prop/src/main/java/io/opentelemetry/context/propagation/BinaryFormat.java deleted file mode 100644 index f25c0b1c808..00000000000 --- a/context_prop/src/main/java/io/opentelemetry/context/propagation/BinaryFormat.java +++ /dev/null @@ -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 { - - /** - * 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. - * - *

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); -} diff --git a/opentracing_shim/src/main/java/io/opentelemetry/opentracingshim/Propagation.java b/opentracing_shim/src/main/java/io/opentelemetry/opentracingshim/Propagation.java index eeb7ea2d430..2852cc58030 100644 --- a/opentracing_shim/src/main/java/io/opentelemetry/opentracingshim/Propagation.java +++ b/opentracing_shim/src/main/java/io/opentelemetry/opentracingshim/Propagation.java @@ -17,10 +17,8 @@ package io.opentelemetry.opentracingshim; import io.opentelemetry.context.propagation.HttpTextFormat; -import io.opentracing.propagation.Binary; import io.opentracing.propagation.TextMapExtract; import io.opentracing.propagation.TextMapInject; -import java.nio.ByteBuffer; import java.util.HashMap; import java.util.Map; import javax.annotation.Nullable; @@ -79,19 +77,4 @@ public String get(Map carrier, String 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)); - } } diff --git a/opentracing_shim/src/main/java/io/opentelemetry/opentracingshim/TracerShim.java b/opentracing_shim/src/main/java/io/opentelemetry/opentracingshim/TracerShim.java index ef410ccac11..7aa8956a921 100644 --- a/opentracing_shim/src/main/java/io/opentelemetry/opentracingshim/TracerShim.java +++ b/opentracing_shim/src/main/java/io/opentelemetry/opentracingshim/TracerShim.java @@ -21,7 +21,6 @@ import io.opentracing.Span; import io.opentracing.SpanContext; import io.opentracing.Tracer; -import io.opentracing.propagation.Binary; import io.opentracing.propagation.Format; import io.opentracing.propagation.TextMapExtract; import io.opentracing.propagation.TextMapInject; @@ -73,8 +72,6 @@ public void inject(SpanContext context, Format format, C carrier) { || format == Format.Builtin.TEXT_MAP_INJECT || format == Format.Builtin.HTTP_HEADERS) { propagation.injectTextFormat(contextShim, (TextMapInject) carrier); - } else if (format == Format.Builtin.BINARY) { - propagation.injectBinaryFormat(contextShim, (Binary) carrier); } } @@ -86,8 +83,6 @@ public SpanContext extract(Format format, C carrier) { || format == Format.Builtin.TEXT_MAP_EXTRACT || format == Format.Builtin.HTTP_HEADERS) { return propagation.extractTextFormat((TextMapExtract) carrier); - } else if (format == Format.Builtin.BINARY) { - return propagation.extractBinaryFormat((Binary) carrier); } } catch (Exception e) { logger.log( diff --git a/sdk/src/main/java/io/opentelemetry/sdk/correlationcontext/CorrelationContextManagerSdk.java b/sdk/src/main/java/io/opentelemetry/sdk/correlationcontext/CorrelationContextManagerSdk.java index b7938beae49..e80737bbd0b 100644 --- a/sdk/src/main/java/io/opentelemetry/sdk/correlationcontext/CorrelationContextManagerSdk.java +++ b/sdk/src/main/java/io/opentelemetry/sdk/correlationcontext/CorrelationContextManagerSdk.java @@ -17,7 +17,6 @@ package io.opentelemetry.sdk.correlationcontext; import io.opentelemetry.context.Scope; -import io.opentelemetry.context.propagation.BinaryFormat; import io.opentelemetry.context.propagation.HttpTextFormat; import io.opentelemetry.correlationcontext.CorrelationContext; import io.opentelemetry.correlationcontext.CorrelationContextManager; @@ -44,12 +43,6 @@ public Scope withContext(CorrelationContext distContext) { return ContextUtils.withCorrelationContext(distContext); } - @Override - public BinaryFormat getBinaryFormat() { - // TODO: Implement this. - return DefaultCorrelationContextManager.getInstance().getBinaryFormat(); - } - @Override public HttpTextFormat getHttpTextFormat() { // TODO: Implement this. diff --git a/sdk/src/main/java/io/opentelemetry/sdk/trace/TracerSdk.java b/sdk/src/main/java/io/opentelemetry/sdk/trace/TracerSdk.java index 4f5f26f9fa4..d9d9b3a54aa 100644 --- a/sdk/src/main/java/io/opentelemetry/sdk/trace/TracerSdk.java +++ b/sdk/src/main/java/io/opentelemetry/sdk/trace/TracerSdk.java @@ -17,20 +17,17 @@ package io.opentelemetry.sdk.trace; import io.opentelemetry.context.Scope; -import io.opentelemetry.context.propagation.BinaryFormat; import io.opentelemetry.context.propagation.HttpTextFormat; import io.opentelemetry.sdk.common.InstrumentationLibraryInfo; import io.opentelemetry.trace.DefaultTracer; import io.opentelemetry.trace.Span; import io.opentelemetry.trace.SpanContext; import io.opentelemetry.trace.Tracer; -import io.opentelemetry.trace.propagation.BinaryTraceContext; import io.opentelemetry.trace.propagation.HttpTraceContext; import io.opentelemetry.trace.unsafe.ContextUtils; /** {@link TracerSdk} is SDK implementation of {@link Tracer}. */ public final class TracerSdk implements Tracer { - private static final BinaryFormat BINARY_FORMAT = new BinaryTraceContext(); private static final HttpTextFormat HTTP_TEXT_FORMAT = new HttpTraceContext(); private final TracerSharedState sharedState; private final InstrumentationLibraryInfo instrumentationLibraryInfo; @@ -65,11 +62,6 @@ public Span.Builder spanBuilder(String spanName) { sharedState.getClock()); } - @Override - public BinaryFormat getBinaryFormat() { - return BINARY_FORMAT; - } - @Override public HttpTextFormat getHttpTextFormat() { return HTTP_TEXT_FORMAT; diff --git a/sdk/src/test/java/io/opentelemetry/sdk/trace/TracerSdkTest.java b/sdk/src/test/java/io/opentelemetry/sdk/trace/TracerSdkTest.java index eb5de9e6c93..14e304f0512 100644 --- a/sdk/src/test/java/io/opentelemetry/sdk/trace/TracerSdkTest.java +++ b/sdk/src/test/java/io/opentelemetry/sdk/trace/TracerSdkTest.java @@ -23,7 +23,6 @@ import io.opentelemetry.sdk.common.InstrumentationLibraryInfo; import io.opentelemetry.trace.DefaultSpan; import io.opentelemetry.trace.Span; -import io.opentelemetry.trace.propagation.BinaryTraceContext; import io.opentelemetry.trace.propagation.HttpTraceContext; import io.opentelemetry.trace.unsafe.ContextUtils; import org.junit.Before; @@ -72,11 +71,6 @@ public void defaultHttpTextFormat() { assertThat(tracer.getHttpTextFormat()).isInstanceOf(HttpTraceContext.class); } - @Test - public void defaultBinaryFormat() { - assertThat(tracer.getBinaryFormat()).isInstanceOf(BinaryTraceContext.class); - } - @Test public void getCurrentSpan() { assertThat(tracer.getCurrentSpan()).isInstanceOf(DefaultSpan.class);