Skip to content

Commit

Permalink
fix(basic-tracer): add timestamp for event (#195)
Browse files Browse the repository at this point in the history
* fix(basic-tracer): add timestamp for event

* fix: use performance.now()
  • Loading branch information
mayurkale22 committed Aug 14, 2019
1 parent b498ba2 commit e114423
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 25 deletions.
4 changes: 2 additions & 2 deletions packages/opentelemetry-basic-tracer/src/Span.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export class Span implements types.Span, ReadableSpan {
readonly parentSpanId?: string;
readonly attributes: types.Attributes = {};
readonly links: types.Link[] = [];
readonly events: types.Event[] = [];
readonly events: types.TimedEvent[] = [];
readonly startTime: number;
name: string;
status: types.Status = {
Expand Down Expand Up @@ -82,7 +82,7 @@ export class Span implements types.Span, ReadableSpan {

addEvent(name: string, attributes?: types.Attributes): this {
if (this._isSpanEnded()) return this;
this.events.push({ name, attributes });
this.events.push({ name, attributes, time: performance.now() });
return this;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ import {
Status,
Attributes,
Link,
Event,
SpanContext,
TimedEvent,
} from '@opentelemetry/types';

export interface ReadableSpan {
Expand All @@ -33,5 +33,5 @@ export interface ReadableSpan {
readonly status: Status;
readonly attributes: Attributes;
readonly links: Link[];
readonly events: Event[];
readonly events: TimedEvent[];
}
35 changes: 15 additions & 20 deletions packages/opentelemetry-basic-tracer/test/Span.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -203,30 +203,25 @@ describe('Span', () => {
span.addEvent('sent');
let readableSpan = span.toReadableSpan();
assert.strictEqual(readableSpan.events.length, 1);
assert.deepStrictEqual(readableSpan.events, [
{
attributes: undefined,
name: 'sent',
},
]);
const [event] = readableSpan.events;
assert.deepStrictEqual(event.name, 'sent');
assert.ok(!event.attributes);
assert.ok(event.time > 0);

span.addEvent('rev', { attr1: 'value', attr2: 123, attr3: true });
readableSpan = span.toReadableSpan();
assert.strictEqual(readableSpan.events.length, 2);
assert.deepStrictEqual(readableSpan.events, [
{
attributes: undefined,
name: 'sent',
},
{
attributes: {
attr1: 'value',
attr2: 123,
attr3: true,
},
name: 'rev',
},
]);
const [event1, event2] = readableSpan.events;
assert.deepStrictEqual(event1.name, 'sent');
assert.ok(!event1.attributes);
assert.ok(event1.time > 0);
assert.deepStrictEqual(event2.name, 'rev');
assert.deepStrictEqual(event2.attributes, {
attr1: 'value',
attr2: 123,
attr3: true,
});
assert.ok(event2.time > 0);

span.end();
// shouldn't add new event
Expand Down
2 changes: 1 addition & 1 deletion packages/opentelemetry-types/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export * from './trace/SpanOptions';
export * from './trace/span_context';
export * from './trace/span_kind';
export * from './trace/status';
export * from './trace/TimedEvent';
export * from './trace/tracer';
export * from './trace/trace_options';
export * from './trace/trace_state';
export * from './trace/tracer';

0 comments on commit e114423

Please sign in to comment.