Add Sentry AI agent monitoring with telemetry configuration (#15301)

This PR implements Sentry's AI agent monitoring by:

- Configuring vercelAIIntegration with recordInputs and recordOutputs
options
- Adding sendDefaultPii to Sentry.init() for better debugging
- Creating a shared AI_TELEMETRY_CONFIG constant to DRY up the telemetry
configuration
- Adding experimental_telemetry to all AI SDK calls (generateText,
generateObject, streamText)

All AI operations are now fully monitored in Sentry with complete
input/output recording for debugging and performance analysis.

Note: Currently on Sentry v9.26.0, which is compatible with this
implementation. No breaking changes from the v9-to-v10 migration guide
were found in the codebase.
This commit is contained in:
Félix Malfait
2025-10-23 18:06:28 +02:00
committed by GitHub
parent 7edfe4bc7a
commit bbe16c23bc
10 changed files with 552 additions and 403 deletions
@@ -4,6 +4,7 @@ import { InjectRepository } from '@nestjs/typeorm';
import { generateObject, generateText, stepCountIs, ToolSet } from 'ai';
import { Repository } from 'typeorm';
import { AI_TELEMETRY_CONFIG } from 'src/engine/core-modules/ai/constants/ai-telemetry.const';
import { AiModelRegistryService } from 'src/engine/core-modules/ai/services/ai-model-registry.service';
import { ToolAdapterService } from 'src/engine/core-modules/ai/services/tool-adapter.service';
import { ToolService } from 'src/engine/core-modules/ai/services/tool.service';
@@ -117,6 +118,7 @@ export class AiAgentExecutorService {
model: registeredModel.model,
prompt: userPrompt,
stopWhen: stepCountIs(AGENT_CONFIG.MAX_STEPS),
experimental_telemetry: AI_TELEMETRY_CONFIG,
});
if (Object.keys(schema).length === 0) {
@@ -134,6 +136,7 @@ export class AiAgentExecutorService {
Please generate the structured output based on the execution results and context above.`,
schema: convertOutputSchemaToZod(schema),
experimental_telemetry: AI_TELEMETRY_CONFIG,
});
return {