Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {
GEN_AI_USAGE_OUTPUT_TOKENS,
GEN_AI_USAGE_TOTAL_TOKENS,
} from '@sentry/conventions/attributes';
import { GEN_AI_RESPONSE_STOP_REASON_ATTRIBUTE } from '../../../../../packages/core/src/tracing/ai/gen-ai-attributes';
import { GEN_AI_RESPONSE_STOP_REASON_ATTRIBUTE } from '../../../../../packages/server-utils/src/ai/core/gen-ai-attributes';
import { createRunner } from '../../../runner';

// This test runs the `@langchain/openai` model (backed by the
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { ChatAnthropic } from '@langchain/anthropic';
import { RunnableLambda, RunnableSequence } from '@langchain/core/runnables';
import { createLangChainCallbackHandler } from '@sentry/core';
import * as Sentry from '@sentry/node';
import express from 'express';

Expand Down Expand Up @@ -51,7 +50,7 @@ async function run() {

const chain = RunnableSequence.from([formatStep, model, parseStep]);

const handler = createLangChainCallbackHandler();
const handler = Sentry.createLangChainCallbackHandler();

await chain.invoke({ topic: 'weather' }, { callbacks: [handler] });
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import {
GEN_AI_EMBEDDINGS_OPERATION_ATTRIBUTE,
GEN_AI_REQUEST_DIMENSIONS_ATTRIBUTE,
GEN_AI_RESPONSE_STOP_REASON_ATTRIBUTE,
} from '../../../../../packages/core/src/tracing/ai/gen-ai-attributes';
} from '../../../../../packages/server-utils/src/ai/core/gen-ai-attributes';
import { getStringAttributeValue } from '../../../utils';
import { cleanupChildProcesses, createEsmAndCjsTests } from '../../../utils/runner';
import { createEsmTests } from '../../../utils/runner/createEsmAndCjsTests';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import {
GEN_AI_USAGE_OUTPUT_TOKENS,
GEN_AI_USAGE_TOTAL_TOKENS,
} from '@sentry/conventions/attributes';
import { GEN_AI_RESPONSE_STOP_REASON_ATTRIBUTE } from '../../../../../../packages/core/src/tracing/ai/gen-ai-attributes';
import { GEN_AI_RESPONSE_STOP_REASON_ATTRIBUTE } from '../../../../../../packages/server-utils/src/ai/core/gen-ai-attributes';
import { conditionalTest, getStringAttributeValue } from '../../../../utils';
import { cleanupChildProcesses, createEsmAndCjsTests } from '../../../../utils/runner';
import { createEsmTests } from '../../../../utils/runner/createEsmAndCjsTests';
Expand Down
8 changes: 4 additions & 4 deletions packages/cloudflare/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,16 +101,12 @@ export {
wrapMcpServerWithSentry,
consoleLoggingIntegration,
createConsolaReporter,
createLangChainCallbackHandler,
instrumentLangChainEmbeddings,
featureFlagsIntegration,
growthbookIntegration,
logger,
metrics,
withStreamedSpan,
spanStreamingIntegration,
instrumentStateGraph,
instrumentCreateReactAgent,
} from '@sentry/core';

export { withSentry } from './withSentry';
Expand All @@ -131,6 +127,10 @@ export {
instrumentAnthropicAiClient,
instrumentGoogleGenAIClient,
instrumentWorkersAiClient,
createLangChainCallbackHandler,
instrumentLangChainEmbeddings,
instrumentStateGraph,
instrumentCreateReactAgent,
} from '@sentry/server-utils';

