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

Commit bd4f1b6

Browse files
authored
Message events: use counters instead of hexdecimal value (#446)
* Message events: use counters instread of hexdecimal string * Change id to number instead of string to match specs This is mostly used in the internal APIs and it won't impact the end users.
1 parent 0c733be commit bd4f1b6

File tree

22 files changed

+69
-103
lines changed

22 files changed

+69
-103
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ All notable changes to this project will be documented in this file.
2424
- Add `TagMetadata` that defines the properties associated with a `Tag`.
2525
- Add HTTP text format serializer to Tag propagation component.
2626
- Enforce `--strictNullChecks` and `--noUnusedLocals` Compiler Options on [opencensus-core] package.
27+
- Please note that there is an API breaking change in methods `addMessageEvent()`. The field `id` is now number instead of string.
2728

2829
## 0.0.9 - 2019-02-12
2930
- Add Metrics API.

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ export abstract class NoRecordSpanBase implements types.Span {
129129

130130
/** No-op implementation of this method. */
131131
addMessageEvent(
132-
type: types.MessageEventType, id: string, timestamp = 0,
132+
type: types.MessageEventType, id: number, timestamp = 0,
133133
uncompressedSize?: number, compressedSize?: number) {}
134134

135135
/** No-op implementation of this method. */

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,7 @@ export abstract class SpanBase implements types.Span {
218218
* zero or undefined, assumed to be the same size as uncompressed.
219219
*/
220220
addMessageEvent(
221-
type: types.MessageEventType, id: string, timestamp = 0,
221+
type: types.MessageEventType, id: number, timestamp = 0,
222222
uncompressedSize?: number, compressedSize?: number) {
223223
if (this.messageEvents.length >=
224224
this.activeTraceParams.numberOfMessageEventsPerSpan!) {

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

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -191,13 +191,12 @@ export interface MessageEvent {
191191
/** Indicates whether the message was sent or received. */
192192
type: MessageEventType;
193193
/**
194-
* An identifier for the MessageEvent's message. This should be a hexadecimal
195-
* value that fits within 64-bits. Message event ids should start with 1 for
194+
* An identifier for the MessageEvent's message that can be used to match
195+
* SENT and RECEIVED MessageEvents. Message event ids should start with 1 for
196196
* both sent and received messages and increment by 1 for each message
197-
* sent/received. See:
198-
* https://github.com/census-instrumentation/opencensus-specs/blob/master/trace/gRPC.md#message-events
197+
* sent/received.
199198
*/
200-
id: string;
199+
id: number;
201200
/** The number of uncompressed bytes sent or received. */
202201
uncompressedSize?: number;
203202
/**
@@ -433,7 +432,7 @@ export interface Span {
433432
* zero or undefined, assumed to be the same size as uncompressed.
434433
*/
435434
addMessageEvent(
436-
type: MessageEventType, id: string, timestamp?: number,
435+
type: MessageEventType, id: number, timestamp?: number,
437436
uncompressedSize?: number, compressedSize?: number): void;
438437

439438
/**

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,7 @@ describe('NoRecordRootSpan()', () => {
2828
noRecordRootSpan.addAnnotation(
2929
'MyAnnotation', {myString: 'bar', myNumber: 123, myBoolean: true});
3030
noRecordRootSpan.addLink('aaaaa', 'aaa', LinkType.CHILD_LINKED_SPAN);
31-
noRecordRootSpan.addMessageEvent(
32-
MessageEventType.RECEIVED, 'aaaa', 123456789);
31+
noRecordRootSpan.addMessageEvent(MessageEventType.RECEIVED, 1, 123456789);
3332
noRecordRootSpan.addAttribute('my_first_attribute', 'foo');
3433
noRecordRootSpan.setStatus(CanonicalCode.OK);
3534
noRecordRootSpan.startChildSpan();

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ describe('NoRecordSpan()', () => {
2525
noRecordSpan.addAnnotation(
2626
'MyAnnotation', {myString: 'bar', myNumber: 123, myBoolean: true});
2727
noRecordSpan.addLink('aaaaa', 'aaa', LinkType.CHILD_LINKED_SPAN);
28-
noRecordSpan.addMessageEvent(MessageEventType.RECEIVED, 'aaaa', 123456789);
28+
noRecordSpan.addMessageEvent(MessageEventType.RECEIVED, 1, 123456789);
2929
noRecordSpan.addAttribute('my_first_attribute', 'foo');
3030
noRecordSpan.setStatus(CanonicalCode.OK);
3131
});

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

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -271,9 +271,7 @@ describe('RootSpan', () => {
271271

272272
const rootSpan = new RootSpan(tracer, name, kind, traceId, parentSpanId);
273273
rootSpan.start();
274-
275-
rootSpan.addMessageEvent(
276-
types.MessageEventType.UNSPECIFIED, 'message_event_test_id');
274+
rootSpan.addMessageEvent(types.MessageEventType.UNSPECIFIED, 1);
277275

278276
assert.ok(rootSpan.messageEvents.length > 0);
279277
assert.equal(rootSpan.droppedMessageEventsCount, 0);

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

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -308,14 +308,14 @@ describe('Span', () => {
308308
span.start();
309309

310310
span.addMessageEvent(
311-
types.MessageEventType.UNSPECIFIED, /* id */ '1',
311+
types.MessageEventType.UNSPECIFIED, /* id */ 1,
312312
/* timestamp */ 1550000000000, /* uncompressedSize */ 55,
313313
/** compressedSize */ 40);
314314

315315
assert.ok(span.messageEvents.length > 0);
316316
assert.deepEqual(span.messageEvents, [{
317317
type: types.MessageEventType.UNSPECIFIED,
318-
id: '1',
318+
id: 1,
319319
timestamp: 1550000000000,
320320
uncompressedSize: 55,
321321
compressedSize: 40,
@@ -331,8 +331,7 @@ describe('Span', () => {
331331
const span = new Span(rootSpan);
332332
span.start();
333333
for (let i = 0; i < 35; i++) {
334-
span.addMessageEvent(
335-
types.MessageEventType.UNSPECIFIED, 'message_event_test_id');
334+
span.addMessageEvent(types.MessageEventType.UNSPECIFIED, 1);
336335
}
337336

338337
assert.equal(span.messageEvents.length, 32);

packages/opencensus-exporter-ocagent/src/adapters.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -179,8 +179,7 @@ const adaptTimeEvents =
179179
timeEvents.push({
180180
time: millisToTimestamp(messageEvent.timestamp),
181181
messageEvent: {
182-
// tslint:disable-next-line:ban Needed to parse hexadecimal.
183-
id: parseInt(messageEvent.id, 16),
182+
id: messageEvent.id,
184183
type: adaptMessageEventType(messageEvent.type),
185184
uncompressedSize: messageEvent.uncompressedSize || 0,
186185
compressedSize: messageEvent.compressedSize || 0

packages/opencensus-exporter-ocagent/test/test-ocagent.ts

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -269,13 +269,12 @@ describe('OpenCensus Agent Exporter', () => {
269269

270270
// Message Event
271271
const timeStamp = 123456789;
272-
rootSpan.addMessageEvent(MessageEventType.SENT, 'aaaa', timeStamp);
273-
rootSpan.addMessageEvent(
274-
MessageEventType.SENT, 'ffff', timeStamp, 100, 12);
275-
rootSpan.addMessageEvent(MessageEventType.RECEIVED, 'ffff', timeStamp);
272+
rootSpan.addMessageEvent(MessageEventType.SENT, 1, timeStamp);
273+
rootSpan.addMessageEvent(MessageEventType.SENT, 2, timeStamp, 100, 12);
274+
rootSpan.addMessageEvent(MessageEventType.RECEIVED, 1, timeStamp);
276275
// Use of `null` is to force a `TYPE_UNSPECIFIED` value
277276
// tslint:disable-next-line:no-any
278-
rootSpan.addMessageEvent(null as any, 'ffff', timeStamp);
277+
rootSpan.addMessageEvent(null as any, 2, timeStamp);
279278

280279
// Links
281280
rootSpan.addLink('aaaaa', 'aaa', LinkType.CHILD_LINKED_SPAN);
@@ -388,7 +387,7 @@ describe('OpenCensus Agent Exporter', () => {
388387
{
389388
messageEvent: {
390389
compressedSize: '12',
391-
id: '65535',
390+
id: 2,
392391
type: 'SENT',
393392
uncompressedSize: '100'
394393
},
@@ -399,7 +398,7 @@ describe('OpenCensus Agent Exporter', () => {
399398
value: 'messageEvent',
400399
messageEvent: {
401400
compressedSize: '0',
402-
id: '65535',
401+
id: 1,
403402
type: 'RECEIVED',
404403
uncompressedSize: '0'
405404
},
@@ -409,7 +408,7 @@ describe('OpenCensus Agent Exporter', () => {
409408
value: 'messageEvent',
410409
messageEvent: {
411410
compressedSize: '0',
412-
id: '65535',
411+
id: 2,
413412
type: 'TYPE_UNSPECIFIED',
414413
uncompressedSize: '0'
415414
},
@@ -493,8 +492,8 @@ describe('OpenCensus Agent Exporter', () => {
493492

494493
// Message Event
495494
const timeStamp = 123456789;
496-
rootSpan.addMessageEvent(MessageEventType.SENT, 'ffff', timeStamp);
497-
rootSpan.addMessageEvent(MessageEventType.RECEIVED, 'ffff', timeStamp);
495+
rootSpan.addMessageEvent(MessageEventType.SENT, 1, timeStamp);
496+
rootSpan.addMessageEvent(MessageEventType.RECEIVED, 1, timeStamp);
498497

499498
// Links
500499
rootSpan.addLink('ffff', 'ffff', LinkType.CHILD_LINKED_SPAN, {
@@ -577,7 +576,7 @@ describe('OpenCensus Agent Exporter', () => {
577576
{
578577
messageEvent: {
579578
compressedSize: '0',
580-
id: '65535',
579+
id: 1,
581580
type: 'SENT',
582581
uncompressedSize: '0'
583582
},
@@ -588,7 +587,7 @@ describe('OpenCensus Agent Exporter', () => {
588587
value: 'messageEvent',
589588
messageEvent: {
590589
compressedSize: '0',
591-
id: '65535',
590+
id: 1,
592591
type: 'RECEIVED',
593592
uncompressedSize: '0'
594593
},

0 commit comments

Comments
 (0)