chore: remove binary propagator (#804)
* chore: remove binary format Co-authored-by: Daniel Dyla <dyladan@users.noreply.github.com>
This commit is contained in:
parent
e2f971dfef
commit
a34d03a8f1
|
|
@ -1,36 +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
|
|
||||||
*
|
|
||||||
* https://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.
|
|
||||||
*/
|
|
||||||
|
|
||||||
import { SpanContext } from '../../trace/span_context';
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Formatter to serializing and deserializing a value with into a binary format.
|
|
||||||
*/
|
|
||||||
export interface BinaryFormat {
|
|
||||||
/**
|
|
||||||
* Serialize the given span context into a Buffer.
|
|
||||||
* @param spanContext The span context to serialize.
|
|
||||||
*/
|
|
||||||
toBytes(spanContext: SpanContext): ArrayBuffer;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Deseralize the given span context from binary encoding. If the input is a
|
|
||||||
* Buffer of incorrect size or unexpected fields, then this function will
|
|
||||||
* return `null`.
|
|
||||||
* @param buffer The span context to deserialize.
|
|
||||||
*/
|
|
||||||
fromBytes(buffer: ArrayBuffer): SpanContext | null;
|
|
||||||
}
|
|
||||||
|
|
@ -19,8 +19,9 @@ import { Carrier } from './carrier';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Injects {@link Context} into and extracts it from carriers that travel
|
* Injects {@link Context} into and extracts it from carriers that travel
|
||||||
* in-band across process boundaries. Encoding is expected to conform to the HTTP
|
* in-band across process boundaries. Encoding is expected to conform to the
|
||||||
* Header Field semantics. Values are often encoded as RPC/HTTP request headers.
|
* HTTP Header Field semantics. Values are often encoded as RPC/HTTP request
|
||||||
|
* headers.
|
||||||
*
|
*
|
||||||
* The carrier of propagated data on both the client (injector) and server
|
* The carrier of propagated data on both the client (injector) and server
|
||||||
* (extractor) side is usually an object such as http headers.
|
* (extractor) side is usually an object such as http headers.
|
||||||
|
|
@ -29,20 +30,25 @@ export interface HttpTextFormat {
|
||||||
/**
|
/**
|
||||||
* Injects values from a given {@link Context} into a carrier.
|
* Injects values from a given {@link Context} into a carrier.
|
||||||
*
|
*
|
||||||
* OpenTelemetry defines a common set of format values (BinaryFormat and
|
* OpenTelemetry defines a common set of format values (HTTPTextFormat), and
|
||||||
* HTTPTextFormat), and each has an expected `carrier` type.
|
* each has an expected `carrier` type.
|
||||||
*
|
*
|
||||||
* @param context the Context from which to extract values to transmit over the wire.
|
* @param context the Context from which to extract values to transmit over
|
||||||
* @param carrier the carrier of propagation fields, such as http request headers.
|
* the wire.
|
||||||
|
* @param carrier the carrier of propagation fields, such as http request
|
||||||
|
* headers.
|
||||||
*/
|
*/
|
||||||
inject(context: Context, carrier: Carrier): void;
|
inject(context: Context, carrier: Carrier): void;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Given a {@link Context} and a carrier, extract context values from a carrier and
|
* Given a {@link Context} and a carrier, extract context values from a
|
||||||
* return a new context, created from the old context, with the extracted values.
|
* carrier and return a new context, created from the old context, with the
|
||||||
|
* extracted values.
|
||||||
*
|
*
|
||||||
* @param context the Context from which to extract values to transmit over the wire.
|
* @param context the Context from which to extract values to transmit over
|
||||||
* @param carrier the carrier of propagation fields, such as http request headers.
|
* the wire.
|
||||||
|
* @param carrier the carrier of propagation fields, such as http request
|
||||||
|
* headers.
|
||||||
*/
|
*/
|
||||||
extract(context: Context, carrier: Carrier): Context;
|
extract(context: Context, carrier: Carrier): Context;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,36 +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
|
|
||||||
*
|
|
||||||
* https://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.
|
|
||||||
*/
|
|
||||||
|
|
||||||
import { SpanContext } from '../../trace/span_context';
|
|
||||||
import { BinaryFormat } from './BinaryFormat';
|
|
||||||
|
|
||||||
/**
|
|
||||||
* No-op implementations of {@link BinaryFormat}.
|
|
||||||
*/
|
|
||||||
export class NoopBinaryFormat implements BinaryFormat {
|
|
||||||
private readonly _buff = new ArrayBuffer(0);
|
|
||||||
// By default does nothing
|
|
||||||
toBytes(spanContext: SpanContext): ArrayBuffer {
|
|
||||||
return this._buff;
|
|
||||||
}
|
|
||||||
|
|
||||||
// By default does nothing
|
|
||||||
fromBytes(buf: ArrayBuffer): SpanContext | null {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
export const NOOP_BINARY_FORMAT = new NoopBinaryFormat();
|
|
||||||
|
|
@ -16,7 +16,6 @@
|
||||||
|
|
||||||
export * from './common/Logger';
|
export * from './common/Logger';
|
||||||
export * from './common/Time';
|
export * from './common/Time';
|
||||||
export * from './context/propagation/BinaryFormat';
|
|
||||||
export * from './context/propagation/carrier';
|
export * from './context/propagation/carrier';
|
||||||
export * from './context/propagation/HttpTextFormat';
|
export * from './context/propagation/HttpTextFormat';
|
||||||
export * from './distributed_context/DistributedContext';
|
export * from './distributed_context/DistributedContext';
|
||||||
|
|
|
||||||
|
|
@ -14,8 +14,7 @@
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { BinaryFormat, HttpTextFormat, Span, SpanOptions, Tracer } from '..';
|
import { HttpTextFormat, Span, SpanOptions, Tracer } from '..';
|
||||||
import { NOOP_BINARY_FORMAT } from '../context/propagation/NoopBinaryFormat';
|
|
||||||
import { NOOP_HTTP_TEXT_FORMAT } from '../context/propagation/NoopHttpTextFormat';
|
import { NOOP_HTTP_TEXT_FORMAT } from '../context/propagation/NoopHttpTextFormat';
|
||||||
import { NOOP_SPAN } from './NoopSpan';
|
import { NOOP_SPAN } from './NoopSpan';
|
||||||
|
|
||||||
|
|
@ -43,11 +42,6 @@ export class NoopTracer implements Tracer {
|
||||||
return target;
|
return target;
|
||||||
}
|
}
|
||||||
|
|
||||||
// By default does nothing
|
|
||||||
getBinaryFormat(): BinaryFormat {
|
|
||||||
return NOOP_BINARY_FORMAT;
|
|
||||||
}
|
|
||||||
|
|
||||||
// By default does nothing
|
// By default does nothing
|
||||||
getHttpTextFormat(): HttpTextFormat {
|
getHttpTextFormat(): HttpTextFormat {
|
||||||
return NOOP_HTTP_TEXT_FORMAT;
|
return NOOP_HTTP_TEXT_FORMAT;
|
||||||
|
|
|
||||||
|
|
@ -15,7 +15,6 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { HttpTextFormat } from '../context/propagation/HttpTextFormat';
|
import { HttpTextFormat } from '../context/propagation/HttpTextFormat';
|
||||||
import { BinaryFormat } from '../context/propagation/BinaryFormat';
|
|
||||||
import { Span } from './span';
|
import { Span } from './span';
|
||||||
import { SpanOptions } from './SpanOptions';
|
import { SpanOptions } from './SpanOptions';
|
||||||
|
|
||||||
|
|
@ -65,19 +64,6 @@ export interface Tracer {
|
||||||
*/
|
*/
|
||||||
bind<T>(target: T, span?: Span): T;
|
bind<T>(target: T, span?: Span): T;
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns the {@link BinaryFormat} interface which can serialize/deserialize
|
|
||||||
* Spans.
|
|
||||||
*
|
|
||||||
* If no tracer implementation is provided, this defaults to the W3C Trace
|
|
||||||
* Context binary format {@link BinaryFormat}. For more details see
|
|
||||||
* <a href="https://w3c.github.io/trace-context-binary/">W3C Trace Context
|
|
||||||
* binary protocol</a>.
|
|
||||||
*
|
|
||||||
* @returns the {@link BinaryFormat} for this implementation.
|
|
||||||
*/
|
|
||||||
getBinaryFormat(): BinaryFormat;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the {@link HttpTextFormat} interface which can inject/extract
|
* Returns the {@link HttpTextFormat} interface which can inject/extract
|
||||||
* Spans.
|
* Spans.
|
||||||
|
|
|
||||||
|
|
@ -29,7 +29,6 @@ describe('API', () => {
|
||||||
'getCurrentSpan',
|
'getCurrentSpan',
|
||||||
'startSpan',
|
'startSpan',
|
||||||
'withSpan',
|
'withSpan',
|
||||||
'getBinaryFormat',
|
|
||||||
'getHttpTextFormat',
|
'getHttpTextFormat',
|
||||||
];
|
];
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -20,7 +20,6 @@ import { Context } from '@opentelemetry/scope-base';
|
||||||
|
|
||||||
describe('NoopTracer', () => {
|
describe('NoopTracer', () => {
|
||||||
it('should not crash', () => {
|
it('should not crash', () => {
|
||||||
const spanContext = { traceId: '', spanId: '' };
|
|
||||||
const tracer = new NoopTracer();
|
const tracer = new NoopTracer();
|
||||||
|
|
||||||
assert.deepStrictEqual(tracer.startSpan('span-name'), NOOP_SPAN);
|
assert.deepStrictEqual(tracer.startSpan('span-name'), NOOP_SPAN);
|
||||||
|
|
@ -45,11 +44,6 @@ describe('NoopTracer', () => {
|
||||||
httpTextFormat.extract(Context.ROOT_CONTEXT, {}),
|
httpTextFormat.extract(Context.ROOT_CONTEXT, {}),
|
||||||
Context.ROOT_CONTEXT
|
Context.ROOT_CONTEXT
|
||||||
);
|
);
|
||||||
|
|
||||||
const binaryFormat = tracer.getBinaryFormat();
|
|
||||||
assert.ok(binaryFormat);
|
|
||||||
assert.ok(binaryFormat.toBytes(spanContext), typeof ArrayBuffer);
|
|
||||||
assert.deepStrictEqual(binaryFormat.fromBytes(new ArrayBuffer(0)), null);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should not crash when .withSpan()', done => {
|
it('should not crash when .withSpan()', done => {
|
||||||
|
|
|
||||||
|
|
@ -1,113 +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
|
|
||||||
*
|
|
||||||
* https://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.
|
|
||||||
*/
|
|
||||||
|
|
||||||
import { BinaryFormat, SpanContext, TraceFlags } from '@opentelemetry/api';
|
|
||||||
|
|
||||||
const VERSION_ID = 0;
|
|
||||||
const TRACE_ID_FIELD_ID = 0;
|
|
||||||
const SPAN_ID_FIELD_ID = 1;
|
|
||||||
const TRACE_OPTION_FIELD_ID = 2;
|
|
||||||
|
|
||||||
// Sizes are number of bytes.
|
|
||||||
const ID_SIZE = 1;
|
|
||||||
const TRACE_ID_SIZE = 16;
|
|
||||||
const SPAN_ID_SIZE = 8;
|
|
||||||
const TRACE_OPTION_SIZE = 1;
|
|
||||||
|
|
||||||
const VERSION_ID_OFFSET = 0;
|
|
||||||
const TRACE_ID_FIELD_ID_OFFSET = VERSION_ID_OFFSET + ID_SIZE;
|
|
||||||
const TRACE_ID_OFFSET = TRACE_ID_FIELD_ID_OFFSET + ID_SIZE;
|
|
||||||
const SPAN_ID_FIELD_ID_OFFSET = TRACE_ID_OFFSET + TRACE_ID_SIZE;
|
|
||||||
const SPAN_ID_OFFSET = SPAN_ID_FIELD_ID_OFFSET + ID_SIZE;
|
|
||||||
const TRACE_OPTION_FIELD_ID_OFFSET = SPAN_ID_OFFSET + SPAN_ID_SIZE;
|
|
||||||
const TRACE_OPTIONS_OFFSET = TRACE_OPTION_FIELD_ID_OFFSET + ID_SIZE;
|
|
||||||
|
|
||||||
const FORMAT_LENGTH =
|
|
||||||
4 * ID_SIZE + TRACE_ID_SIZE + SPAN_ID_SIZE + TRACE_OPTION_SIZE;
|
|
||||||
|
|
||||||
export class BinaryTraceContext implements BinaryFormat {
|
|
||||||
toBytes(spanContext: SpanContext): Uint8Array {
|
|
||||||
/**
|
|
||||||
* 0 1 2
|
|
||||||
* 0 1 2345678901234567 8 90123456 7 8
|
|
||||||
* -------------------------------------
|
|
||||||
* | | | | | | | |
|
|
||||||
* -------------------------------------
|
|
||||||
* ^ ^ ^ ^ ^ ^ ^
|
|
||||||
* | | | | | | `-- options value
|
|
||||||
* | | | | | `---- options field ID (2)
|
|
||||||
* | | | | `---------- spanID value
|
|
||||||
* | | | `--------------- spanID field ID (1)
|
|
||||||
* | | `--------------------------- traceID value
|
|
||||||
* | `---------------------------------- traceID field ID (0)
|
|
||||||
* `------------------------------------ version (0)
|
|
||||||
*/
|
|
||||||
const traceId = spanContext.traceId;
|
|
||||||
const spanId = spanContext.spanId;
|
|
||||||
const buf = new Uint8Array(FORMAT_LENGTH);
|
|
||||||
let j = TRACE_ID_OFFSET;
|
|
||||||
for (let i = TRACE_ID_OFFSET; i < SPAN_ID_FIELD_ID_OFFSET; i++) {
|
|
||||||
// tslint:disable-next-line:ban Needed to parse hexadecimal.
|
|
||||||
buf[j++] = parseInt(traceId.substr((i - TRACE_ID_OFFSET) * 2, 2), 16);
|
|
||||||
}
|
|
||||||
buf[j++] = SPAN_ID_FIELD_ID;
|
|
||||||
for (let i = SPAN_ID_OFFSET; i < TRACE_OPTION_FIELD_ID_OFFSET; i++) {
|
|
||||||
// tslint:disable-next-line:ban Needed to parse hexadecimal.
|
|
||||||
buf[j++] = parseInt(spanId.substr((i - SPAN_ID_OFFSET) * 2, 2), 16);
|
|
||||||
}
|
|
||||||
buf[j++] = TRACE_OPTION_FIELD_ID;
|
|
||||||
buf[j++] = Number(spanContext.traceFlags) || TraceFlags.UNSAMPLED;
|
|
||||||
return buf;
|
|
||||||
}
|
|
||||||
|
|
||||||
fromBytes(buf: Uint8Array): SpanContext | null {
|
|
||||||
const result: SpanContext = { traceId: '', spanId: '' };
|
|
||||||
// Length must be 29.
|
|
||||||
if (buf.length !== FORMAT_LENGTH) return null;
|
|
||||||
// Check version and field numbers.
|
|
||||||
if (
|
|
||||||
buf[VERSION_ID_OFFSET] !== VERSION_ID ||
|
|
||||||
buf[TRACE_ID_FIELD_ID_OFFSET] !== TRACE_ID_FIELD_ID ||
|
|
||||||
buf[SPAN_ID_FIELD_ID_OFFSET] !== SPAN_ID_FIELD_ID ||
|
|
||||||
buf[TRACE_OPTION_FIELD_ID_OFFSET] !== TRACE_OPTION_FIELD_ID
|
|
||||||
) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
result.isRemote = true;
|
|
||||||
|
|
||||||
// See serializeSpanContext for byte offsets.
|
|
||||||
result.traceId = toHex(buf.slice(TRACE_ID_OFFSET, SPAN_ID_FIELD_ID_OFFSET));
|
|
||||||
result.spanId = toHex(
|
|
||||||
buf.slice(SPAN_ID_OFFSET, TRACE_OPTION_FIELD_ID_OFFSET)
|
|
||||||
);
|
|
||||||
result.traceFlags = buf[TRACE_OPTIONS_OFFSET];
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function toHex(buff: Uint8Array) {
|
|
||||||
let out = '';
|
|
||||||
for (let i = 0; i < buff.length; ++i) {
|
|
||||||
const n = buff[i];
|
|
||||||
if (n < 16) {
|
|
||||||
out += '0' + n.toString(16);
|
|
||||||
} else {
|
|
||||||
out += n.toString(16);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return out;
|
|
||||||
}
|
|
||||||
|
|
@ -21,7 +21,6 @@ export * from './common/types';
|
||||||
export * from './version';
|
export * from './version';
|
||||||
export * from './context/context';
|
export * from './context/context';
|
||||||
export * from './context/propagation/B3Format';
|
export * from './context/propagation/B3Format';
|
||||||
export * from './context/propagation/BinaryTraceContext';
|
|
||||||
export * from './context/propagation/HttpTraceContext';
|
export * from './context/propagation/HttpTraceContext';
|
||||||
export * from './platform';
|
export * from './platform';
|
||||||
export * from './trace/instrumentation/BasePlugin';
|
export * from './trace/instrumentation/BasePlugin';
|
||||||
|
|
|
||||||
|
|
@ -1,144 +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
|
|
||||||
*
|
|
||||||
* https://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.
|
|
||||||
*/
|
|
||||||
|
|
||||||
import * as assert from 'assert';
|
|
||||||
import { BinaryTraceContext } from '../../src/context/propagation/BinaryTraceContext';
|
|
||||||
import { SpanContext, TraceFlags } from '@opentelemetry/api';
|
|
||||||
|
|
||||||
describe('BinaryTraceContext', () => {
|
|
||||||
const binaryTraceContext = new BinaryTraceContext();
|
|
||||||
const commonTraceId = 'd4cda95b652f4a1592b449d5929fda1b';
|
|
||||||
const commonSpanId = '75e8ed491aec7eca';
|
|
||||||
|
|
||||||
const testCases: Array<{
|
|
||||||
structured: SpanContext | null;
|
|
||||||
binary: Uint8Array;
|
|
||||||
description: string;
|
|
||||||
}> = [
|
|
||||||
{
|
|
||||||
structured: {
|
|
||||||
traceId: commonTraceId,
|
|
||||||
spanId: commonSpanId,
|
|
||||||
traceFlags: TraceFlags.SAMPLED,
|
|
||||||
},
|
|
||||||
binary: new Uint8Array([
|
|
||||||
0,
|
|
||||||
0,
|
|
||||||
212,
|
|
||||||
205,
|
|
||||||
169,
|
|
||||||
91,
|
|
||||||
101,
|
|
||||||
47,
|
|
||||||
74,
|
|
||||||
21,
|
|
||||||
146,
|
|
||||||
180,
|
|
||||||
73,
|
|
||||||
213,
|
|
||||||
146,
|
|
||||||
159,
|
|
||||||
218,
|
|
||||||
27,
|
|
||||||
1,
|
|
||||||
117,
|
|
||||||
232,
|
|
||||||
237,
|
|
||||||
73,
|
|
||||||
26,
|
|
||||||
236,
|
|
||||||
126,
|
|
||||||
202,
|
|
||||||
2,
|
|
||||||
1,
|
|
||||||
]),
|
|
||||||
description: 'span context with 64-bit span ID',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
structured: { traceId: commonTraceId, spanId: commonSpanId },
|
|
||||||
binary: new Uint8Array([
|
|
||||||
0,
|
|
||||||
0,
|
|
||||||
212,
|
|
||||||
205,
|
|
||||||
169,
|
|
||||||
91,
|
|
||||||
101,
|
|
||||||
47,
|
|
||||||
74,
|
|
||||||
21,
|
|
||||||
146,
|
|
||||||
180,
|
|
||||||
73,
|
|
||||||
213,
|
|
||||||
146,
|
|
||||||
159,
|
|
||||||
218,
|
|
||||||
27,
|
|
||||||
1,
|
|
||||||
117,
|
|
||||||
232,
|
|
||||||
237,
|
|
||||||
73,
|
|
||||||
26,
|
|
||||||
236,
|
|
||||||
126,
|
|
||||||
202,
|
|
||||||
2,
|
|
||||||
0,
|
|
||||||
]),
|
|
||||||
description: 'span context with no traceFlags',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
structured: null,
|
|
||||||
binary: new Uint8Array([0, 0]),
|
|
||||||
description: 'incomplete binary span context (by returning null)',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
structured: null,
|
|
||||||
binary: new Uint8Array(58),
|
|
||||||
description: 'bad binary span context (by returning null)',
|
|
||||||
},
|
|
||||||
];
|
|
||||||
|
|
||||||
describe('.toBytes()', () => {
|
|
||||||
testCases.forEach(
|
|
||||||
testCase =>
|
|
||||||
testCase.structured &&
|
|
||||||
it(`should serialize ${testCase.description}`, () => {
|
|
||||||
assert.deepStrictEqual(
|
|
||||||
binaryTraceContext.toBytes(testCase.structured!),
|
|
||||||
testCase.binary
|
|
||||||
);
|
|
||||||
})
|
|
||||||
);
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('.fromBytes()', () => {
|
|
||||||
testCases.forEach(testCase =>
|
|
||||||
it(`should deserialize ${testCase.description}`, () => {
|
|
||||||
assert.deepStrictEqual(
|
|
||||||
binaryTraceContext.fromBytes(testCase.binary),
|
|
||||||
testCase.structured &&
|
|
||||||
Object.assign(
|
|
||||||
{ isRemote: true, traceFlags: TraceFlags.UNSAMPLED },
|
|
||||||
testCase.structured
|
|
||||||
)
|
|
||||||
);
|
|
||||||
})
|
|
||||||
);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
@ -17,7 +17,6 @@
|
||||||
import * as assert from 'assert';
|
import * as assert from 'assert';
|
||||||
import {
|
import {
|
||||||
ALWAYS_SAMPLER,
|
ALWAYS_SAMPLER,
|
||||||
BinaryTraceContext,
|
|
||||||
HttpTraceContext,
|
HttpTraceContext,
|
||||||
NEVER_SAMPLER,
|
NEVER_SAMPLER,
|
||||||
NoopLogger,
|
NoopLogger,
|
||||||
|
|
@ -57,13 +56,6 @@ describe('NodeTracerProvider', () => {
|
||||||
assert.ok(provider instanceof NodeTracerProvider);
|
assert.ok(provider instanceof NodeTracerProvider);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should construct an instance with binary format', () => {
|
|
||||||
provider = new NodeTracerProvider({
|
|
||||||
binaryFormat: new BinaryTraceContext(),
|
|
||||||
});
|
|
||||||
assert.ok(provider instanceof NodeTracerProvider);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should construct an instance with http text format', () => {
|
it('should construct an instance with http text format', () => {
|
||||||
provider = new NodeTracerProvider({
|
provider = new NodeTracerProvider({
|
||||||
httpTextFormat: new HttpTraceContext(),
|
httpTextFormat: new HttpTraceContext(),
|
||||||
|
|
@ -262,16 +254,6 @@ describe('NodeTracerProvider', () => {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('.getBinaryFormat()', () => {
|
|
||||||
it('should get default binary formatter', () => {
|
|
||||||
provider = new NodeTracerProvider({});
|
|
||||||
assert.ok(
|
|
||||||
provider.getTracer('default').getBinaryFormat() instanceof
|
|
||||||
BinaryTraceContext
|
|
||||||
);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('.getHttpTextFormat()', () => {
|
describe('.getHttpTextFormat()', () => {
|
||||||
it('should get default HTTP text formatter', () => {
|
it('should get default HTTP text formatter', () => {
|
||||||
provider = new NodeTracerProvider({});
|
provider = new NodeTracerProvider({});
|
||||||
|
|
|
||||||
|
|
@ -36,7 +36,6 @@ import { mergeConfig } from './utility';
|
||||||
*/
|
*/
|
||||||
export class Tracer implements types.Tracer {
|
export class Tracer implements types.Tracer {
|
||||||
private readonly _defaultAttributes: types.Attributes;
|
private readonly _defaultAttributes: types.Attributes;
|
||||||
private readonly _binaryFormat: types.BinaryFormat;
|
|
||||||
private readonly _httpTextFormat: types.HttpTextFormat;
|
private readonly _httpTextFormat: types.HttpTextFormat;
|
||||||
private readonly _sampler: types.Sampler;
|
private readonly _sampler: types.Sampler;
|
||||||
private readonly _scopeManager: ScopeManager;
|
private readonly _scopeManager: ScopeManager;
|
||||||
|
|
@ -51,7 +50,6 @@ export class Tracer implements types.Tracer {
|
||||||
private _tracerProvider: BasicTracerProvider
|
private _tracerProvider: BasicTracerProvider
|
||||||
) {
|
) {
|
||||||
const localConfig = mergeConfig(config);
|
const localConfig = mergeConfig(config);
|
||||||
this._binaryFormat = localConfig.binaryFormat;
|
|
||||||
this._defaultAttributes = localConfig.defaultAttributes;
|
this._defaultAttributes = localConfig.defaultAttributes;
|
||||||
this._httpTextFormat = localConfig.httpTextFormat;
|
this._httpTextFormat = localConfig.httpTextFormat;
|
||||||
this._sampler = localConfig.sampler;
|
this._sampler = localConfig.sampler;
|
||||||
|
|
@ -141,13 +139,6 @@ export class Tracer implements types.Tracer {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns the binary format interface which can serialize/deserialize Spans.
|
|
||||||
*/
|
|
||||||
getBinaryFormat(): types.BinaryFormat {
|
|
||||||
return this._binaryFormat;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the HTTP text format interface which can inject/extract Spans.
|
* Returns the HTTP text format interface which can inject/extract Spans.
|
||||||
*/
|
*/
|
||||||
|
|
|
||||||
|
|
@ -16,7 +16,6 @@
|
||||||
|
|
||||||
import {
|
import {
|
||||||
ALWAYS_SAMPLER,
|
ALWAYS_SAMPLER,
|
||||||
BinaryTraceContext,
|
|
||||||
HttpTraceContext,
|
HttpTraceContext,
|
||||||
LogLevel,
|
LogLevel,
|
||||||
} from '@opentelemetry/core';
|
} from '@opentelemetry/core';
|
||||||
|
|
@ -37,7 +36,6 @@ export const DEFAULT_MAX_LINKS_PER_SPAN = 32;
|
||||||
*/
|
*/
|
||||||
export const DEFAULT_CONFIG = {
|
export const DEFAULT_CONFIG = {
|
||||||
defaultAttributes: {},
|
defaultAttributes: {},
|
||||||
binaryFormat: new BinaryTraceContext(),
|
|
||||||
httpTextFormat: new HttpTraceContext(),
|
httpTextFormat: new HttpTraceContext(),
|
||||||
logLevel: LogLevel.DEBUG,
|
logLevel: LogLevel.DEBUG,
|
||||||
sampler: ALWAYS_SAMPLER,
|
sampler: ALWAYS_SAMPLER,
|
||||||
|
|
|
||||||
|
|
@ -17,7 +17,6 @@
|
||||||
import { ScopeManager } from '@opentelemetry/scope-base';
|
import { ScopeManager } from '@opentelemetry/scope-base';
|
||||||
import {
|
import {
|
||||||
Attributes,
|
Attributes,
|
||||||
BinaryFormat,
|
|
||||||
HttpTextFormat,
|
HttpTextFormat,
|
||||||
Logger,
|
Logger,
|
||||||
Sampler,
|
Sampler,
|
||||||
|
|
@ -28,11 +27,6 @@ import { LogLevel } from '@opentelemetry/core';
|
||||||
* TracerConfig provides an interface for configuring a Basic Tracer.
|
* TracerConfig provides an interface for configuring a Basic Tracer.
|
||||||
*/
|
*/
|
||||||
export interface TracerConfig {
|
export interface TracerConfig {
|
||||||
/**
|
|
||||||
* Binary formatter which can serialize/deserialize Spans.
|
|
||||||
*/
|
|
||||||
binaryFormat?: BinaryFormat;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Attributed that will be applied on every span created by Tracer.
|
* Attributed that will be applied on every span created by Tracer.
|
||||||
* Useful to add infrastructure and environment information to your spans.
|
* Useful to add infrastructure and environment information to your spans.
|
||||||
|
|
|
||||||
|
|
@ -17,7 +17,6 @@
|
||||||
import { Context, TraceFlags } from '@opentelemetry/api';
|
import { Context, TraceFlags } from '@opentelemetry/api';
|
||||||
import {
|
import {
|
||||||
ALWAYS_SAMPLER,
|
ALWAYS_SAMPLER,
|
||||||
BinaryTraceContext,
|
|
||||||
HttpTraceContext,
|
HttpTraceContext,
|
||||||
NEVER_SAMPLER,
|
NEVER_SAMPLER,
|
||||||
NoopLogger,
|
NoopLogger,
|
||||||
|
|
@ -36,13 +35,6 @@ describe('BasicTracerProvider', () => {
|
||||||
assert.ok(provider instanceof BasicTracerProvider);
|
assert.ok(provider instanceof BasicTracerProvider);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should construct an instance with binary format', () => {
|
|
||||||
const provider = new BasicTracerProvider({
|
|
||||||
binaryFormat: new BinaryTraceContext(),
|
|
||||||
});
|
|
||||||
assert.ok(provider instanceof BasicTracerProvider);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should construct an instance with http text format', () => {
|
it('should construct an instance with http text format', () => {
|
||||||
const provider = new BasicTracerProvider({
|
const provider = new BasicTracerProvider({
|
||||||
httpTextFormat: new HttpTraceContext(),
|
httpTextFormat: new HttpTraceContext(),
|
||||||
|
|
@ -348,13 +340,6 @@ describe('BasicTracerProvider', () => {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('.getBinaryFormat()', () => {
|
|
||||||
it('should get default binary formatter', () => {
|
|
||||||
const tracer = new BasicTracerProvider().getTracer('default');
|
|
||||||
assert.ok(tracer.getBinaryFormat() instanceof BinaryTraceContext);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('.getHttpTextFormat()', () => {
|
describe('.getHttpTextFormat()', () => {
|
||||||
it('should get default HTTP text formatter', () => {
|
it('should get default HTTP text formatter', () => {
|
||||||
const tracer = new BasicTracerProvider().getTracer('default');
|
const tracer = new BasicTracerProvider().getTracer('default');
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue