Skip to content

Commit 065a994

Browse files
committed
fix truncation, revert some comments
1 parent b6b4a0c commit 065a994

File tree

3 files changed

+27
-20
lines changed

3 files changed

+27
-20
lines changed

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

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ import type {
3434
AnthropicAiStreamingEvent,
3535
ContentBlock,
3636
} from './types';
37-
import { shouldInstrument } from './utils';
37+
import { handleResponseError, shouldInstrument } from './utils';
3838

3939
/**
4040
* Extract request attributes from method arguments
@@ -96,23 +96,6 @@ function addPrivateRequestAttributes(span: Span, params: Record<string, unknown>
9696
}
9797
}
9898

99-
/**
100-
* Capture error information from the response
101-
* @see https://docs.anthropic.com/en/api/errors#error-shapes
102-
*/
103-
function handleResponseError(span: Span, response: AnthropicAiResponse): void {
104-
if (response.error) {
105-
span.setStatus({ code: SPAN_STATUS_ERROR, message: response.error.type || 'unknown_error' });
106-
107-
captureException(response.error, {
108-
mechanism: {
109-
handled: false,
110-
type: 'auto.ai.anthropic.anthropic_error',
111-
},
112-
});
113-
}
114-
}
115-
11699
/**
117100
* Add content attributes when recordOutputs is enabled
118101
*/
Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,28 @@
1+
import type { Span} from '../..';
2+
import { captureException, SPAN_STATUS_ERROR } from '../..';
13
import { ANTHROPIC_AI_INSTRUMENTED_METHODS } from './constants';
2-
import type { AnthropicAiInstrumentedMethod } from './types';
4+
import type { AnthropicAiInstrumentedMethod, AnthropicAiResponse } from './types';
35

46
/**
57
* Check if a method path should be instrumented
68
*/
79
export function shouldInstrument(methodPath: string): methodPath is AnthropicAiInstrumentedMethod {
810
return ANTHROPIC_AI_INSTRUMENTED_METHODS.includes(methodPath as AnthropicAiInstrumentedMethod);
911
}
12+
13+
/**
14+
* Capture error information from the response
15+
* @see https://docs.anthropic.com/en/api/errors#error-shapes
16+
*/
17+
export function handleResponseError(span: Span, response: AnthropicAiResponse): void {
18+
if (response.error) {
19+
span.setStatus({ code: SPAN_STATUS_ERROR, message: response.error.type || 'unknown_error' });
20+
21+
captureException(response.error, {
22+
mechanism: {
23+
handled: false,
24+
type: 'auto.ai.anthropic.anthropic_error',
25+
},
26+
});
27+
}
28+
}

packages/core/src/utils/google-genai/index.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,10 +128,15 @@ function extractRequestAttributes(
128128

129129
return attributes;
130130
}
131-
131+
/**
132+
* Add private request attributes to spans.
133+
* This is only recorded if recordInputs is true.
134+
* Handles different parameter formats for different Google GenAI methods.
135+
*/
132136
function addPrivateRequestAttributes(span: Span, params: Record<string, unknown>): void {
133137
if ('contents' in params) {
134138
const contents = params.contents;
139+
// For models.generateContent: ContentListUnion: Content | Content[] | PartUnion | PartUnion[]
135140
if (Array.isArray(contents)) {
136141
const truncatedContents = truncateGenAiMessages(contents);
137142
span.setAttributes({ [GEN_AI_REQUEST_MESSAGES_ATTRIBUTE]: JSON.stringify(truncatedContents) });

0 commit comments

Comments
 (0)