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: apply spec changes for TraceParams #2190

Merged
merged 10 commits into from
May 13, 2021
2 changes: 1 addition & 1 deletion packages/opentelemetry-sdk-node/src/sdk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ export class NodeSDK {
tracerProviderConfig.sampler = configuration.sampler;
}
if (configuration.traceParams) {
tracerProviderConfig.traceParams = configuration.traceParams;
tracerProviderConfig.spanLimits = configuration.traceParams;
weyert marked this conversation as resolved.
Show resolved Hide resolved
}

const spanProcessor =
Expand Down
4 changes: 2 additions & 2 deletions packages/opentelemetry-sdk-node/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import { Resource } from '@opentelemetry/resources';
import {
SpanExporter,
SpanProcessor,
TraceParams,
SpanLimits,
} from '@opentelemetry/tracing';

export interface NodeSDKConfiguration {
Expand All @@ -38,5 +38,5 @@ export interface NodeSDKConfiguration {
sampler: Sampler;
spanProcessor: SpanProcessor;
traceExporter: SpanExporter;
traceParams: TraceParams;
traceParams: SpanLimits;
weyert marked this conversation as resolved.
Show resolved Hide resolved
}
10 changes: 5 additions & 5 deletions packages/opentelemetry-tracing/src/Span.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import { SemanticAttributes } from '@opentelemetry/semantic-conventions';
import { ReadableSpan } from './export/ReadableSpan';
import { Tracer } from './Tracer';
import { SpanProcessor } from './SpanProcessor';
import { TraceParams } from './types';
import { SpanLimits } from './types';
import { SpanAttributeValue, Context } from '@opentelemetry/api';
import { ExceptionEventName } from './enums';

Expand All @@ -55,7 +55,7 @@ export class Span implements api.Span, ReadableSpan {
private _ended = false;
private _duration: api.HrTime = [-1, -1];
private readonly _spanProcessor: SpanProcessor;
private readonly _traceParams: TraceParams;
private readonly _spanLimits: SpanLimits;

/** Constructs a new Span instance. */
constructor(
Expand All @@ -76,7 +76,7 @@ export class Span implements api.Span, ReadableSpan {
this.startTime = timeInputToHrTime(startTime);
this.resource = parentTracer.resource;
this.instrumentationLibrary = parentTracer.instrumentationLibrary;
this._traceParams = parentTracer.getActiveTraceParams();
this._spanLimits = parentTracer.getSpanLimits();
this._spanProcessor = parentTracer.getActiveSpanProcessor();
this._spanProcessor.onStart(this, context);
}
Expand All @@ -99,7 +99,7 @@ export class Span implements api.Span, ReadableSpan {

if (
Object.keys(this.attributes).length >=
this._traceParams.numberOfAttributesPerSpan! &&
this._spanLimits.attributeCountLimit! &&
!Object.prototype.hasOwnProperty.call(this.attributes, key)
) {
return this;
Expand Down Expand Up @@ -128,7 +128,7 @@ export class Span implements api.Span, ReadableSpan {
startTime?: api.TimeInput
): this {
if (this._isSpanEnded()) return this;
if (this.events.length >= this._traceParams.numberOfEventsPerSpan!) {
if (this.events.length >= this._spanLimits.eventCountLimit!) {
api.diag.warn('Dropping extra events.');
this.events.shift();
}
Expand Down
12 changes: 6 additions & 6 deletions packages/opentelemetry-tracing/src/Tracer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,15 @@ import {
import { Resource } from '@opentelemetry/resources';
import { BasicTracerProvider } from './BasicTracerProvider';
import { Span } from './Span';
import { TraceParams, TracerConfig } from './types';
import { SpanLimits, TracerConfig } from './types';
import { mergeConfig } from './utility';

/**
* This class represents a basic tracer.
*/
export class Tracer implements api.Tracer {
private readonly _sampler: api.Sampler;
private readonly _traceParams: TraceParams;
private readonly _spanLimits: SpanLimits;
private readonly _idGenerator: IdGenerator;
readonly resource: Resource;
readonly instrumentationLibrary: InstrumentationLibrary;
Expand All @@ -47,7 +47,7 @@ export class Tracer implements api.Tracer {
) {
const localConfig = mergeConfig(config);
this._sampler = localConfig.sampler;
this._traceParams = localConfig.traceParams;
this._spanLimits = localConfig.spanLimits;
this._idGenerator = config.idGenerator || new RandomIdGenerator();
this.resource = _tracerProvider.resource;
this.instrumentationLibrary = instrumentationLibrary;
Expand Down Expand Up @@ -124,9 +124,9 @@ export class Tracer implements api.Tracer {
return span;
}

/** Returns the active {@link TraceParams}. */
getActiveTraceParams(): TraceParams {
return this._traceParams;
/** Returns the active {@link SpanLimits}. */
getSpanLimits(): SpanLimits {
return this._spanLimits;
}

getActiveSpanProcessor() {
Expand Down
8 changes: 4 additions & 4 deletions packages/opentelemetry-tracing/src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,10 @@ const FALLBACK_OTEL_TRACES_SAMPLER = TracesSamplerValues.AlwaysOn;
*/
export const DEFAULT_CONFIG = {
sampler: buildSamplerFromEnv(env),
traceParams: {
numberOfAttributesPerSpan: getEnv().OTEL_SPAN_ATTRIBUTE_COUNT_LIMIT,
numberOfLinksPerSpan: getEnv().OTEL_SPAN_LINK_COUNT_LIMIT,
numberOfEventsPerSpan: getEnv().OTEL_SPAN_EVENT_COUNT_LIMIT,
spanLimits: {
attributeCountLimit: getEnv().OTEL_SPAN_ATTRIBUTE_COUNT_LIMIT,
linkCountLimit: getEnv().OTEL_SPAN_LINK_COUNT_LIMIT,
eventCountLimit: getEnv().OTEL_SPAN_EVENT_COUNT_LIMIT,
},
};

Expand Down
18 changes: 9 additions & 9 deletions packages/opentelemetry-tracing/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ export interface TracerConfig {
*/
sampler?: Sampler;

/** Trace Parameters */
traceParams?: TraceParams;
/** Span Limits */
spanLimits?: SpanLimits;

/** Resource associated with trace telemetry */
resource?: Resource;
Expand All @@ -56,13 +56,13 @@ export interface SDKRegistrationConfig {
}

/** Global configuration of trace service */
export interface TraceParams {
/** numberOfAttributesPerSpan is number of attributes per span */
numberOfAttributesPerSpan?: number;
/** numberOfLinksPerSpan is number of links per span */
numberOfLinksPerSpan?: number;
/** numberOfEventsPerSpan is number of message events per span */
numberOfEventsPerSpan?: number;
export interface SpanLimits {
/** attributeCountLimit is number of attributes per span */
attributeCountLimit?: number;
/** linkCountLimit is number of links per span */
linkCountLimit?: number;
/** eventCountLimit is number of message events per span */
eventCountLimit?: number;
}

/** Interface configuration for a buffer. */
Expand Down
6 changes: 3 additions & 3 deletions packages/opentelemetry-tracing/src/utility.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,10 @@ export function mergeConfig(userConfig: TracerConfig) {
userConfig
);

target.traceParams = Object.assign(
target.spanLimits = Object.assign(
{},
DEFAULT_CONFIG.traceParams,
userConfig.traceParams || {}
DEFAULT_CONFIG.spanLimits,
userConfig.spanLimits || {}
);

return target;
Expand Down
52 changes: 26 additions & 26 deletions packages/opentelemetry-tracing/test/BasicTracerProvider.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,51 +68,51 @@ describe('BasicTracerProvider', () => {
assert.ok(provider instanceof BasicTracerProvider);
});

it('should construct an instance with default trace params', () => {
it('should construct an instance with default span limits', () => {
const tracer = new BasicTracerProvider({}).getTracer('default');
assert.deepStrictEqual(tracer.getActiveTraceParams(), {
numberOfAttributesPerSpan: 128,
numberOfEventsPerSpan: 128,
numberOfLinksPerSpan: 128,
assert.deepStrictEqual(tracer.getSpanLimits(), {
attributeCountLimit: 128,
eventCountLimit: 128,
linkCountLimit: 128,
});
});

it('should construct an instance with customized numberOfAttributesPerSpan trace params', () => {
it('should construct an instance with customized attributeCountLimit span limits', () => {
const tracer = new BasicTracerProvider({
traceParams: {
numberOfAttributesPerSpan: 100,
spanLimits: {
attributeCountLimit: 100,
},
}).getTracer('default');
assert.deepStrictEqual(tracer.getActiveTraceParams(), {
numberOfAttributesPerSpan: 100,
numberOfEventsPerSpan: 128,
numberOfLinksPerSpan: 128,
assert.deepStrictEqual(tracer.getSpanLimits(), {
attributeCountLimit: 100,
eventCountLimit: 128,
linkCountLimit: 128,
});
});

it('should construct an instance with customized numberOfEventsPerSpan trace params', () => {
it('should construct an instance with customized eventCountLimit span limits', () => {
const tracer = new BasicTracerProvider({
traceParams: {
numberOfEventsPerSpan: 300,
spanLimits: {
eventCountLimit: 300,
},
}).getTracer('default');
assert.deepStrictEqual(tracer.getActiveTraceParams(), {
numberOfAttributesPerSpan: 128,
numberOfEventsPerSpan: 300,
numberOfLinksPerSpan: 128,
assert.deepStrictEqual(tracer.getSpanLimits(), {
attributeCountLimit: 128,
eventCountLimit: 300,
linkCountLimit: 128,
});
});

it('should construct an instance with customized numberOfLinksPerSpan trace params', () => {
it('should construct an instance with customized linkCountLimit span limits', () => {
const tracer = new BasicTracerProvider({
traceParams: {
numberOfLinksPerSpan: 10,
spanLimits: {
linkCountLimit: 10,
},
}).getTracer('default');
assert.deepStrictEqual(tracer.getActiveTraceParams(), {
numberOfAttributesPerSpan: 128,
numberOfEventsPerSpan: 128,
numberOfLinksPerSpan: 10,
assert.deepStrictEqual(tracer.getSpanLimits(), {
attributeCountLimit: 128,
eventCountLimit: 128,
linkCountLimit: 10,
});
});

Expand Down
6 changes: 3 additions & 3 deletions packages/opentelemetry-tracing/test/Span.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@ const performanceTimeOrigin = hrTime();

describe('Span', () => {
const tracer = new BasicTracerProvider({
traceParams: {
numberOfAttributesPerSpan: 100,
numberOfEventsPerSpan: 100,
spanLimits: {
attributeCountLimit: 100,
eventCountLimit: 100,
},
}).getTracer('default');
const name = 'span1';
Expand Down