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

feat: span processor onstart recieves context #1632

Merged
merged 2 commits into from
Oct 30, 2020
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,24 +14,24 @@
* limitations under the License.
*/

import * as assert from 'assert';
import * as api from '@opentelemetry/api';
import { Span, BasicTracerProvider } from '@opentelemetry/tracing';
import {
NoopLogger,
hrTimeToMicroseconds,
hrTimeDuration,
hrTimeToMicroseconds,
NoopLogger,
VERSION,
} from '@opentelemetry/core';
import { Resource, TELEMETRY_SDK_RESOURCE } from '@opentelemetry/resources';
import { BasicTracerProvider, Span } from '@opentelemetry/tracing';
import * as assert from 'assert';
import {
toZipkinSpan,
_toZipkinTags,
_toZipkinAnnotations,
statusCodeTagName,
statusDescriptionTagName,
toZipkinSpan,
_toZipkinAnnotations,
_toZipkinTags,
} from '../../src/transform';
import * as zipkinTypes from '../../src/types';
import { Resource, TELEMETRY_SDK_RESOURCE } from '@opentelemetry/resources';
const logger = new NoopLogger();
const tracer = new BasicTracerProvider({
logger,
Expand All @@ -57,6 +57,7 @@ describe('transform', () => {
it('should convert an OpenTelemetry span to a Zipkin span', () => {
const span = new Span(
tracer,
api.ROOT_CONTEXT,
'my-span',
spanContext,
api.SpanKind.SERVER,
Expand Down Expand Up @@ -107,6 +108,7 @@ describe('transform', () => {
it("should skip parentSpanId if doesn't exist", () => {
const span = new Span(
tracer,
api.ROOT_CONTEXT,
'my-span',
spanContext,
api.SpanKind.SERVER
Expand Down Expand Up @@ -152,7 +154,13 @@ describe('transform', () => {
it(`should map OpenTelemetry SpanKind ${
api.SpanKind[item.ot]
} to Zipkin ${item.zipkin}`, () => {
const span = new Span(tracer, 'my-span', spanContext, item.ot);
const span = new Span(
tracer,
api.ROOT_CONTEXT,
'my-span',
spanContext,
item.ot
);
span.end();

const zipkinSpan = toZipkinSpan(
Expand Down Expand Up @@ -190,6 +198,7 @@ describe('transform', () => {
it('should convert OpenTelemetry attributes to Zipkin tags', () => {
const span = new Span(
tracer,
api.ROOT_CONTEXT,
'my-span',
spanContext,
api.SpanKind.SERVER,
Expand Down Expand Up @@ -219,6 +228,7 @@ describe('transform', () => {
it('should map OpenTelemetry Status.code to a Zipkin tag', () => {
const span = new Span(
tracer,
api.ROOT_CONTEXT,
'my-span',
spanContext,
api.SpanKind.SERVER,
Expand Down Expand Up @@ -249,6 +259,7 @@ describe('transform', () => {
it('should map OpenTelemetry Status.message to a Zipkin tag', () => {
const span = new Span(
tracer,
api.ROOT_CONTEXT,
'my-span',
spanContext,
api.SpanKind.SERVER,
Expand Down Expand Up @@ -284,6 +295,7 @@ describe('transform', () => {
it('should convert OpenTelemetry events to Zipkin annotations', () => {
const span = new Span(
tracer,
api.ROOT_CONTEXT,
'my-span',
spanContext,
api.SpanKind.SERVER,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,12 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { CanonicalCode, SpanKind, TraceFlags } from '@opentelemetry/api';
import {
CanonicalCode,
ROOT_CONTEXT,
SpanKind,
TraceFlags,
} from '@opentelemetry/api';
import { NoopLogger } from '@opentelemetry/core';
import { BasicTracerProvider, Span } from '@opentelemetry/tracing';
import { HttpAttribute } from '@opentelemetry/semantic-conventions';
Expand Down Expand Up @@ -256,6 +261,7 @@ describe('Utility', () => {
for (const obj of [undefined, { statusCode: 400 }]) {
const span = new Span(
new BasicTracerProvider().getTracer('default'),
ROOT_CONTEXT,
'test',
{ spanId: '', traceId: '', traceFlags: TraceFlags.SAMPLED },
SpanKind.INTERNAL
Expand Down
2 changes: 1 addition & 1 deletion packages/opentelemetry-tracing/src/BasicTracerProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export class BasicTracerProvider implements api.TracerProvider {
private readonly _registeredSpanProcessors: SpanProcessor[] = [];
private readonly _tracers: Map<string, Tracer> = new Map();

activeSpanProcessor = new NoopSpanProcessor();
activeSpanProcessor: SpanProcessor = new NoopSpanProcessor();
readonly logger: api.Logger;
readonly resource: Resource;

Expand Down
5 changes: 3 additions & 2 deletions packages/opentelemetry-tracing/src/MultiSpanProcessor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
* limitations under the License.
*/

import { Context } from '@opentelemetry/api';
import { globalErrorHandler } from '@opentelemetry/core';
import { ReadableSpan } from './export/ReadableSpan';
import { Span } from './Span';
Expand Down Expand Up @@ -46,9 +47,9 @@ export class MultiSpanProcessor implements SpanProcessor {
});
}

onStart(span: Span): void {
onStart(span: Span, context: Context): void {
for (const spanProcessor of this._spanProcessors) {
spanProcessor.onStart(span);
spanProcessor.onStart(span, context);
}
}

Expand Down
3 changes: 2 additions & 1 deletion packages/opentelemetry-tracing/src/NoopSpanProcessor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,14 @@
* limitations under the License.
*/

import { Context } from '@opentelemetry/api';
import { ReadableSpan } from './export/ReadableSpan';
import { Span } from './Span';
import { SpanProcessor } from './SpanProcessor';

/** No-op implementation of SpanProcessor */
export class NoopSpanProcessor implements SpanProcessor {
onStart(span: Span): void {}
onStart(span: Span, context: Context): void {}
onEnd(span: ReadableSpan): void {}
shutdown(): Promise<void> {
return Promise.resolve();
Expand Down
5 changes: 3 additions & 2 deletions packages/opentelemetry-tracing/src/Span.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ import { ReadableSpan } from './export/ReadableSpan';
import { Tracer } from './Tracer';
import { SpanProcessor } from './SpanProcessor';
import { TraceParams } from './types';
import { AttributeValue } from '@opentelemetry/api';
import { AttributeValue, Context } from '@opentelemetry/api';

/**
* This class represents a span.
Expand Down Expand Up @@ -63,6 +63,7 @@ export class Span implements api.Span, ReadableSpan {
/** Constructs a new Span instance. */
constructor(
parentTracer: Tracer,
context: Context,
spanName: string,
spanContext: api.SpanContext,
kind: api.SpanKind,
Expand All @@ -81,7 +82,7 @@ export class Span implements api.Span, ReadableSpan {
this._logger = parentTracer.logger;
this._traceParams = parentTracer.getActiveTraceParams();
this._spanProcessor = parentTracer.getActiveSpanProcessor();
this._spanProcessor.onStart(this);
this._spanProcessor.onStart(this, context);
}

context(): api.SpanContext {
Expand Down
3 changes: 2 additions & 1 deletion packages/opentelemetry-tracing/src/SpanProcessor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
* limitations under the License.
*/

import { Context } from '@opentelemetry/api';
import { ReadableSpan } from './export/ReadableSpan';
import { Span } from './Span';

Expand All @@ -32,7 +33,7 @@ export interface SpanProcessor {
* returns true.
* @param span the Span that just started.
*/
onStart(span: Span): void;
onStart(span: Span, parentContext: Context): void;

/**
* Called when a {@link ReadableSpan} is ended, if the `span.isRecording()`
Expand Down
1 change: 1 addition & 0 deletions packages/opentelemetry-tracing/src/Tracer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ export class Tracer implements api.Tracer {

const span = new Span(
this,
context,
name,
spanContext,
spanKind,
Expand Down
Loading