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

fix: add parentContext to onStart #2757

Merged
merged 4 commits into from
Feb 6, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* limitations under the License.
*/

import { context, TraceFlags } from '@opentelemetry/api';
import { context, Context, TraceFlags } from '@opentelemetry/api';
import {
BindOnceFuture,
ExportResultCode,
Expand Down Expand Up @@ -73,7 +73,7 @@ export abstract class BatchSpanProcessorBase<T extends BufferConfig> implements
}

// does nothing.
onStart(_span: Span): void {}
onStart(_span: Span, _parentContext: Context): void {}

onEnd(span: ReadableSpan): void {
if (this._shutdownOnce.isCalled) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* limitations under the License.
*/

import { context, TraceFlags } from '@opentelemetry/api';
import { context, Context, TraceFlags } from '@opentelemetry/api';
import {
ExportResultCode,
globalErrorHandler,
Expand Down Expand Up @@ -45,7 +45,7 @@ export class SimpleSpanProcessor implements SpanProcessor {
}

// does nothing.
onStart(_span: Span): void {}
onStart(_span: Span, _parentContext: Context): void {}

onEnd(span: ReadableSpan): void {
if (this._shutdownOnce.isCalled) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* limitations under the License.
*/

import { diag } from '@opentelemetry/api';
import { diag, ROOT_CONTEXT } from '@opentelemetry/api';
import {
AlwaysOnSampler,
ExportResultCode,
Expand Down Expand Up @@ -131,14 +131,14 @@ describe('BatchSpanProcessorBase', () => {

const span = createSampledSpan(`${name}_0`);

processor.onStart(span);
processor.onStart(span, ROOT_CONTEXT);
processor.onEnd(span);
assert.strictEqual(processor['_finishedSpans'].length, 1);

await processor.forceFlush();
assert.strictEqual(exporter.getFinishedSpans().length, 1);

processor.onStart(span);
processor.onStart(span, ROOT_CONTEXT);
processor.onEnd(span);
assert.strictEqual(processor['_finishedSpans'].length, 1);

Expand All @@ -147,7 +147,7 @@ describe('BatchSpanProcessorBase', () => {
assert.strictEqual(spy.args.length, 2);
assert.strictEqual(exporter.getFinishedSpans().length, 0);

processor.onStart(span);
processor.onStart(span, ROOT_CONTEXT);
processor.onEnd(span);
assert.strictEqual(spy.args.length, 2);
assert.strictEqual(processor['_finishedSpans'].length, 0);
Expand All @@ -160,7 +160,7 @@ describe('BatchSpanProcessorBase', () => {

const span = createUnsampledSpan(`${name}_0`);

processor.onStart(span);
processor.onStart(span, ROOT_CONTEXT);
processor.onEnd(span);

await processor.forceFlush();
Expand All @@ -174,14 +174,14 @@ describe('BatchSpanProcessorBase', () => {
const processor = new BatchSpanProcessor(exporter, defaultBufferConfig);
for (let i = 0; i < defaultBufferConfig.maxExportBatchSize; i++) {
const span = createSampledSpan(`${name}_${i}`);
processor.onStart(span);
processor.onStart(span, ROOT_CONTEXT);
assert.strictEqual(exporter.getFinishedSpans().length, 0);

processor.onEnd(span);
assert.strictEqual(exporter.getFinishedSpans().length, 0);
}
const span = createSampledSpan(`${name}_6`);
processor.onStart(span);
processor.onStart(span, ROOT_CONTEXT);
processor.onEnd(span);

setTimeout(async () => {
Expand All @@ -199,7 +199,7 @@ describe('BatchSpanProcessorBase', () => {
const processor = new BatchSpanProcessor(exporter, defaultBufferConfig);
for (let i = 0; i < defaultBufferConfig.maxExportBatchSize; i++) {
const span = createSampledSpan(`${name}_${i}`);
processor.onStart(span);
processor.onStart(span, ROOT_CONTEXT);
processor.onEnd(span);
assert.strictEqual(exporter.getFinishedSpans().length, 0);
}
Expand All @@ -218,7 +218,7 @@ describe('BatchSpanProcessorBase', () => {
const processor = new BatchSpanProcessor(exporter, defaultBufferConfig);
for (let i = 0; i < defaultBufferConfig.maxExportBatchSize; i++) {
const span = createSampledSpan(`${name}_${i}`);
processor.onStart(span);
processor.onStart(span, ROOT_CONTEXT);
processor.onEnd(span);
}
assert.strictEqual(exporter.getFinishedSpans().length, 0);
Expand All @@ -238,7 +238,7 @@ describe('BatchSpanProcessorBase', () => {
// start but do not end spans
for (let i = 0; i < defaultBufferConfig.maxExportBatchSize; i++) {
const span = tracer.startSpan('spanName');
processor.onStart(span as Span);
processor.onStart(span as Span, ROOT_CONTEXT);
}

setTimeout(() => {
Expand Down Expand Up @@ -266,11 +266,11 @@ describe('BatchSpanProcessorBase', () => {
const totalSpans = defaultBufferConfig.maxExportBatchSize * 2;
for (let i = 0; i < totalSpans; i++) {
const span = createSampledSpan(`${name}_${i}`);
processor.onStart(span);
processor.onStart(span, ROOT_CONTEXT);
processor.onEnd(span);
}
const span = createSampledSpan(`${name}_last`);
processor.onStart(span);
processor.onStart(span, ROOT_CONTEXT);
processor.onEnd(span);
clock.tick(defaultBufferConfig.scheduledDelayMillis + 10);

Expand Down Expand Up @@ -326,7 +326,7 @@ describe('BatchSpanProcessorBase', () => {

it('should call an async callback when flushing is complete', done => {
const span = createSampledSpan('test');
processor.onStart(span);
processor.onStart(span, ROOT_CONTEXT);
processor.onEnd(span);
processor.forceFlush().then(() => {
assert.strictEqual(exporter.getFinishedSpans().length, 1);
Expand All @@ -343,7 +343,7 @@ describe('BatchSpanProcessorBase', () => {
}, 0);
});
const span = createSampledSpan('test');
processor.onStart(span);
processor.onStart(span, ROOT_CONTEXT);
processor.onEnd(span);

processor.shutdown().then(() => {
Expand All @@ -367,7 +367,7 @@ describe('BatchSpanProcessorBase', () => {

for (let i = 0; i < defaultBufferConfig.maxExportBatchSize; i++) {
const span = createSampledSpan('test');
processor.onStart(span);
processor.onStart(span, ROOT_CONTEXT);
processor.onEnd(span);
}

Expand Down Expand Up @@ -402,7 +402,7 @@ describe('BatchSpanProcessorBase', () => {
const processor = new BatchSpanProcessor(testTracingExporter);

const span = createSampledSpan('test');
processor.onStart(span);
processor.onStart(span, ROOT_CONTEXT);
processor.onEnd(span);

processor.forceFlush().then(() => {
Expand All @@ -429,7 +429,7 @@ describe('BatchSpanProcessorBase', () => {
it('should drop spans', () => {
const span = createSampledSpan('test');
for (let i = 0, j = 20; i < j; i++) {
processor.onStart(span);
processor.onStart(span, ROOT_CONTEXT);
processor.onEnd(span);
}
assert.equal(processor['_finishedSpans'].length, 6);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ describe('SimpleSpanProcessor', () => {
spanContext,
SpanKind.CLIENT
);
processor.onStart(span);
processor.onStart(span, ROOT_CONTEXT);
assert.strictEqual(exporter.getFinishedSpans().length, 0);

processor.onEnd(span);
Expand All @@ -92,7 +92,7 @@ describe('SimpleSpanProcessor', () => {
spanContext,
SpanKind.CLIENT
);
processor.onStart(span);
processor.onStart(span, ROOT_CONTEXT);
assert.strictEqual(exporter.getFinishedSpans().length, 0);

processor.onEnd(span);
Expand All @@ -117,7 +117,7 @@ describe('SimpleSpanProcessor', () => {
spanContext,
SpanKind.CLIENT
);
processor.onStart(span);
processor.onStart(span, ROOT_CONTEXT);

sinon.stub(exporter, 'export').callsFake((_, callback) => {
setTimeout(() => {
Expand Down Expand Up @@ -195,7 +195,7 @@ describe('SimpleSpanProcessor', () => {
SpanKind.CLIENT
);

processor.onStart(span);
processor.onStart(span, ROOT_CONTEXT);
processor.onEnd(span);

const exporterCreatedSpans = testTracingExporter.getExporterCreatedSpans();
Expand Down