|
1 | | -import { getClient } from '../../currentScopes'; |
2 | 1 | import { captureException } from '../../exports'; |
3 | 2 | import { SEMANTIC_ATTRIBUTE_SENTRY_OP, SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN } from '../../semanticAttributes'; |
4 | 3 | import { SPAN_STATUS_ERROR } from '../../tracing'; |
@@ -41,26 +40,16 @@ import { extractToolsFromCompiledGraph, setResponseAttributes } from './utils'; |
41 | 40 | * const compiled = graph.compile({ name: 'my_agent' }); |
42 | 41 | * ``` |
43 | 42 | */ |
44 | | -export function instrumentLangGraph( |
45 | | - stateGraph: { compile?: (...args: unknown[]) => CompiledGraph }, |
46 | | - options: LangGraphOptions = {}, |
47 | | -): void { |
48 | | - const client = getClient(); |
49 | | - const clientOptions = client?.getOptions(); |
50 | | - const defaultPii = Boolean(clientOptions?.sendDefaultPii); |
| 43 | +// eslint-disable-next-line @typescript-eslint/no-explicit-any |
| 44 | +export function instrumentLangGraph<T extends { compile: (...args: any[]) => any }>( |
| 45 | + stateGraph: T, |
| 46 | + options?: LangGraphOptions, |
| 47 | +): T { |
| 48 | + const _options: LangGraphOptions = options || {}; |
51 | 49 |
|
52 | | - const recordInputs = options.recordInputs ?? defaultPii; |
53 | | - const recordOutputs = options.recordOutputs ?? defaultPii; |
| 50 | + stateGraph.compile = instrumentStateGraphCompile(stateGraph.compile.bind(stateGraph), _options); |
54 | 51 |
|
55 | | - const instrumentationOptions: LangGraphOptions = { |
56 | | - recordInputs, |
57 | | - recordOutputs, |
58 | | - }; |
59 | | - |
60 | | - if (stateGraph.compile && typeof stateGraph.compile === 'function') { |
61 | | - const originalCompile = stateGraph.compile; |
62 | | - stateGraph.compile = instrumentStateGraphCompile(originalCompile, instrumentationOptions); |
63 | | - } |
| 52 | + return stateGraph; |
64 | 53 | } |
65 | 54 |
|
66 | 55 | /** |
|
0 commit comments