Skip to content

Commit e9d9f51

Browse files
committed
Move stuff to sub folder, update with small refactor
1 parent db18c0a commit e9d9f51

File tree

7 files changed

+19
-17
lines changed

7 files changed

+19
-17
lines changed

packages/core/src/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -125,8 +125,8 @@ 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';
129-
export type { OpenAiClient, OpenAiOptions, InstrumentedMethod } from './utils/openai-types';
128+
export { INTEGRATION_NAME } from './utils/openai/constants';
129+
export type { OpenAiClient, OpenAiOptions, InstrumentedMethod } from './utils/openai/types';
130130
export type { FeatureFlag } from './utils/featureFlags';
131131
export {
132132
_INTERNAL_copyFlagsFromScopeToEvent,

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

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
import { getCurrentScope } from '../currentScopes';
2-
import { captureException } from '../exports';
3-
import { startSpan } from '../tracing/trace';
4-
import type { Span, SpanAttributeValue } from '../types-hoist/span';
1+
import { getCurrentScope } from '../../currentScopes';
2+
import { captureException } from '../../exports';
3+
import { startSpan } from '../../tracing/trace';
4+
import type { Span, SpanAttributeValue } from '../../types-hoist/span';
55
import {
66
GEN_AI_OPERATION_NAME_ATTRIBUTE,
77
GEN_AI_REQUEST_FREQUENCY_PENALTY_ATTRIBUTE,
@@ -23,8 +23,8 @@ import {
2323
OPENAI_RESPONSE_TIMESTAMP_ATTRIBUTE,
2424
OPENAI_USAGE_COMPLETION_TOKENS_ATTRIBUTE,
2525
OPENAI_USAGE_PROMPT_TOKENS_ATTRIBUTE,
26-
} from './gen-ai-attributes';
27-
import { INTEGRATION_NAME } from './openai-constants';
26+
} from '../gen-ai-attributes';
27+
import { INTEGRATION_NAME } from './constants';
2828
import type {
2929
InstrumentedMethod,
3030
OpenAiChatCompletionObject,
@@ -33,15 +33,15 @@ import type {
3333
OpenAiOptions,
3434
OpenAiResponse,
3535
OpenAIResponseObject,
36-
} from './openai-types';
36+
} from './types';
3737
import {
3838
buildMethodPath,
3939
getOperationName,
4040
getSpanOperation,
4141
isChatCompletionResponse,
4242
isResponsesApiResponse,
4343
shouldInstrument,
44-
} from './openai-utils';
44+
} from './utils';
4545

4646
/**
4747
* Extract request attributes from method arguments

packages/core/src/utils/openai-types.ts renamed to packages/core/src/utils/openai/types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { INSTRUMENTED_METHODS } from './openai-constants';
1+
import type { INSTRUMENTED_METHODS } from './constants';
22

33
/**
44
* Attribute values may be any non-nullish primitive value except an object.

packages/core/src/utils/openai-utils.ts renamed to packages/core/src/utils/openai/utils.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import { OPENAI_OPERATIONS } from './gen-ai-attributes';
2-
import { INSTRUMENTED_METHODS } from './openai-constants';
3-
import type { InstrumentedMethod, OpenAiChatCompletionObject, OpenAIResponseObject } from './openai-types';
1+
import { OPENAI_OPERATIONS } from '../gen-ai-attributes';
2+
import { INSTRUMENTED_METHODS } from './constants';
3+
import type { InstrumentedMethod, OpenAiChatCompletionObject, OpenAIResponseObject } from './types';
44

55
/**
66
* Maps OpenAI method paths to Sentry operation names

packages/core/test/lib/utils/openai-utils.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import {
66
isChatCompletionResponse,
77
isResponsesApiResponse,
88
shouldInstrument,
9-
} from '../../../src/utils/openai-utils';
9+
} from '../../../src/utils/openai/utils';
1010

1111
describe('openai-utils', () => {
1212
describe('getOperationName', () => {

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ import {
77
import type { Integration, OpenAiClient, OpenAiOptions } from '@sentry/core';
88
import { getCurrentScope, instrumentOpenAiClient, INTEGRATION_NAME, SDK_VERSION } from '@sentry/core';
99

10+
const supportedVersions = ['>=4.0.0 <6'];
11+
1012
export interface OpenAiIntegration extends Integration {
1113
options: OpenAiOptions;
1214
}
@@ -46,7 +48,7 @@ export class SentryOpenAiInstrumentation extends InstrumentationBase<Instrumenta
4648
* Initializes the instrumentation by defining the modules to be patched.
4749
*/
4850
public init(): InstrumentationModuleDefinition {
49-
const module = new InstrumentationNodeModuleDefinition('openai', ['>=4.0.0'], this._patch.bind(this));
51+
const module = new InstrumentationNodeModuleDefinition('openai', supportedVersions, this._patch.bind(this));
5052
return module;
5153
}
5254

@@ -76,7 +78,7 @@ export class SentryOpenAiInstrumentation extends InstrumentationBase<Instrumenta
7678
const scopeClient = getCurrentScope().getClient();
7779
const integration = scopeClient?.getIntegrationByName<OpenAiIntegration>(INTEGRATION_NAME);
7880
const integrationOpts = integration?.options;
79-
const defaultPii = integration ? Boolean(scopeClient?.getOptions().sendDefaultPii) : false;
81+
const defaultPii = Boolean(scopeClient?.getOptions().sendDefaultPii);
8082

8183
const { recordInputs, recordOutputs } = determineRecordingSettings(integrationOpts, defaultPii);
8284

0 commit comments

Comments
 (0)