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

Commit 77036f4

Browse files
tcolgatekjin
authored andcommitted
feat: messageEvent should include timestamp (#81)
BREAKING CHANGE: span.addAnnotation now accepts timestamp as its last argument instead of as its second argument.
1 parent b99ff15 commit 77036f4

4 files changed

Lines changed: 17 additions & 12 deletions

File tree

packages/opencensus-core/src/trace/model/span-base.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -136,15 +136,15 @@ export abstract class SpanBase implements types.Span {
136136
/**
137137
* Adds an annotation to the span.
138138
* @param description Describes the event.
139-
* @param timestamp A timestamp that maks the event.
140139
* @param attributes A set of attributes on the annotation.
140+
* @param timestamp A time, in milliseconds. Defaults to Date.now()
141141
*/
142142
addAnnotation(
143-
description: string, timestamp: number, attributes?: types.Attributes) {
143+
description: string, attributes?: types.Attributes, timestamp = 0) {
144144
this.annotations.push({
145145
'description': description,
146-
'timestamp': timestamp,
147146
'attributes': attributes,
147+
'timestamp': timestamp ? timestamp : Date.now(),
148148
} as types.Annotation);
149149
}
150150

@@ -170,11 +170,13 @@ export abstract class SpanBase implements types.Span {
170170
* Adds a message event to the span.
171171
* @param type The type of message event.
172172
* @param id An identifier for the message event.
173+
* @param timestamp A time in milliseconds. Defaults to Date.now()
173174
*/
174-
addMessageEvent(type: string, id: string) {
175+
addMessageEvent(type: string, id: string, timestamp = 0) {
175176
this.messageEvents.push({
176177
'type': type,
177178
'id': id,
179+
'timestamp': timestamp ? timestamp : Date.now(),
178180
} as types.MessageEvent);
179181
}
180182

@@ -217,4 +219,4 @@ export abstract class SpanBase implements types.Span {
217219
this.logger.debug(
218220
'truncating %s %o', this.className, {id: this.id, name: this.name});
219221
}
220-
}
222+
}

packages/opencensus-core/src/trace/model/types.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,14 +32,16 @@ export interface Attributes { [attributeKey: string]: string|number|boolean; }
3232
export interface Annotation {
3333
/** A user-supplied message describing the event. */
3434
description: string;
35-
/** A timestamp that maks the event. */
35+
/** A timestamp for the event event. */
3636
timestamp: number;
3737
/** A set of attributes on the annotation. */
3838
attributes: Attributes;
3939
}
4040

4141
/** An event describing a message sent/received between Spans. */
4242
export interface MessageEvent {
43+
/** A timestamp for the event. */
44+
timestamp: number;
4345
/** Indicates whether the message was sent or received. */
4446
type: string;
4547
/** An identifier for the MessageEvent's message. */
@@ -166,11 +168,11 @@ export interface Span {
166168
/**
167169
* Adds an annotation to the span.
168170
* @param description Describes the event.
169-
* @param timestamp A timestamp that maks the event.
170171
* @param attributes A set of attributes on the annotation.
172+
* @param timestamp A timestamp for this event.
171173
*/
172174
addAnnotation(
173-
description: string, timestamp: number, attributes?: Attributes): void;
175+
description: string, attributes?: Attributes, timestamp?: number): void;
174176

175177
/**
176178
* Adds a link to the span.
@@ -187,8 +189,9 @@ export interface Span {
187189
* Adds a message event to the span.
188190
* @param type The type of message event.
189191
* @param id An identifier for the message event.
192+
* @param timestamp A timestamp for this event.
190193
*/
191-
addMessageEvent(type: string, id: string): void;
194+
addMessageEvent(type: string, id: string, timestamp?: number): void;
192195

193196
/** Starts a span. */
194197
start(): void;

packages/opencensus-core/test/test-root-span.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ describe('RootSpan', () => {
205205
const rootSpan = new RootSpan(tracer);
206206
rootSpan.start();
207207

208-
rootSpan.addAnnotation('description test', Date.now(), {} as Attributes);
208+
rootSpan.addAnnotation('description test', {} as Attributes, Date.now());
209209

210210
assert.ok(rootSpan.annotations.length > 0);
211211
assert.ok(instanceOfAnnotation(rootSpan.annotations[0]));

packages/opencensus-core/test/test-span.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ describe('Span', () => {
207207
const span = new Span(rootSpan);
208208
span.start();
209209

210-
span.addAnnotation('description test', Date.now(), {} as Attributes);
210+
span.addAnnotation('description test', {} as Attributes, Date.now());
211211

212212
assert.ok(span.annotations.length > 0);
213213
assert.ok(instanceOfAnnotation(span.annotations[0]));
@@ -260,4 +260,4 @@ describe('Span', () => {
260260
assert.ok(instanceOfLink(span.messageEvents[0]));
261261
});
262262
});
263-
});
263+
});

0 commit comments

Comments
 (0)