UNPKG

@sentry/node

Version:

Sentry Node SDK using OpenTelemetry for performance instrumentation

55 lines (54 loc) • 2.35 kB
import { init } from "./sdk/index.js"; import { setConversationId } from "@sentry/core"; import { eveIntegration, eveTracePolicy } from "@sentry/server-utils"; // src/eve.ts /** * All-in-one Sentry setup for an [eve](https://eve.dev) agent, wired into a single * `agent/instrumentation/*.ts` provider file. * * @example * ```ts * // agent/instrumentation/sentry.ts * import * as Sentry from '@sentry/node'; * import { defineInstrumentation } from 'eve/instrumentation'; * * export default defineInstrumentation(Sentry.eveInstrumentation({ dsn: '__DSN__' })); * ``` * * It: * - runs `Sentry.init` with the given options at server startup (`setup`), adding {@link eveIntegration}; * - asks eve for full gen_ai results ({@link eveTracePolicy}); Sentry filters content by `dataCollection.genAI` * when it builds spans. On eve >= 1.0.0-rc.10 this also sets the AI SDK's `recordInputs`/`recordOutputs` flags, * which apply to every AI SDK telemetry integration in the app; * - tags each turn's AI spans with a Sentry conversation id via `turn.started` and `step.attempt.started` * (eve < 0.84) / `model.started` (eve >= 0.84) events — the instrumentation-provider equivalent of `eveConversationHook`. Provider event handlers * receive the session id on the event (`event.sessionId` / `event.scope.sessionId`), unlike hook * handlers, which read it from their context. */ function eveInstrumentation(options = {}) { const { getConversationId, ...initOptions } = options; const setConversationIdFromSession = (sessionId) => { setConversationId(getConversationId ? getConversationId({ session: { id: sessionId } }) : sessionId); }; return { setup() { init({ ...initOptions, integrations: withEveIntegration(initOptions.integrations) }); }, tracePolicy: eveTracePolicy, events: { "turn.started": (event) => setConversationIdFromSession(event.sessionId), "step.attempt.started": (event) => setConversationIdFromSession(event.scope.sessionId), "model.started": (event) => setConversationIdFromSession(event.scope.sessionId) } }; } function withEveIntegration(integrations) { const eve = eveIntegration(); if (typeof integrations === "function") return (defaults) => [...integrations(defaults), eve]; return [...integrations ?? [], eve]; } export { eveInstrumentation }; //# sourceMappingURL=eve.js.map