Skip to content

Commit

Permalink
Added tests for adding custom attributes on span
Browse files Browse the repository at this point in the history
  • Loading branch information
adampapadopoulos committed Nov 16, 2023
1 parent 2978c20 commit 9ffce41
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -582,6 +582,26 @@ describe('UserInteractionInstrumentation', () => {
assertInteractionSpan(span, { name: 'play' });
});

it('should apply custom attributes to spans', () => {
const customAttributeName = 'custom_attribute';
const customAttributeValue = 'custom_attribute_value';
registerTestInstrumentations({
eventNames: ['play'],
applyCustomAttributesOnSpan: (span) => {
span.setAttribute(customAttributeName, customAttributeValue)
},
});

fakeEventInteraction('play');
assert.strictEqual(exportSpy.args.length, 1, 'should export one span');
const span = exportSpy.args[0][0][0];
assert.strictEqual(
span.attributes[customAttributeName],
customAttributeValue,
'should have custom attribute on span'
);
});

it('should not be exported not configured spans', () => {
registerTestInstrumentations({
eventNames: ['play'],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,26 @@ describe('UserInteractionInstrumentation', () => {
assertInteractionSpan(span, { name: 'play' });
});

it('should apply custom attributes to spans', () => {
const customAttributeName = 'custom_attribute';
const customAttributeValue = 'custom_attribute_value';
registerTestInstrumentations({
eventNames: ['play'],
applyCustomAttributesOnSpan: (span) => {
span.setAttribute(customAttributeName, customAttributeValue)
},
});

fakeEventInteraction('play');
assert.strictEqual(exportSpy.args.length, 1, 'should export one span');
const span = exportSpy.args[0][0][0];
assert.strictEqual(
span.attributes[customAttributeName],
customAttributeValue,
'should have custom attribute on span'
);
});

it('not configured spans should not be exported', () => {
registerTestInstrumentations({
eventNames: ['play'],
Expand Down

0 comments on commit 9ffce41

Please sign in to comment.