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

add default value when attributes are not specified #351

Merged
merged 2 commits into from
Feb 19, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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