Skip to content

Commit 2fd9b1d

Browse files
authored
fix(llmobs): make sure all sdk methods are on the no-op sdk as well (#6949)
* add in forgotten no-op functions * update & make no-op tests more explicit * add test to verify method consistency
1 parent f04d912 commit 2fd9b1d

File tree

2 files changed

+70
-5
lines changed

2 files changed

+70
-5
lines changed

packages/dd-trace/src/llmobs/noop.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,12 @@ class NoopLLMObs {
7575
submitEvaluation (llmobsSpanContext, options) {}
7676

7777
flush () {}
78+
79+
registerProcessor (processor) {}
80+
81+
deregisterProcessor () {}
82+
83+
annotationContext (options, fn) { return fn() }
7884
}
7985

8086
module.exports = NoopLLMObs

packages/dd-trace/test/llmobs/noop.spec.js

Lines changed: 64 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,23 @@
33
const { expect } = require('chai')
44
const { describe, it, before } = require('mocha')
55

6+
const assert = require('node:assert')
7+
8+
const LLMObsSDK = require('../../../dd-trace/src/llmobs/sdk')
9+
10+
function getClassMethods (clsProto, { ignore = [] } = {}) {
11+
const ignoreList = new Set(['constructor', ...[].concat(ignore)])
12+
return Object.getOwnPropertyNames(clsProto)
13+
.filter(member => {
14+
if (member.startsWith('_') || ignoreList.has(member)) {
15+
return false
16+
}
17+
18+
const descriptor = Object.getOwnPropertyDescriptor(clsProto, member)
19+
return descriptor && typeof descriptor.value === 'function'
20+
})
21+
}
22+
623
describe('noop', () => {
724
let tracer
825
let llmobs
@@ -12,12 +29,54 @@ describe('noop', () => {
1229
llmobs = tracer.llmobs
1330
})
1431

15-
const nonTracingOps = ['enable', 'disable', 'annotate', 'exportSpan', 'submitEvaluation', 'flush']
16-
for (const op of nonTracingOps) {
17-
it(`using "${op}" should not throw`, () => {
18-
llmobs[op]()
32+
it('has all of the methods that the actual LLMObs SDK does', () => {
33+
assert.deepStrictEqual(
34+
getClassMethods(LLMObsSDK.prototype).sort(),
35+
// the actual LLMObs SDK inherits the "decorate" method from the NoopLLMObs SDK
36+
// so we need to ignore it from the noop LLMObs SDK when comparing
37+
getClassMethods(Object.getPrototypeOf(llmobs), { ignore: ['decorate'] }).sort()
38+
)
39+
})
40+
41+
it('using "enable" should not throw', () => {
42+
llmobs.enable()
43+
})
44+
45+
it('using "disable" should not throw', () => {
46+
llmobs.disable()
47+
})
48+
49+
it('using "annotate" should not throw', () => {
50+
llmobs.annotate()
51+
})
52+
53+
it('using "exportSpan" should not throw', () => {
54+
llmobs.exportSpan()
55+
})
56+
57+
it('using "submitEvaluation" should not throw', () => {
58+
llmobs.submitEvaluation()
59+
})
60+
61+
it('using "flush" should not throw', () => {
62+
llmobs.flush()
63+
})
64+
65+
it('using "registerProcessor" should not throw', () => {
66+
llmobs.registerProcessor(() => {})
67+
})
68+
69+
it('using "deregisterProcessor" should not throw', () => {
70+
llmobs.deregisterProcessor()
71+
})
72+
73+
it('using "annotationContext" should not throw', () => {
74+
const result = llmobs.annotationContext({}, () => {
75+
return 5
1976
})
20-
}
77+
78+
assert.equal(result, 5)
79+
})
2180

2281
describe('trace', () => {
2382
it('should not throw with just a span', () => {

0 commit comments

Comments
 (0)