Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move SpanContext isValid to the API #1447

Merged
merged 24 commits into from
Aug 31, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
5a7640d
refactor: make spanContext into class with isValid
srjames90 Aug 18, 2020
ee305c0
refactor: use class instantiation for spanContext
srjames90 Aug 18, 2020
9abb326
refactor: moves test and fix tests
srjames90 Aug 18, 2020
9c34b01
fix: add check for isValid
srjames90 Aug 19, 2020
3773f2a
revert: the changes to spanContext
srjames90 Aug 24, 2020
81b5506
refactor: move spancontext-utils to api package
srjames90 Aug 24, 2020
e83ae92
fix: lint and invalid psan id and invalid trace id
srjames90 Aug 24, 2020
2221074
fix: make isValid more robust
srjames90 Aug 24, 2020
c02e362
Merge branch 'master' into span-context-is-valid
srjames90 Aug 24, 2020
895db7a
refactor: rename isValid to isSpanContextValid
srjames90 Aug 25, 2020
cf20897
Merge branch 'master' into span-context-is-valid
srjames90 Aug 25, 2020
42db3c3
refactor: update regex and checks
srjames90 Aug 25, 2020
8641192
fix: export isSpanContextValid from api.trace
srjames90 Aug 26, 2020
6f695be
fix: run npm run lint:fix
srjames90 Aug 26, 2020
d555ab0
fix: run lint fix in api
srjames90 Aug 26, 2020
d537d85
Merge branch 'master' of https://github.com/open-telemetry/openteleme…
srjames90 Aug 26, 2020
f163513
refactor: prevent function overhead
srjames90 Aug 27, 2020
6e7f94f
fix: lint
srjames90 Aug 27, 2020
f38d97c
fix: remove unused import
srjames90 Aug 27, 2020
f8b7a6e
Merge branch 'master' into span-context-is-valid
srjames90 Aug 27, 2020
efe94a8
Merge branch 'master' into span-context-is-valid
srjames90 Aug 27, 2020
b72e068
Merge branch 'master' into span-context-is-valid
srjames90 Aug 31, 2020
73ee51d
Merge branch 'master' into span-context-is-valid
srjames90 Aug 31, 2020
9f8f599
Merge branch 'master' into span-context-is-valid
dyladan Aug 31, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
refactor: moves test and fix tests
  • Loading branch information
srjames90 committed Aug 19, 2020
commit 9abb326d316b2079eefeab6e56fa2d469c9659a5
11 changes: 1 addition & 10 deletions packages/opentelemetry-api/src/trace/NoopSpan.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,8 @@
import { TimeInput } from '../common/Time';
import { Attributes } from './attributes';
import { Span } from './span';
import { SpanContext } from './span_context';
import { INVALID_SPAN_CONTEXT, SpanContext } from './span_context';
import { Status } from './status';
import { TraceFlags } from './trace_flags';

export const INVALID_TRACE_ID = '0';
export const INVALID_SPAN_ID = '0';
const INVALID_SPAN_CONTEXT: SpanContext = new SpanContext({
traceId: INVALID_TRACE_ID,
spanId: INVALID_SPAN_ID,
traceFlags: TraceFlags.NONE,
});

