Skip to content

Commit

Permalink
fix: Reverted openai instrumentation update to handle broken version …
Browse files Browse the repository at this point in the history
…of 4.40.1 (#2182)
  • Loading branch information
bizob2828 authored May 3, 2024
1 parent d72d19b commit 6968f0a
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 11 deletions.
10 changes: 0 additions & 10 deletions lib/instrumentation/openai.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ const { RecorderSpec } = require('../../lib/shim/specs')

const MIN_VERSION = '4.0.0'
const MIN_STREAM_VERSION = '4.12.2'
const WRAP_EXPORTS = '4.40.1'
const { AI } = require('../../lib/metrics/names')
const { OPENAI } = AI
const semver = require('semver')
Expand Down Expand Up @@ -219,15 +218,6 @@ module.exports = function initialize(agent, openai, moduleName, shim) {
// initially declaring the variable.
TRACKING_METRIC = `${TRACKING_METRIC}/${shim.pkgVersion}`

if (semver.gte(shim.pkgVersion, WRAP_EXPORTS)) {
instrumentExport({ openai: openai.OpenAI, shim })
} else {
instrumentExport({ openai, shim })
}
}

function instrumentExport({ openai, shim }) {
const { agent } = shim
/**
* Instrumentation is only done to get the response headers and attach
* to the active segment as openai hides the headers from the functions we are
Expand Down
2 changes: 1 addition & 1 deletion test/versioned/openai/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ common.beforeHook = async function beforeHook(t) {
t.context.port = port
t.context.server = server
t.context.agent = helper.instrumentMockedAgent(config)
const OpenAI = require('openai').default
const OpenAI = require('openai')
t.context.client = new OpenAI({
apiKey: 'fake-versioned-test-key',
baseURL: `http://${host}:${port}`
Expand Down

0 comments on commit 6968f0a

Please sign in to comment.