Skip to content
This repository has been archived by the owner on Oct 3, 2023. It is now read-only.

Commit

Permalink
fix: allow override global trace params limits (#643)
Browse files Browse the repository at this point in the history
  • Loading branch information
mayurkale22 authored Aug 27, 2019
1 parent 2ae76c3 commit 0d9427b
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 37 deletions.
43 changes: 12 additions & 31 deletions packages/opencensus-core/src/trace/sampler/sampler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,45 +118,26 @@ export class TraceParamsBuilder {
static getNumberOfAnnotationEventsPerSpan(
traceParameters: TraceParams
): number {
if (
!traceParameters.numberOfAnnontationEventsPerSpan ||
traceParameters.numberOfAnnontationEventsPerSpan >
DEFAULT_SPAN_MAX_NUM_ANNOTATIONS
) {
return DEFAULT_SPAN_MAX_NUM_ANNOTATIONS;
}
return traceParameters.numberOfAnnontationEventsPerSpan;
return !traceParameters.numberOfAnnontationEventsPerSpan
? DEFAULT_SPAN_MAX_NUM_ANNOTATIONS
: traceParameters.numberOfAnnontationEventsPerSpan;
}

static getNumberOfAttributesPerSpan(traceParameters: TraceParams): number {
if (
!traceParameters.numberOfAttributesPerSpan ||
traceParameters.numberOfAttributesPerSpan >
DEFAULT_SPAN_MAX_NUM_ATTRIBUTES
) {
return DEFAULT_SPAN_MAX_NUM_ATTRIBUTES;
}
return traceParameters.numberOfAttributesPerSpan;
return !traceParameters.numberOfAttributesPerSpan
? DEFAULT_SPAN_MAX_NUM_ATTRIBUTES
: traceParameters.numberOfAttributesPerSpan;
}

static getNumberOfMessageEventsPerSpan(traceParameters: TraceParams): number {
if (
!traceParameters.numberOfMessageEventsPerSpan ||
traceParameters.numberOfMessageEventsPerSpan >
DEFAULT_SPAN_MAX_NUM_MESSAGE_EVENTS
) {
return DEFAULT_SPAN_MAX_NUM_MESSAGE_EVENTS;
}
return traceParameters.numberOfMessageEventsPerSpan;
return !traceParameters.numberOfMessageEventsPerSpan
? DEFAULT_SPAN_MAX_NUM_MESSAGE_EVENTS
: traceParameters.numberOfMessageEventsPerSpan;
}

static getNumberOfLinksPerSpan(traceParameters: TraceParams): number {
if (
!traceParameters.numberOfLinksPerSpan ||
traceParameters.numberOfLinksPerSpan > DEFAULT_SPAN_MAX_NUM_LINKS
) {
return DEFAULT_SPAN_MAX_NUM_LINKS;
}
return traceParameters.numberOfLinksPerSpan;
return !traceParameters.numberOfLinksPerSpan
? DEFAULT_SPAN_MAX_NUM_LINKS
: traceParameters.numberOfLinksPerSpan;
}
}
27 changes: 21 additions & 6 deletions packages/opencensus-core/test/test-tracer-base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ describe('Tracer Base', () => {
);
});

it('should create a tracer with default TraceParams when parameters with values higher than maximum limit are specified upon initialisation', () => {
it('should create a tracer with default TraceParams when parameters with values higher than limit are specified upon initialisation', () => {
const traceParametersWithHigherThanMaximumValues: TraceParams = {
numberOfAnnontationEventsPerSpan: 50,
numberOfMessageEventsPerSpan: 200,
Expand All @@ -271,16 +271,16 @@ describe('Tracer Base', () => {
tracer.start(defaultConfig);
assert.strictEqual(
tracer.activeTraceParams.numberOfAnnontationEventsPerSpan,
32
50
);
assert.strictEqual(
tracer.activeTraceParams.numberOfAttributesPerSpan,
32
37
);
assert.strictEqual(tracer.activeTraceParams.numberOfLinksPerSpan, 32);
assert.strictEqual(tracer.activeTraceParams.numberOfLinksPerSpan, 45);
assert.strictEqual(
tracer.activeTraceParams.numberOfMessageEventsPerSpan,
128
200
);
});
});
Expand Down Expand Up @@ -382,6 +382,21 @@ describe('Tracer Base', () => {
assert.strictEqual(rootSpan.allDescendants().length, 3);
});
});

it('should add attributes more than default limit when override', () => {
defaultConfig.traceParams = { numberOfAttributesPerSpan: 48 };
tracer.start(defaultConfig);
tracer.startRootSpan(options, rootSpan => {
const span = tracer.startChildSpan({
name: 'spanName',
childOf: rootSpan,
});
for (let i = 0; i < 40; i++) {
span.addAttribute(`attr ${i}`, i);
}
assert.strictEqual(Object.keys(span.attributes).length, 40);
});
});
});

/** Should not create a Span instance */
Expand Down Expand Up @@ -422,7 +437,7 @@ describe('Tracer Base', () => {
});
});
});
it('should add add attributes to spans', () => {
it('should add attributes to spans', () => {
assert.deepStrictEqual(
rootSpanLocal.attributes,
tracerConfig.defaultAttributes
Expand Down

0 comments on commit 0d9427b

Please sign in to comment.