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

Commit

Permalink
add default value when attributes are not specified (#351)
Browse files Browse the repository at this point in the history
* add default value when attributes are not specified

* fix build
  • Loading branch information
mayurkale22 committed Feb 19, 2019
1 parent 21b64a0 commit 4530fc6
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 5 deletions.
4 changes: 2 additions & 2 deletions packages/opencensus-core/src/trace/model/span-base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ export abstract class SpanBase implements types.Span {
}
this.annotations.push({
'description': description,
'attributes': attributes,
'attributes': attributes || {},
'timestamp': timestamp ? timestamp : Date.now(),
} as types.Annotation);
}
Expand All @@ -200,7 +200,7 @@ export abstract class SpanBase implements types.Span {
'traceId': traceId,
'spanId': spanId,
'type': type,
'attributes': attributes
'attributes': attributes || {}
} as types.Link);
}

Expand Down
13 changes: 13 additions & 0 deletions packages/opencensus-core/test/test-root-span.ts
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,19 @@ describe('RootSpan', () => {
assert.equal(rootSpan.droppedAnnotationsCount, 0);
assert.ok(instanceOfAnnotation(rootSpan.annotations[0]));
});

it('should add an annotation without attributes and timestamp', () => {
const rootSpan = new RootSpan(tracer);
rootSpan.start();

rootSpan.addAnnotation('description test');

assert.ok(rootSpan.annotations.length > 0);
assert.equal(rootSpan.droppedAnnotationsCount, 0);
assert.equal(rootSpan.annotations[0].description, 'description test');
assert.deepEqual(rootSpan.annotations[0].attributes, {});
assert.ok(rootSpan.annotations[0].timestamp > 0);
});
});

/**
Expand Down
9 changes: 6 additions & 3 deletions packages/opencensus-exporter-ocagent/test/test-ocagent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -535,13 +535,15 @@ describe('OpenCensus Agent Exporter', () => {
type: 'PARENT_LINKED_SPAN',
traceId: buff,
spanId: buff,
attributes: null
attributes:
{'attributeMap': {}, 'droppedAttributesCount': 0}
},
{
type: 'TYPE_UNSPECIFIED',
traceId: buff,
spanId: buff,
attributes: null
attributes:
{'attributeMap': {}, 'droppedAttributesCount': 0}
}
]
});
Expand Down Expand Up @@ -712,7 +714,8 @@ describe('OpenCensus Agent Exporter', () => {
type: 'PARENT_LINKED_SPAN',
traceId: buff,
spanId: buff,
attributes: null
attributes:
{'attributeMap': {}, 'droppedAttributesCount': 0}
}
]
});
Expand Down

0 comments on commit 4530fc6

Please sign in to comment.