/**
* The NoopSpan is the default {@link Span} that is used when no Span
Expand Down
11 changes: 8 additions & 3 deletions packages/opentelemetry-api/src/trace/span_context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,6 @@
import { TraceFlags } from './trace_flags';
import { TraceState } from './trace_state';

export const INVALID_SPANID = '0';
export const INVALID_TRACEID = '0';

/**
* A SpanContext represents the portion of a {@link Span} which must be
* serialized and propagated along side of a {@link CorrelationContext}.
Expand Down Expand Up @@ -97,3 +94,11 @@ export class SpanContext {
return this.traceId !== INVALID_TRACEID && this.spanId !== INVALID_SPANID;
}
}

export const INVALID_SPANID = '0';
srjames90 marked this conversation as resolved.
Show resolved Hide resolved
export const INVALID_TRACEID = '0';
export const INVALID_SPAN_CONTEXT: SpanContext = new SpanContext({
traceId: INVALID_TRACEID,
spanId: INVALID_SPANID,
traceFlags: TraceFlags.NONE,
});
40 changes: 40 additions & 0 deletions packages/opentelemetry-api/test/api/api.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ import api, {
SpanOptions,
Span,
SpanContext,
INVALID_TRACEID,
INVALID_SPANID,
context,
trace,
propagation,
Expand All @@ -38,6 +40,44 @@ describe('API', () => {
assert.strictEqual(typeof tracer, 'object');
});

describe('SpanContext', () => {
it('should return true for valid spancontext', () => {
const spanContext = new SpanContext({
traceId: 'd4cda95b652f4a1592b449d5929fda1b',
spanId: '6e0c63257de34c92',
traceFlags: TraceFlags.NONE,
});
assert.ok(spanContext.isValid());
});

it('should return false when traceId is invalid', () => {
const spanContext = new SpanContext({
traceId: INVALID_TRACEID,
spanId: '6e0c63257de34c92',
traceFlags: TraceFlags.NONE,
});
assert.ok(!spanContext.isValid());
});

it('should return false when spanId is invalid', () => {
const spanContext = new SpanContext({
traceId: 'd4cda95b652f4a1592b449d5929fda1b',
spanId: INVALID_SPANID,
traceFlags: TraceFlags.NONE,
});
assert.ok(!spanContext.isValid());
});

it('should return false when traceId & spanId is invalid', () => {
const spanContext = new SpanContext({
traceId: INVALID_TRACEID,
spanId: INVALID_SPANID,
traceFlags: TraceFlags.NONE,
});
assert.ok(!spanContext.isValid());
});
});

describe('GlobalTracerProvider', () => {
const spanContext = new SpanContext({
traceId: 'd4cda95b652f4a1592b449d5929fda1b',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
import * as assert from 'assert';
import {
CanonicalCode,
INVALID_SPAN_ID,
INVALID_TRACE_ID,
INVALID_SPANID,
INVALID_TRACEID,
NoopSpan,
SpanContext,
TraceFlags,
Expand All @@ -45,11 +45,14 @@ describe('NoopSpan', () => {
span.updateName('my-span');

assert.ok(!span.isRecording());
assert.deepStrictEqual(span.context(), new SpanContext({
traceId: INVALID_TRACE_ID,
spanId: INVALID_SPAN_ID,
traceFlags: TraceFlags.NONE,
}));
assert.deepStrictEqual(
span.context(),
new SpanContext({
traceId: INVALID_TRACEID,
spanId: INVALID_SPANID,
traceFlags: TraceFlags.NONE,
})
);
span.end();
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -172,12 +172,15 @@ export class B3Propagator implements HttpTextPropagator {
) {
context = context.setValue(PARENT_SPAN_ID_KEY, parentSpanId);
context = context.setValue(DEBUG_FLAG_KEY, debug);
return setExtractedSpanContext(context, new SpanContext({
traceId,
spanId,
isRemote: true,
traceFlags,
}));
return setExtractedSpanContext(
context,
new SpanContext({
traceId,
spanId,
isRemote: true,
traceFlags,
})
);
}
return context;
}
Expand Down
1 change: 0 additions & 1 deletion packages/opentelemetry-core/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ export * from './trace/sampler/AlwaysOffSampler';
export * from './trace/sampler/AlwaysOnSampler';
export * from './trace/sampler/ParentOrElseSampler';
export * from './trace/sampler/ProbabilitySampler';
export * from './trace/spancontext-utils';
export * from './trace/TraceState';
export * from './trace/IdGenerator';
export * from './utils/url';
Expand Down
7 changes: 5 additions & 2 deletions packages/opentelemetry-core/src/trace/NoRecordingSpan.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,11 @@
* limitations under the License.
*/

import { SpanContext, NoopSpan } from '@opentelemetry/api';
import { INVALID_SPAN_CONTEXT } from '../trace/spancontext-utils';
import {
INVALID_SPAN_CONTEXT,
SpanContext,
NoopSpan,
} from '@opentelemetry/api';

/**
* The NoRecordingSpan extends the {@link NoopSpan}, making all operations no-op
Expand Down
36 changes: 0 additions & 36 deletions packages/opentelemetry-core/src/trace/spancontext-utils.ts

This file was deleted.

Loading