// eslint-disable-next-line typescript/no-deprecated
Expand Down
6 changes: 0 additions & 6 deletions packages/core/.oxlintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,6 @@
"rules": {
"sdk/no-unsafe-random-apis": "off"
}
},
{
"files": ["src/tracing/langchain/utils.ts"],
"rules": {
"max-lines": "off"
}
}
],
"ignorePatterns": ["rollup.npm.config.mjs"]
Expand Down
14 changes: 0 additions & 14 deletions packages/core/src/server-exports.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,17 +60,3 @@ export { addVercelAiProcessors, getProviderMetadataAttributes } from './tracing/
export { getTruncatedJsonString, shouldEnableTruncation, resolveAIRecordingOptions } from './tracing/ai/utils';
export { _INTERNAL_getSpanContextForToolCallId, _INTERNAL_cleanupToolCallSpanContext } from './tracing/vercel-ai/utils';
export { toolCallSpanContextMap as _INTERNAL_toolCallSpanContextMap } from './tracing/vercel-ai/constants';
export { createLangChainCallbackHandler, instrumentLangChainEmbeddings } from './tracing/langchain';
export { _INTERNAL_getLangChainEmbeddingsSpanOptions } from './tracing/langchain/embeddings';
export { _INTERNAL_mergeLangChainCallbackHandler } from './tracing/langchain/utils';
export { LANGCHAIN_INTEGRATION_NAME } from './tracing/langchain/constants';
export type { LangChainOptions, LangChainIntegration } from './tracing/langchain/types';
export {
instrumentStateGraphCompile,
instrumentCreateReactAgent,
instrumentStateGraph,
instrumentCompiledGraphInvoke,
} from './tracing/langgraph';
export { wrapToolsWithSpans, extractLLMFromParams, extractAgentNameFromParams } from './tracing/langgraph/utils';
export { LANGGRAPH_INTEGRATION_NAME } from './tracing/langgraph/constants';
export type { LangGraphOptions, LangGraphIntegration, CompiledGraph } from './tracing/langgraph/types';
8 changes: 4 additions & 4 deletions packages/node/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ export {
instrumentOpenAiClient,
instrumentAnthropicAiClient,
instrumentGoogleGenAIClient,
createLangChainCallbackHandler,
instrumentLangChainEmbeddings,
instrumentStateGraph,
instrumentStateGraphCompile,
} from '@sentry/server-utils';
export { setupHapiErrorHandler } from './integrations/tracing/hapi';
export { setupKoaErrorHandler } from './integrations/tracing/koa';
Expand Down Expand Up @@ -145,10 +149,6 @@ export {
wrapMcpServerWithSentry,
featureFlagsIntegration,
spanStreamingIntegration,
createLangChainCallbackHandler,
instrumentLangChainEmbeddings,
instrumentStateGraph,
instrumentStateGraphCompile,
} from '@sentry/core';

