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

Commit a687f7f

Browse files
draffenspergermayurkale22
authored andcommitted
Add message sizes to addMessageEvent function (#344)
* Add message sizes to `addMessageEvent` function * Add comment to message event id * Fixes based on review comments
1 parent 82b26d2 commit a687f7f

File tree

4 files changed

+29
-7
lines changed

4 files changed

+29
-7
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ All notable changes to this project will be documented in this file.
44

55
## Unreleased
66

7+
- Add optional `compressedSize` and `uncompressedSize` params to `Span.addMessageEvent`
78

89
## 0.0.9 - 2019-02-12
910
- Add Metrics API.

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

+11-4
Original file line numberDiff line numberDiff line change
@@ -209,18 +209,25 @@ export abstract class SpanBase implements types.Span {
209209
* @param type The type of message event.
210210
* @param id An identifier for the message event.
211211
* @param timestamp A time in milliseconds. Defaults to Date.now()
212+
* @param uncompressedSize The number of uncompressed bytes sent or received
213+
* @param compressedSize The number of compressed bytes sent or received. If
214+
* zero or undefined, assumed to be the same size as uncompressed.
212215
*/
213-
addMessageEvent(type: types.MessageEventType, id: string, timestamp = 0) {
216+
addMessageEvent(
217+
type: types.MessageEventType, id: string, timestamp = 0,
218+
uncompressedSize?: number, compressedSize?: number) {
214219
if (this.messageEvents.length >=
215220
this.activeTraceParams.numberOfMessageEventsPerSpan) {
216221
this.messageEvents.shift();
217222
this.droppedMessageEventsCount++;
218223
}
219224

220225
this.messageEvents.push({
221-
'type': type,
222-
'id': id,
223-
'timestamp': timestamp ? timestamp : Date.now(),
226+
type,
227+
id,
228+
timestamp: timestamp ? timestamp : Date.now(),
229+
uncompressedSize,
230+
compressedSize,
224231
} as types.MessageEvent);
225232
}
226233

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

+7-1
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,13 @@ export interface MessageEvent {
192192
timestamp: number;
193193
/** Indicates whether the message was sent or received. */
194194
type: MessageEventType;
195-
/** An identifier for the MessageEvent's message. */
195+
/**
196+
* An identifier for the MessageEvent's message. This should be a hexadecimal
197+
* value that fits within 64-bits. Message event ids should start with 1 for
198+
* both sent and received messages and increment by 1 for each message
199+
* sent/received. See:
200+
* https://github.com/census-instrumentation/opencensus-specs/blob/master/trace/gRPC.md#message-events
201+
*/
196202
id: string;
197203
/** The number of uncompressed bytes sent or received. */
198204
uncompressedSize?: number;

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

+10-2
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ import {CoreTracer} from '../src/trace/model/tracer';
2121
import * as types from '../src/trace/model/types';
2222
import {Annotation, Attributes, Link} from '../src/trace/model/types';
2323

24-
2524
// TODO: we should evaluate a way to merge similar test cases between span and
2625
// rootspan
2726

@@ -304,9 +303,18 @@ describe('Span', () => {
304303
span.start();
305304

306305
span.addMessageEvent(
307-
types.MessageEventType.UNSPECIFIED, 'message_event_test_id');
306+
types.MessageEventType.UNSPECIFIED, /* id */ '1',
307+
/* timestamp */ 1550000000000, /* uncompressedSize */ 55,
308+
/** compressedSize */ 40);
308309

309310
assert.ok(span.messageEvents.length > 0);
311+
assert.deepEqual(span.messageEvents, [{
312+
type: types.MessageEventType.UNSPECIFIED,
313+
id: '1',
314+
timestamp: 1550000000000,
315+
uncompressedSize: 55,
316+
compressedSize: 40,
317+
}]);
310318
assert.equal(span.droppedMessageEventsCount, 0);
311319
assert.ok(instanceOfLink(span.messageEvents[0]));
312320
});

0 commit comments

Comments
 (0)