Skip to content

Commit

Permalink
feat(sdk-trace-base): improve log messages when dropping span events (o…
Browse files Browse the repository at this point in the history
  • Loading branch information
mkubliniak authored and rdeavila94 committed Jan 3, 2024
1 parent 22cea00 commit fb6d8dc
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 1 deletion.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ For experimental package changes, see the [experimental CHANGELOG](experimental/

### :rocket: (Enhancement)

* feat(sdk-trace-base): improve log messages when dropping span events [#4223](https://github.com/open-telemetry/opentelemetry-js/pull/4223) @mkubliniak

### :bug: (Bug Fix)

### :books: (Refine Doc)
Expand Down
10 changes: 9 additions & 1 deletion packages/opentelemetry-sdk-trace-base/src/Span.ts
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,9 @@ export class Span implements APISpan, ReadableSpan {
return this;
}
if (this.events.length >= this._spanLimits.eventCountLimit!) {
diag.warn('Dropping extra events.');
if (this._droppedEventsCount === 0) {
diag.debug('Dropping extra events.');
}
this.events.shift();
this._droppedEventsCount++;
}
Expand Down Expand Up @@ -242,6 +244,12 @@ export class Span implements APISpan, ReadableSpan {
this._duration = [0, 0];
}

if (this._droppedEventsCount > 0) {
diag.warn(
`Dropped ${this._droppedEventsCount} events because eventCountLimit reached`
);
}

this._spanProcessor.onEnd(this);
}

Expand Down
11 changes: 11 additions & 0 deletions packages/opentelemetry-sdk-trace-base/test/common/Span.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
*/

import {
diag,
SpanStatusCode,
Exception,
ROOT_CONTEXT,
Expand Down Expand Up @@ -786,13 +787,23 @@ describe('Span', () => {
spanContext,
SpanKind.CLIENT
);

const debugStub = sinon.spy(diag, 'debug');
const warnStub = sinon.spy(diag, 'warn');

for (let i = 0; i < 150; i++) {
span.addEvent('sent' + i);
}
span.end();

assert.strictEqual(span.events.length, 100);
assert.strictEqual(span.events[span.events.length - 1].name, 'sent149');

sinon.assert.calledOnceWithExactly(debugStub, 'Dropping extra events.');
sinon.assert.calledOnceWithExactly(
warnStub,
'Dropped 50 events because eventCountLimit reached'
);
});

it('should store the count of dropped events in droppedEventsCount', () => {
Expand Down

0 comments on commit fb6d8dc

Please sign in to comment.