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

Commit

Permalink
Add message sizes to addMessageEvent function (#344)
Browse files Browse the repository at this point in the history
* Add message sizes to `addMessageEvent` function

* Add comment to message event id

* Fixes based on review comments
  • Loading branch information
draffensperger authored and mayurkale22 committed Feb 14, 2019
1 parent 82b26d2 commit a687f7f
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 7 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ All notable changes to this project will be documented in this file.

## Unreleased

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

## 0.0.9 - 2019-02-12
- Add Metrics API.
Expand Down
15 changes: 11 additions & 4 deletions packages/opencensus-core/src/trace/model/span-base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -209,18 +209,25 @@ export abstract class SpanBase implements types.Span {
* @param type The type of message event.
* @param id An identifier for the message event.
* @param timestamp A time in milliseconds. Defaults to Date.now()
* @param uncompressedSize The number of uncompressed bytes sent or received
* @param compressedSize The number of compressed bytes sent or received. If
* zero or undefined, assumed to be the same size as uncompressed.
*/
addMessageEvent(type: types.MessageEventType, id: string, timestamp = 0) {
addMessageEvent(
type: types.MessageEventType, id: string, timestamp = 0,
uncompressedSize?: number, compressedSize?: number) {
if (this.messageEvents.length >=
this.activeTraceParams.numberOfMessageEventsPerSpan) {
this.messageEvents.shift();
this.droppedMessageEventsCount++;
}

this.messageEvents.push({
'type': type,
'id': id,
'timestamp': timestamp ? timestamp : Date.now(),
type,
id,
timestamp: timestamp ? timestamp : Date.now(),
uncompressedSize,
compressedSize,
} as types.MessageEvent);
}

Expand Down
8 changes: 7 additions & 1 deletion packages/opencensus-core/src/trace/model/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,13 @@ export interface MessageEvent {
timestamp: number;
/** Indicates whether the message was sent or received. */
type: MessageEventType;
/** An identifier for the MessageEvent's message. */
/**
* An identifier for the MessageEvent's message. This should be a hexadecimal
* value that fits within 64-bits. Message event ids should start with 1 for
* both sent and received messages and increment by 1 for each message
* sent/received. See:
* https://github.com/census-instrumentation/opencensus-specs/blob/master/trace/gRPC.md#message-events
*/
id: string;
/** The number of uncompressed bytes sent or received. */
uncompressedSize?: number;
Expand Down
12 changes: 10 additions & 2 deletions packages/opencensus-core/test/test-span.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import {CoreTracer} from '../src/trace/model/tracer';
import * as types from '../src/trace/model/types';
import {Annotation, Attributes, Link} from '../src/trace/model/types';


// TODO: we should evaluate a way to merge similar test cases between span and
// rootspan

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

span.addMessageEvent(
types.MessageEventType.UNSPECIFIED, 'message_event_test_id');
types.MessageEventType.UNSPECIFIED, /* id */ '1',
/* timestamp */ 1550000000000, /* uncompressedSize */ 55,
/** compressedSize */ 40);

assert.ok(span.messageEvents.length > 0);
assert.deepEqual(span.messageEvents, [{
type: types.MessageEventType.UNSPECIFIED,
id: '1',
timestamp: 1550000000000,
uncompressedSize: 55,
compressedSize: 40,
}]);
assert.equal(span.droppedMessageEventsCount, 0);
assert.ok(instanceOfLink(span.messageEvents[0]));
});
Expand Down

0 comments on commit a687f7f

Please sign in to comment.