Skip to content

Commit 7df24cd

Browse files
committed
Use shouldEnableTruncation in Anthropic AI integration
1 parent 68c20be commit 7df24cd

File tree

1 file changed

+4
-11
lines changed
  • packages/core/src/tracing/anthropic-ai

1 file changed

+4
-11
lines changed

packages/core/src/tracing/anthropic-ai/index.ts

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
1-
import { getClient } from '../../currentScopes';
21
import { captureException } from '../../exports';
32
import { SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN } from '../../semanticAttributes';
43
import { SPAN_STATUS_ERROR } from '../../tracing';
5-
import { hasSpanStreamingEnabled } from '../../tracing/spans/hasSpanStreamingEnabled';
64
import { startSpan, startSpanManual } from '../../tracing/trace';
75
import type { Span, SpanAttributeValue } from '../../types-hoist/span';
86
import {
@@ -27,6 +25,7 @@ import {
2725
buildMethodPath,
2826
resolveAIRecordingOptions,
2927
setTokenUsageAttributes,
28+
shouldEnableTruncation,
3029
wrapPromiseWithMethods,
3130
} from '../ai/utils';
3231
import { ANTHROPIC_METHOD_REGISTRY } from './constants';
@@ -208,9 +207,7 @@ function handleStreamingRequest<T extends unknown[], R>(
208207
originalResult = originalMethod.apply(context, args) as Promise<R>;
209208

210209
if (options.recordInputs && params) {
211-
const client = getClient();
212-
const enableTruncation = options.enableTruncation ?? !(client && hasSpanStreamingEnabled(client));
213-
addPrivateRequestAttributes(span, params, enableTruncation);
210+
addPrivateRequestAttributes(span, params, shouldEnableTruncation(options.enableTruncation));
214211
}
215212

216213
return (async () => {
@@ -232,9 +229,7 @@ function handleStreamingRequest<T extends unknown[], R>(
232229
return startSpanManual(spanConfig, span => {
233230
try {
234231
if (options.recordInputs && params) {
235-
const client = getClient();
236-
const enableTruncation = options.enableTruncation ?? !(client && hasSpanStreamingEnabled(client));
237-
addPrivateRequestAttributes(span, params, enableTruncation);
232+
addPrivateRequestAttributes(span, params, shouldEnableTruncation(options.enableTruncation));
238233
}
239234
const messageStream = target.apply(context, args);
240235
return instrumentMessageStream(messageStream, span, options.recordOutputs ?? false);
@@ -295,9 +290,7 @@ function instrumentMethod<T extends unknown[], R>(
295290
originalResult = target.apply(context, args) as Promise<R>;
296291

297292
if (options.recordInputs && params) {
298-
const client = getClient();
299-
const enableTruncation = options.enableTruncation ?? !(client && hasSpanStreamingEnabled(client));
300-
addPrivateRequestAttributes(span, params, enableTruncation);
293+
addPrivateRequestAttributes(span, params, shouldEnableTruncation(options.enableTruncation));
301294
}
302295

303296
return originalResult.then(

0 commit comments

Comments
 (0)