export type {
Expand Down
2 changes: 2 additions & 0 deletions packages/server-utils/src/ai/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,5 @@ export { instrumentOpenAiClient } from './openai';
export { instrumentAnthropicAiClient } from './anthropic-ai';
export { instrumentGoogleGenAIClient } from './google-genai';
export { instrumentWorkersAiClient } from './workers-ai';
export { createLangChainCallbackHandler, instrumentLangChainEmbeddings } from './langchain';
export { instrumentStateGraph, instrumentStateGraphCompile, instrumentCreateReactAgent } from './langgraph';
Comment thread
nicohrubec marked this conversation as resolved.
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
/* eslint-disable typescript-eslint/no-deprecated */
import { captureException } from '../../exports';
import { SEMANTIC_ATTRIBUTE_SENTRY_OP, SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN } from '../../semanticAttributes';
import { startSpan } from '../../tracing/trace';
import type { SpanAttributeValue } from '../../types/span';
import {
captureException,
SEMANTIC_ATTRIBUTE_SENTRY_OP,
SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN,
startSpan,
} from '@sentry/core';
import type { SpanAttributeValue } from '@sentry/core';
import {
GEN_AI_EMBEDDINGS_INPUT,
GEN_AI_OPERATION_NAME,
Expand All @@ -13,8 +16,8 @@ import {
GEN_AI_EMBEDDINGS_OPERATION_ATTRIBUTE,
GEN_AI_REQUEST_DIMENSIONS_ATTRIBUTE,
GEN_AI_REQUEST_ENCODING_FORMAT_ATTRIBUTE,
} from '../ai/gen-ai-attributes';
import { resolveAIRecordingOptions } from '../ai/utils';
} from '../core/gen-ai-attributes';
import { resolveAIRecordingOptions } from '../core/utils';
import { LANGCHAIN_ORIGIN } from './constants';
import type { LangChainOptions } from './types';

Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
/* eslint-disable typescript-eslint/no-deprecated */
/* eslint-disable max-lines */
import { captureException } from '../../exports';
import { SEMANTIC_ATTRIBUTE_SENTRY_OP, SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN } from '../../semanticAttributes';
import { SPAN_STATUS_ERROR } from '../../tracing';
import { startSpanManual } from '../../tracing/trace';
import type { Span, SpanAttributeValue } from '../../types/span';
import {
captureException,
SEMANTIC_ATTRIBUTE_SENTRY_OP,
SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN,
SPAN_STATUS_ERROR,
startSpanManual,
} from '@sentry/core';
import type { Span, SpanAttributeValue } from '@sentry/core';
import {
GEN_AI_OPERATION_NAME,
GEN_AI_REQUEST_AVAILABLE_TOOLS,
Expand All @@ -13,7 +16,7 @@ import {
GEN_AI_TOOL_NAME,
GEN_AI_TOOL_OUTPUT,
} from '@sentry/conventions/attributes';
import { resolveAIRecordingOptions, shouldEnableTruncation } from '../ai/utils';
import { resolveAIRecordingOptions, shouldEnableTruncation } from '../core/utils';
import { LANGCHAIN_ORIGIN } from './constants';
import type {
LangChainCallbackHandler,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* eslint-disable max-lines */

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why now?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not sure

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah there was an override in core for this file (removed it now)

/* eslint-disable typescript-eslint/no-deprecated */
import { SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN } from '../../semanticAttributes';
import type { SpanAttributeValue } from '../../types/span';
import { stringify } from '../../utils/string';
import { SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN, stringify } from '@sentry/core';
import type { SpanAttributeValue } from '@sentry/core';
import {
GEN_AI_AGENT_NAME,
GEN_AI_INPUT_MESSAGES,
Expand All @@ -25,9 +25,9 @@ import {
GEN_AI_USAGE_OUTPUT_TOKENS,
GEN_AI_USAGE_TOTAL_TOKENS,
} from '@sentry/conventions/attributes';
import { GEN_AI_REQUEST_STREAM_ATTRIBUTE, GEN_AI_RESPONSE_STOP_REASON_ATTRIBUTE } from '../ai/gen-ai-attributes';
import { isContentMedia, stripInlineMediaFromSingleMessage } from '../ai/mediaStripping';
import { extractSystemInstructions, getTruncatedJsonString } from '../ai/utils';
import { GEN_AI_REQUEST_STREAM_ATTRIBUTE, GEN_AI_RESPONSE_STOP_REASON_ATTRIBUTE } from '../core/gen-ai-attributes';
import { isContentMedia, stripInlineMediaFromSingleMessage } from '../core/mediaStripping';
import { extractSystemInstructions, getTruncatedJsonString } from '../core/utils';
import { LANGCHAIN_ORIGIN, ROLE_MAP } from './constants';
import type { LangChainLLMResult, LangChainMessage, LangChainSerialized } from './types';

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
/* eslint-disable typescript-eslint/no-deprecated */
import { captureException } from '../../exports';
import { SEMANTIC_ATTRIBUTE_SENTRY_OP, SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN } from '../../semanticAttributes';
import { SPAN_STATUS_ERROR } from '../../tracing';
import {
captureException,
SEMANTIC_ATTRIBUTE_SENTRY_OP,
SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN,
SPAN_STATUS_ERROR,
startSpan,
stringify,
} from '@sentry/core';
import {
GEN_AI_AGENT_NAME,
GEN_AI_CONVERSATION_ID,
Expand All @@ -12,18 +17,16 @@ import {
GEN_AI_REQUEST_MODEL,
GEN_AI_SYSTEM_INSTRUCTIONS,
} from '@sentry/conventions/attributes';
import { GEN_AI_INVOKE_AGENT_OPERATION_ATTRIBUTE } from '../ai/gen-ai-attributes';
import { GEN_AI_INVOKE_AGENT_OPERATION_ATTRIBUTE } from '../core/gen-ai-attributes';
import {
extractSystemInstructions,
getTruncatedJsonString,
resolveAIRecordingOptions,
shouldEnableTruncation,
} from '../ai/utils';
import { stringify } from '../../utils/string';
} from '../core/utils';
import { createLangChainCallbackHandler } from '../langchain';
import type { BaseChatModel, LangChainMessage } from '../langchain/types';
import { normalizeLangChainMessages } from '../langchain/utils';
import { startSpan } from '../trace';
import { LANGGRAPH_ORIGIN } from './constants';
import type { CompiledGraph, LangGraphOptions } from './types';
import {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
/* eslint-disable typescript-eslint/no-deprecated */
import { captureException } from '../../exports';
import { SEMANTIC_ATTRIBUTE_SENTRY_OP, SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN } from '../../semanticAttributes';
import { SPAN_STATUS_ERROR } from '../../tracing';
import type { Span, SpanAttributes } from '../../types/span';
import {
captureException,
SEMANTIC_ATTRIBUTE_SENTRY_OP,
SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN,
SPAN_STATUS_ERROR,
startSpan,
} from '@sentry/core';
import type { Span, SpanAttributes } from '@sentry/core';
import {
GEN_AI_AGENT_NAME,
GEN_AI_OPERATION_NAME,
Expand All @@ -19,10 +23,9 @@ import {
GEN_AI_USAGE_OUTPUT_TOKENS,
GEN_AI_USAGE_TOTAL_TOKENS,
} from '@sentry/conventions/attributes';
import { GEN_AI_EXECUTE_TOOL_OPERATION_ATTRIBUTE, GEN_AI_TOOL_CALL_ID_ATTRIBUTE } from '../ai/gen-ai-attributes';
import { GEN_AI_EXECUTE_TOOL_OPERATION_ATTRIBUTE, GEN_AI_TOOL_CALL_ID_ATTRIBUTE } from '../core/gen-ai-attributes';
import type { BaseChatModel, LangChainMessage } from '../langchain/types';
import { normalizeLangChainMessages } from '../langchain/utils';
import { startSpan } from '../trace';
import { LANGGRAPH_ORIGIN } from './constants';
import type { CompiledGraph, LangGraphOptions, LangGraphTool } from './types';

Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,13 @@
import * as diagnosticsChannel from 'node:diagnostics_channel';
import type { IntegrationFn, LangChainOptions, Span } from '@sentry/core';
import {
_INTERNAL_getLangChainEmbeddingsSpanOptions,
_INTERNAL_mergeLangChainCallbackHandler,
_INTERNAL_skipAiProviderWrapping,
createLangChainCallbackHandler,
defineIntegration,
LANGCHAIN_INTEGRATION_NAME,
startInactiveSpan,
} from '@sentry/core';
import type { IntegrationFn, Span } from '@sentry/core';
import { _INTERNAL_skipAiProviderWrapping, defineIntegration, startInactiveSpan } from '@sentry/core';
import { ANTHROPIC_AI_INTEGRATION_NAME } from '../../ai/anthropic-ai/constants';
import { GOOGLE_GENAI_INTEGRATION_NAME } from '../../ai/google-genai/constants';
import { createLangChainCallbackHandler } from '../../ai/langchain';
import { LANGCHAIN_INTEGRATION_NAME } from '../../ai/langchain/constants';
import { _INTERNAL_getLangChainEmbeddingsSpanOptions } from '../../ai/langchain/embeddings';
import type { LangChainOptions } from '../../ai/langchain/types';
import { _INTERNAL_mergeLangChainCallbackHandler } from '../../ai/langchain/utils';
import { OPENAI_INTEGRATION_NAME } from '../../ai/openai/constants';
import { CHANNELS } from '../../orchestrion/channels';
import { langchainEmbeddingsChannels } from '../../orchestrion/config/langchain';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,12 @@
import * as diagnosticsChannel from 'node:diagnostics_channel';
import type { CompiledGraph, IntegrationFn, LangGraphOptions } from '@sentry/core';
import {
createLangChainCallbackHandler,
debug,
defineIntegration,
extractAgentNameFromParams,
extractLLMFromParams,
instrumentCompiledGraphInvoke,
LANGGRAPH_INTEGRATION_NAME,
resolveAIRecordingOptions,
wrapToolsWithSpans,
} from '@sentry/core';
import type { IntegrationFn } from '@sentry/core';
import { debug, defineIntegration } from '@sentry/core';
import { resolveAIRecordingOptions } from '../../ai/core/utils';
import { createLangChainCallbackHandler } from '../../ai/langchain';
import { instrumentCompiledGraphInvoke } from '../../ai/langgraph';
import { LANGGRAPH_INTEGRATION_NAME } from '../../ai/langgraph/constants';
import type { CompiledGraph, LangGraphOptions } from '../../ai/langgraph/types';
import { extractAgentNameFromParams, extractLLMFromParams, wrapToolsWithSpans } from '../../ai/langgraph/utils';
import { DEBUG_BUILD } from '../../debug-build';
import { CHANNELS } from '../../orchestrion/channels';
import { langgraphModuleNames } from '../../orchestrion/config/langgraph';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import { beforeEach, describe, expect, it, vi } from 'vitest';
import type * as AiCoreUtils from '../../../../src/ai/core/utils';
import type * as SentryCore from '@sentry/core';
import {
GEN_AI_EMBEDDINGS_INPUT,
GEN_AI_OPERATION_NAME,
Expand All @@ -9,33 +11,38 @@ import {
GEN_AI_EMBEDDINGS_OPERATION_ATTRIBUTE,
GEN_AI_REQUEST_DIMENSIONS_ATTRIBUTE,
GEN_AI_REQUEST_ENCODING_FORMAT_ATTRIBUTE,
} from '../../../src/tracing/ai/gen-ai-attributes';
import { instrumentEmbeddingMethod, instrumentLangChainEmbeddings } from '../../../src/tracing/langchain/embeddings';

vi.mock('../../../src/tracing/ai/utils', () => ({
resolveAIRecordingOptions: (options: { recordInputs?: boolean; recordOutputs?: boolean } = {}) => ({
recordInputs: options.recordInputs ?? false,
recordOutputs: options.recordOutputs ?? false,
}),
}));
} from '../../../../src/ai/core/gen-ai-attributes';
import { instrumentEmbeddingMethod, instrumentLangChainEmbeddings } from '../../../../src/ai/langchain/embeddings';

vi.mock('../../../../src/ai/core/utils', async importOriginal => {
const actual = (await importOriginal()) as typeof AiCoreUtils;
return {
...actual,
resolveAIRecordingOptions: (options: { recordInputs?: boolean; recordOutputs?: boolean } = {}) => ({
recordInputs: options.recordInputs ?? false,
recordOutputs: options.recordOutputs ?? false,
}),
};
});

let capturedSpanConfig: { name: string; op: string; attributes: Record<string, unknown> } | undefined;

vi.mock('../../../src/tracing/trace', () => ({
startSpan: (
config: { name: string; op: string; attributes: Record<string, unknown> },
callback: (span: unknown) => unknown,
) => {
capturedSpanConfig = config;
return callback({ setAttribute: vi.fn() });
},
}));

import { captureException } from '../../../src/exports';

vi.mock('../../../src/exports', () => ({
captureException: vi.fn(),
}));
vi.mock('@sentry/core', async importOriginal => {
const actual = (await importOriginal()) as typeof SentryCore;
return {
...actual,
startSpan: (
config: { name: string; op: string; attributes: Record<string, unknown> },
callback: (span: unknown) => unknown,
) => {
capturedSpanConfig = config;
return callback({ setAttribute: vi.fn() });
},
captureException: vi.fn(),
};
});

import { captureException } from '@sentry/core';

describe('instrumentEmbeddingMethod', () => {
beforeEach(() => {
Expand Down
Loading
Loading