Skip to content

Commit 743f896

Browse files
authoredMar 4, 2025··
[MLOB-2333] chore(llmobs): add telemetry for LLMObs span start (#5359)
* add llmobs telemetry span start counts * change autoinstrumentation to autoinstrumented * add telemetry to wrap * integration name instead of kind
1 parent ba2c256 commit 743f896

File tree

6 files changed

+25
-0
lines changed

6 files changed

+25
-0
lines changed
 

‎packages/dd-trace/src/llmobs/plugins/base.js

+3
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
const log = require('../../log')
44
const { storage: llmobsStorage } = require('../storage')
5+
const telemetry = require('../telemetry')
56

67
const TracingPlugin = require('../../plugins/tracing')
78
const LLMObsTagger = require('../tagger')
@@ -36,6 +37,8 @@ class LLMObsPlugin extends TracingPlugin {
3637
// register options may not be set for operations we do not trace with llmobs
3738
// ie OpenAI fine tuning jobs, file jobs, etc.
3839
if (registerOptions) {
40+
telemetry.incrementLLMObsSpanStartCount({ autoinstrumented: true, integration: this.constructor.id })
41+
3942
ctx.llmobs = {} // initialize context-based namespace
4043
llmobsStorage.enterWith({ span })
4144
ctx.llmobs.parent = parent

‎packages/dd-trace/src/llmobs/plugins/bedrockruntime.js

+3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
const BaseLLMObsPlugin = require('./base')
22
const { storage } = require('../../../../datadog-core')
33
const llmobsStore = storage('llmobs')
4+
const telemetry = require('../telemetry')
45

56
const {
67
extractRequestParams,
@@ -46,6 +47,8 @@ class BedrockRuntimeLLMObsPlugin extends BaseLLMObsPlugin {
4647
}
4748

4849
setLLMObsTags ({ request, span, response, modelProvider, modelName }) {
50+
telemetry.incrementLLMObsSpanStartCount({ autoinstrumented: true, integration: 'bedrock' })
51+
4952
const parent = llmobsStore.getStore()?.span
5053
this._tagger.registerLLMObsSpan(span, {
5154
parent,

‎packages/dd-trace/src/llmobs/plugins/langchain/index.js

+1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ const LlmHandler = require('./handlers/llm')
2121
const EmbeddingHandler = require('./handlers/embedding')
2222

2323
class LangChainLLMObsPlugin extends LLMObsPlugin {
24+
static get id () { return 'langchain' }
2425
static get prefix () {
2526
return 'tracing:apm:langchain:invoke'
2627
}

‎packages/dd-trace/src/llmobs/plugins/openai.js

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
const LLMObsPlugin = require('./base')
44

55
class OpenAiLLMObsPlugin extends LLMObsPlugin {
6+
static get id () { return 'openai' }
67
static get prefix () {
78
return 'tracing:apm:openai:request'
89
}

‎packages/dd-trace/src/llmobs/sdk.js

+5
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ const Span = require('../opentracing/span')
1414

1515
const tracerVersion = require('../../../../package.json').version
1616
const logger = require('../log')
17+
const telemetry = require('./telemetry')
1718

1819
const LLMObsTagger = require('./tagger')
1920

@@ -88,6 +89,8 @@ class LLMObs extends NoopLLMObs {
8889

8990
const kind = validateKind(options.kind) // will throw if kind is undefined or not an expected kind
9091

92+
telemetry.incrementLLMObsSpanStartCount({ autoinstrumented: false, kind })
93+
9194
// name is required for spans generated with `trace`
9295
// while `kind` is required, this should never throw (as otherwise it would have thrown above)
9396
const name = options.name || kind
@@ -133,6 +136,8 @@ class LLMObs extends NoopLLMObs {
133136
const llmobs = this
134137

135138
function wrapped () {
139+
telemetry.incrementLLMObsSpanStartCount({ autoinstrumented: false, kind })
140+
136141
const span = llmobs._tracer.scope().active()
137142
const fnArgs = arguments
138143

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
'use strict'
2+
3+
const telemetryMetrics = require('../telemetry/metrics')
4+
const llmobsMetrics = telemetryMetrics.manager.namespace('mlobs')
5+
6+
function incrementLLMObsSpanStartCount (tags, value = 1) {
7+
llmobsMetrics.count('span.start', tags).inc(value)
8+
}
9+
10+
module.exports = {
11+
incrementLLMObsSpanStartCount
12+
}

0 commit comments

Comments
 (0)
Please sign in to comment.