1- import { getClient } from '../../currentScopes' ;
21import { captureException } from '../../exports' ;
32import { SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN } from '../../semanticAttributes' ;
43import { SPAN_STATUS_ERROR } from '../../tracing' ;
5- import { hasSpanStreamingEnabled } from '../../tracing/spans/hasSpanStreamingEnabled' ;
64import { startSpan , startSpanManual } from '../../tracing/trace' ;
75import type { Span , SpanAttributeValue } from '../../types-hoist/span' ;
86import {
@@ -27,6 +25,7 @@ import {
2725 buildMethodPath ,
2826 resolveAIRecordingOptions ,
2927 setTokenUsageAttributes ,
28+ shouldEnableTruncation ,
3029 wrapPromiseWithMethods ,
3130} from '../ai/utils' ;
3231import { 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