Skip to content

Commit

Permalink
add module tests + do not enable when not specified
Browse files Browse the repository at this point in the history
  • Loading branch information
sabrenner committed Oct 15, 2024
1 parent dbe664d commit 00d4572
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 1 deletion.
2 changes: 1 addition & 1 deletion packages/dd-trace/src/llmobs/sdk.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class LLMObs {

this._handleSpanProcess = data => this._processor.process(data)

this._enable()
if (this.enabled) this._enable()
}

get enabled () {
Expand Down
68 changes: 68 additions & 0 deletions packages/dd-trace/test/llmobs/index.spec.js
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)
})
})

0 comments on commit 00d4572

Please sign in to comment.