Skip to content

Commit 398b78a

Browse files
authored
fix(llmobs): do not submit spans without an ml application specified (#5986)
* fix no ml app error
1 parent 9b24b9a commit 398b78a

File tree

2 files changed

+42
-13
lines changed

2 files changed

+42
-13
lines changed

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

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -61,19 +61,6 @@ class LLMObsTagger {
6161
if (!this._config.llmobs.enabled) return
6262
if (!kind) return // do not register it in the map if it doesn't have an llmobs span kind
6363

64-
this._register(span)
65-
66-
if (name) this._setTag(span, NAME, name)
67-
68-
this._setTag(span, SPAN_KIND, kind)
69-
if (modelName) this._setTag(span, MODEL_NAME, modelName)
70-
if (modelProvider) this._setTag(span, MODEL_PROVIDER, modelProvider)
71-
72-
sessionId = sessionId || registry.get(parent)?.[SESSION_ID]
73-
if (sessionId) this._setTag(span, SESSION_ID, sessionId)
74-
if (integration) this._setTag(span, INTEGRATION, integration)
75-
if (_decorator) this._setTag(span, DECORATOR, _decorator)
76-
7764
const spanMlApp =
7865
mlApp ||
7966
registry.get(parent)?.[ML_APP] ||
@@ -87,8 +74,21 @@ class LLMObsTagger {
8774
)
8875
}
8976

77+
this._register(span)
78+
9079
this._setTag(span, ML_APP, spanMlApp)
9180

81+
if (name) this._setTag(span, NAME, name)
82+
83+
this._setTag(span, SPAN_KIND, kind)
84+
if (modelName) this._setTag(span, MODEL_NAME, modelName)
85+
if (modelProvider) this._setTag(span, MODEL_PROVIDER, modelProvider)
86+
87+
sessionId = sessionId || registry.get(parent)?.[SESSION_ID]
88+
if (sessionId) this._setTag(span, SESSION_ID, sessionId)
89+
if (integration) this._setTag(span, INTEGRATION, integration)
90+
if (_decorator) this._setTag(span, DECORATOR, _decorator)
91+
9292
const parentId =
9393
parent?.context().toSpanId() ??
9494
span.context()._trace.tags[PROPAGATED_PARENT_ID_KEY] ??

packages/dd-trace/test/llmobs/sdk/integration.spec.js

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -294,4 +294,33 @@ describe('end to end sdk integration tests', () => {
294294
expect(getTag(llmobsSpans[2], 'ml_app')).to.equal('test')
295295
})
296296
})
297+
298+
describe('with no global mlApp', () => {
299+
let originalMlApp
300+
301+
before(() => {
302+
originalMlApp = tracer._tracer._config.llmobs.mlApp
303+
tracer._tracer._config.llmobs.mlApp = null
304+
})
305+
306+
after(() => {
307+
tracer._tracer._config.llmobs.mlApp = originalMlApp
308+
})
309+
310+
it('does not submit a span if there is no mlApp', () => {
311+
payloadGenerator = function () {
312+
let error
313+
try {
314+
llmobs.trace({ kind: 'workflow', name: 'myWorkflow' }, () => {})
315+
} catch (e) {
316+
error = e
317+
}
318+
319+
expect(error).to.exist
320+
}
321+
322+
const { llmobsSpans } = run(payloadGenerator)
323+
expect(llmobsSpans).to.have.lengthOf(0)
324+
})
325+
})
297326
})

0 commit comments

Comments
 (0)