-
Notifications
You must be signed in to change notification settings - Fork 306
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add module tests + do not enable when not specified
- Loading branch information
Showing
2 changed files
with
69 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
'use strict' | ||
|
||
const proxyquire = require('proxyquire') | ||
const { channel } = require('dc-polyfill') | ||
const injectCh = channel('dd-trace:span:inject') | ||
|
||
describe('module', () => { | ||
let llmobsModule | ||
let store | ||
let logger | ||
|
||
beforeEach(() => { | ||
store = {} | ||
logger = { debug: sinon.stub() } | ||
llmobsModule = proxyquire('../../../dd-trace/src/llmobs', { | ||
'../log': logger, | ||
'../../../datadog-core': { | ||
storage: { | ||
getStore () { | ||
return store | ||
} | ||
} | ||
} | ||
}) | ||
}) | ||
|
||
it('injects LLMObs parent ID when there is a parent LLMObs span', () => { | ||
llmobsModule.enable({}) | ||
store.llmobsSpan = { | ||
context () { | ||
return { | ||
toSpanId () { | ||
return 'parent-id' | ||
} | ||
} | ||
} | ||
} | ||
|
||
const carrier = { | ||
'x-datadog-tags': '' | ||
} | ||
injectCh.publish({ carrier }) | ||
|
||
expect(carrier['x-datadog-tags']).to.equal(',_dd.p.llmobs_parent_id=parent-id') | ||
}) | ||
|
||
it('does not inject LLMObs parent ID when there is no parent LLMObs span', () => { | ||
llmobsModule.enable({}) | ||
|
||
const carrier = { | ||
'x-datadog-tags': '' | ||
} | ||
injectCh.publish({ carrier }) | ||
expect(logger.debug).to.have.been.calledWith('No active span to inject LLMObs info.') | ||
expect(carrier['x-datadog-tags']).to.equal('') | ||
}) | ||
|
||
it('does nothing after being disabled', () => { | ||
const before = injectCh._subscribers.length | ||
llmobsModule.enable({}) | ||
const during = injectCh._subscribers.length | ||
llmobsModule.disable() | ||
const after = injectCh._subscribers.length | ||
|
||
expect(during).to.equal(before + 1) | ||
expect(after).to.equal(before) | ||
}) | ||
}) |