Skip to content

Commit 04f6bc4

Browse files
authored
chore(llmobs): Add llmobs product enabled telemetry metrics (#5475)
* Add product_enabled metric, need to add tags * Add llmobs enabled metrics - wip, add more tags * Add manual flag * Use env var check * Allow optional envs * fmt
1 parent 312a500 commit 04f6bc4

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ const { storage } = require('./storage')
66

77
const LLMObsSpanProcessor = require('./span_processor')
88

9+
const telemetry = require('./telemetry')
910
const { channel } = require('dc-polyfill')
1011
const spanProcessCh = channel('dd-trace:span:process')
1112
const evalMetricAppendCh = channel('llmobs:eval-metric:append')
@@ -29,6 +30,7 @@ let spanWriter
2930
let evalWriter
3031

3132
function enable (config) {
33+
const startTime = performance.now()
3234
// create writers and eval writer append and flush channels
3335
// span writer append is handled by the span processor
3436
evalWriter = new LLMObsEvalMetricsWriter(config)
@@ -44,6 +46,7 @@ function enable (config) {
4446

4547
// distributed tracing for llmobs
4648
injectCh.subscribe(handleLLMObsParentIdInjection)
49+
telemetry.recordLLMObsEnabled(startTime, config)
4750
}
4851

4952
function disable () {

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

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,23 @@ function incrementLLMObsSpanFinishedCount (span, value = 1) {
7474
llmobsMetrics.count('span.finished', tags).inc(value)
7575
}
7676

77+
function recordLLMObsEnabled (startTime, config, value = 1) {
78+
const initTimeMs = performance.now() - startTime
79+
// There isn't an easy way to determine if a user automatically enabled LLMObs via
80+
// in-code or command line setup. We'll use the presence of DD_LLMOBS_ENABLED env var
81+
// as a rough heuristic, but note that this isn't perfect since
82+
// a user may have env vars but enable manually in code.
83+
const autoEnabled = !!config._env?.['llmobs.enabled']
84+
const tags = {
85+
error: 0,
86+
agentless: Number(config.llmobs.agentlessEnabled),
87+
site: config.site,
88+
auto: Number(autoEnabled)
89+
}
90+
llmobsMetrics.count('product_enabled', tags).inc(value)
91+
llmobsMetrics.distribution('init_time', tags).track(initTimeMs)
92+
}
93+
7794
function recordLLMObsRawSpanSize (event, rawEventSize) {
7895
const tags = extractTagsFromSpanEvent(event)
7996
llmobsMetrics.distribution('span.raw_size', tags).track(rawEventSize)
@@ -86,6 +103,7 @@ function recordLLMObsSpanSize (event, eventSize, shouldTruncate) {
86103
}
87104

88105
module.exports = {
106+
recordLLMObsEnabled,
89107
incrementLLMObsSpanStartCount,
90108
incrementLLMObsSpanFinishedCount,
91109
recordLLMObsRawSpanSize,

0 commit comments

Comments
 (0)