Skip to content

Commit 04a2dde

Browse files
committed
Remove vercel code leftovers from openai's
1 parent e9d9f51 commit 04a2dde

File tree

7 files changed

+13
-32
lines changed

7 files changed

+13
-32
lines changed

dev-packages/node-integration-tests/suites/tracing/openai/scenario.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ async function run() {
9999
model: 'error-model',
100100
messages: [{ role: 'user', content: 'This will fail' }],
101101
});
102-
} catch (error) {
102+
} catch {
103103
// Error is expected and handled
104104
}
105105
});

packages/core/src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ export { _INTERNAL_captureLog, _INTERNAL_flushLogsBuffer, _INTERNAL_captureSeria
125125
export { consoleLoggingIntegration } from './logs/console-integration';
126126
export { addVercelAiProcessors } from './utils/vercel-ai';
127127
export { instrumentOpenAiClient } from './utils/openai';
128-
export { INTEGRATION_NAME } from './utils/openai/constants';
128+
export { OPENAI_INTEGRATION_NAME } from './utils/openai/constants';
129129
export type { OpenAiClient, OpenAiOptions, InstrumentedMethod } from './utils/openai/types';
130130
export type { FeatureFlag } from './utils/featureFlags';
131131
export {

packages/core/src/utils/openai/constants.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
export const INTEGRATION_NAME = 'OpenAI';
1+
export const OPENAI_INTEGRATION_NAME = 'OpenAI';
22

33
// https://platform.openai.com/docs/quickstart?api-mode=responses
44
// https://platform.openai.com/docs/quickstart?api-mode=chat

packages/core/src/utils/openai/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ import {
2424
OPENAI_USAGE_COMPLETION_TOKENS_ATTRIBUTE,
2525
OPENAI_USAGE_PROMPT_TOKENS_ATTRIBUTE,
2626
} from '../gen-ai-attributes';
27-
import { INTEGRATION_NAME } from './constants';
27+
import { OPENAI_INTEGRATION_NAME } from './constants';
2828
import type {
2929
InstrumentedMethod,
3030
OpenAiChatCompletionObject,
@@ -200,7 +200,7 @@ function addRequestAttributes(span: Span, params: Record<string, unknown>): void
200200
function getOptionsFromIntegration(): OpenAiOptions {
201201
const scope = getCurrentScope();
202202
const client = scope.getClient();
203-
const integration = client?.getIntegrationByName(INTEGRATION_NAME) as OpenAiIntegration | undefined;
203+
const integration = client?.getIntegrationByName(OPENAI_INTEGRATION_NAME) as OpenAiIntegration | undefined;
204204
const shouldRecordInputsAndOutputs = integration ? Boolean(client?.getOptions().sendDefaultPii) : false;
205205

206206
return {

packages/core/src/utils/openai/utils.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,6 @@ export function getOperationName(methodPath: string): string {
1313
// The responses API is also a chat operation
1414
return OPENAI_OPERATIONS.CHAT;
1515
}
16-
if (methodPath.includes('embeddings')) {
17-
return 'embeddings';
18-
}
19-
// Default to the last part of the method path
2016
return methodPath.split('.').pop() || 'unknown';
2117
}
2218

packages/node/src/integrations/tracing/openai/index.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,16 @@
11
import type { IntegrationFn, OpenAiOptions } from '@sentry/core';
2-
import { defineIntegration, INTEGRATION_NAME } from '@sentry/core';
2+
import { defineIntegration, OPENAI_INTEGRATION_NAME } from '@sentry/core';
33
import { generateInstrumentOnce } from '@sentry/node-core';
44
import { SentryOpenAiInstrumentation } from './instrumentation';
55

6-
export const instrumentOpenAi = generateInstrumentOnce(INTEGRATION_NAME, () => new SentryOpenAiInstrumentation({}));
6+
export const instrumentOpenAi = generateInstrumentOnce(
7+
OPENAI_INTEGRATION_NAME,
8+
() => new SentryOpenAiInstrumentation({}),
9+
);
710

811
const _openAiIntegration = ((options: OpenAiOptions = {}) => {
912
return {
10-
name: INTEGRATION_NAME,
13+
name: OPENAI_INTEGRATION_NAME,
1114
options,
1215
setupOnce() {
1316
instrumentOpenAi();

packages/node/src/integrations/tracing/openai/instrumentation.ts

Lines changed: 2 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import {
55
InstrumentationNodeModuleDefinition,
66
} from '@opentelemetry/instrumentation';
77
import type { Integration, OpenAiClient, OpenAiOptions } from '@sentry/core';
8-
import { getCurrentScope, instrumentOpenAiClient, INTEGRATION_NAME, SDK_VERSION } from '@sentry/core';
8+
import { getCurrentScope, instrumentOpenAiClient, OPENAI_INTEGRATION_NAME, SDK_VERSION } from '@sentry/core';
99

1010
const supportedVersions = ['>=4.0.0 <6'];
1111

@@ -37,9 +37,6 @@ function determineRecordingSettings(
3737
* Sentry OpenAI instrumentation using OpenTelemetry.
3838
*/
3939
export class SentryOpenAiInstrumentation extends InstrumentationBase<InstrumentationConfig> {
40-
private _isPatched = false;
41-
private _callbacks: Array<() => void> = [];
42-
4340
public constructor(config: InstrumentationConfig = {}) {
4441
super('@sentry/instrumentation-openai', SDK_VERSION, config);
4542
}
@@ -52,31 +49,16 @@ export class SentryOpenAiInstrumentation extends InstrumentationBase<Instrumenta
5249
return module;
5350
}
5451

55-
/**
56-
* Schedules a callback once patching is complete.
57-
*/
58-
public callWhenPatched(callback: () => void): void {
59-
if (this._isPatched) {
60-
callback();
61-
} else {
62-
this._callbacks.push(callback);
63-
}
64-
}
65-
6652
/**
6753
* Core patch logic applying instrumentation to the OpenAI client constructor.
6854
*/
6955
private _patch(exports: PatchedModuleExports): PatchedModuleExports | void {
70-
this._isPatched = true;
71-
this._callbacks.forEach(cb => cb());
72-
this._callbacks = [];
73-
7456
const Original = exports.OpenAI;
7557

7658
const WrappedOpenAI = function (this: unknown, ...args: unknown[]) {
7759
const instance = Reflect.construct(Original, args);
7860
const scopeClient = getCurrentScope().getClient();
79-
const integration = scopeClient?.getIntegrationByName<OpenAiIntegration>(INTEGRATION_NAME);
61+
const integration = scopeClient?.getIntegrationByName<OpenAiIntegration>(OPENAI_INTEGRATION_NAME);
8062
const integrationOpts = integration?.options;
8163
const defaultPii = Boolean(scopeClient?.getOptions().sendDefaultPii);
8264

0 commit comments

Comments
 (0)