Skip to content

Commit

Permalink
feat: Added supportability metric to track when streaming is disabled
Browse files Browse the repository at this point in the history
  • Loading branch information
bizob2828 committed Feb 15, 2024
1 parent e911bd7 commit af8e361
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 4 deletions.
6 changes: 3 additions & 3 deletions lib/instrumentation/openai.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,8 @@ const { RecorderSpec } = require('../../lib/shim/specs')

const MIN_VERSION = '4.0.0'
const MIN_STREAM_VERSION = '4.12.2'
const {
AI: { OPENAI }
} = require('../../lib/metrics/names')
const { AI } = require('../../lib/metrics/names')
const { OPENAI } = AI
const semver = require('semver')
const { DESTINATIONS } = require('../config/attribute-filter')

Expand Down Expand Up @@ -189,6 +188,7 @@ function instrumentStream({ agent, shim, request, response, segment }) {
shim.logger.warn(
'`ai_monitoring.streaming.enabled` is set to `false`, stream will not be instrumented.'
)
agent.metrics.getOrCreateMetric(AI.STREAMING_DISABLED).incrementCallCount()
return
}

Expand Down
3 changes: 2 additions & 1 deletion lib/metrics/names.js
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,8 @@ const EXPRESS = {
}

const AI = {
TRACKING_PREFIX: 'Supportability/Nodejs/ML',
TRACKING_PREFIX: `${SUPPORTABILITY.NODEJS}/ML`,
STREAMING_DISABLED: `${SUPPORTABILITY.NODEJS}/ML/Streaming/Disabled`,
EMBEDDING: 'Llm/embedding',
COMPLETION: 'Llm/completion'
}
Expand Down
4 changes: 4 additions & 0 deletions test/versioned/openai/chat-completions.tap.js
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,10 @@ tap.test('OpenAI instrumentation - chat completions', (t) => {
test.equal(metrics.callCount > 0, true)
const attributes = tx.trace.attributes.get(DESTINATIONS.TRANS_EVENT)
test.equal(attributes.llm, true)
const streamingDisabled = agent.metrics.getOrCreateMetric(
'Supportability/Nodejs/ML/Streaming/Disabled'
)
test.equal(streamingDisabled.callCount > 0, true)
tx.end()
test.end()
})
Expand Down

0 comments on commit af8e361

Please sign in to comment.