Skip to content

Commit b0b1858

Browse files
nicohrubeccodex
andcommitted
ref(server-utils): Clarify API promise helper naming and references
Co-Authored-By: GPT-6 <codex@openai.com>
1 parent a0faac6 commit b0b1858

4 files changed

Lines changed: 9 additions & 8 deletions

File tree

‎packages/server-utils/src/ai/core/apiPromise.ts‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,9 @@ function isApiPromise(value: unknown): value is ApiPromise {
1313
// OpenAI and Anthropic return an APIPromise that extends the native promise objects and redefines .then() in a way that internally triggers body parsing.
1414
// This can lead to double parsing if our instrumentation triggers .then on this promise.
1515
// Instead, we need to avoid triggering .then on the APIPromise and instead observe the internal parsing process to get the response body.
16-
// APIPromise implementation: https://github.com/openai/openai-node/blob/main/src/core/api-promise.ts
17-
export function onApiPromiseResponse(
16+
// OpenAI APIPromise: https://github.com/openai/openai-node/blob/71d24120c4cc4e5897a767f16d25f2804fa4ad7c/src/core/api-promise.ts
17+
// Anthropic APIPromise: https://github.com/anthropics/anthropic-sdk-typescript/blob/d49bdab458000bcdffe77bd84b03293f31824fb3/src/core/api-promise.ts
18+
export function wrapApiPromiseResponse(
1819
result: unknown,
1920
onResponse: (response: unknown) => void,
2021
onError: (error: unknown) => void,

‎packages/server-utils/src/integrations/anthropic.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import {
1010
startInactiveSpan,
1111
} from '@sentry/core';
1212
import { getGenAiSpanOp, resolveAIRecordingOptions } from '../ai/core/utils';
13-
import { onApiPromiseResponse } from '../ai/core/apiPromise';
13+
import { wrapApiPromiseResponse } from '../ai/core/apiPromise';
1414
import { addPrivateRequestAttributes, addResponseAttributes, extractRequestAttributes } from '../ai/anthropic-ai';
1515
import { instrumentAsyncIterableStream, instrumentMessageStream } from '../ai/anthropic-ai/streaming';
1616
import type { AnthropicAiOptions, AnthropicAiResponse } from '../ai/anthropic-ai/types';
@@ -65,7 +65,7 @@ function instrumentAnthropic(options: AnthropicAiOptions): void {
6565
);
6666
},
6767
deferSpanEnd: ({ span, data, end }) =>
68-
onApiPromiseResponse(
68+
wrapApiPromiseResponse(
6969
data.result,
7070
response => {
7171
data.result = response;

‎packages/server-utils/src/integrations/openai-compatible.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import {
99
} from '@sentry/core';
1010
import { GEN_AI_PROVIDER_NAME } from '@sentry/conventions/attributes';
1111
import { getGenAiSpanOp, resolveAIRecordingOptions } from '../ai/core/utils';
12-
import { onApiPromiseResponse } from '../ai/core/apiPromise';
12+
import { wrapApiPromiseResponse } from '../ai/core/apiPromise';
1313
import { addRequestAttributes, extractRequestAttributes } from '../ai/openai';
1414
import { instrumentStream } from '../ai/openai/streaming';
1515
import type { OpenAiOptions } from '../ai/openai/types';
@@ -68,7 +68,7 @@ export function createOpenAiCompatibleIntegration<T extends OpenAiCompatibleProv
6868
addResponseAttributes(span, data.result, resolveAIRecordingOptions(options).recordOutputs);
6969
},
7070
deferSpanEnd: ({ span, data, end }) =>
71-
onApiPromiseResponse(
71+
wrapApiPromiseResponse(
7272
data.result,
7373
response => {
7474
data.result = response;

‎packages/server-utils/src/integrations/openai.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import {
1010
} from '@sentry/core';
1111
import { getGenAiSpanOp, resolveAIRecordingOptions } from '../ai/core/utils';
1212
import { addRequestAttributes, extractRequestAttributes } from '../ai/openai';
13-
import { onApiPromiseResponse } from '../ai/core/apiPromise';
13+
import { wrapApiPromiseResponse } from '../ai/core/apiPromise';
1414
import { instrumentStream } from '../ai/openai/streaming';
1515
import type { OpenAiOptions } from '../ai/openai/types';
1616
import { addResponseAttributes } from '../ai/openai/utils';
@@ -60,7 +60,7 @@ function instrumentOpenai(options: OpenAiOptions): void {
6060
addResponseAttributes(span, data.result, resolveAIRecordingOptions(options).recordOutputs);
6161
},
6262
deferSpanEnd: ({ span, data, end }) =>
63-
onApiPromiseResponse(
63+
wrapApiPromiseResponse(
6464
data.result,
6565
response => {
6666
data.result = response;

0 commit comments

Comments
 (0)