-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Expand file tree
/
Copy pathutils.ts
More file actions
29 lines (26 loc) · 1.02 KB
/
utils.ts
File metadata and controls
29 lines (26 loc) · 1.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
import { captureException } from '../../exports';
import { SPAN_STATUS_ERROR } from '../../tracing';
import type { Span } from '../../types-hoist/span';
import { ANTHROPIC_AI_INSTRUMENTED_METHODS } from './constants';
import type { AnthropicAiInstrumentedMethod, AnthropicAiResponse } from './types';
/**
* Check if a method path should be instrumented
*/
export function shouldInstrument(methodPath: string): methodPath is AnthropicAiInstrumentedMethod {
return ANTHROPIC_AI_INSTRUMENTED_METHODS.includes(methodPath as AnthropicAiInstrumentedMethod);
}
/**
* Capture error information from the response
* @see https://docs.anthropic.com/en/api/errors#error-shapes
*/
export function handleResponseError(span: Span, response: AnthropicAiResponse): void {
if (response.error) {
span.setStatus({ code: SPAN_STATUS_ERROR, message: response.error.type || 'internal_error' });
captureException(response.error, {
mechanism: {
handled: false,
type: 'auto.ai.anthropic.anthropic_error',
},
});
}
}