eve
Version:
Filesystem-first framework for durable backend AI agents that run anywhere.
1 lines • 2.73 kB
JavaScript
import{PROVIDER}from"#public/instrumentation/provider.js";import{batchSpanProcessor}from"#tracing/batch-span-processor.js";import{contentFilteringProcessor}from"#tracing/content-span-processor.js";import{vercelRuntimeSpanProcessor}from"#tracing/vercel-runtime-span-exporter.js";const OTEL_DECLARATION=Symbol.for(`eve.instrumentation.otel`),OTEL_INTEGRATION=Symbol.for(`eve.instrumentation.otel-integration`);function otel(e={}){return{[OTEL_DECLARATION]:!0,[PROVIDER]:!0,options:e}}function otelIntegration(e={}){return createOtelIntegration(e)}function managedOtelIntegration(e={}){return createOtelIntegration(e)}function createOtelIntegration(e){assertNoRemovedContentOptions(e);let t=e.spanProcessors??[],n=e.traceExporter===void 0?t:[...t,batchSpanProcessor(e.traceExporter)];return{[OTEL_INTEGRATION]:!0,[PROVIDER]:!0,metricReaders:e.metricReaders??[],runtimeContext:e.runtimeContext,spanProcessors:n.map(t=>contentFilteringProcessor(t,e.exportPolicy))}}function agentRunsIntegration(e={}){return assertNoRemovedContentOptions(e),{[OTEL_INTEGRATION]:!0,[PROVIDER]:!0,metricReaders:[],spanProcessors:[contentFilteringProcessor(vercelRuntimeSpanProcessor(),e.exportPolicy)]}}function assertNoRemovedContentOptions(e){if(Object.hasOwn(e,`recordInputs`)||Object.hasOwn(e,`recordOutputs`))throw Error("OpenTelemetry destination options no longer support `recordInputs` or `recordOutputs`. Use an `exportPolicy` span decision with `{ redact: true, inputs: true }`, `{ redact: true, outputs: true }`, or both.")}function isOtelDeclaration(e){return typeof e==`object`&&!!e&&e[OTEL_DECLARATION]===!0}function isOtelIntegration(e){return typeof e==`object`&&!!e&&e[OTEL_INTEGRATION]===!0}function collectOtelPipeline(e){let t=[],n=[],r=[],i,a=!1,o=!1;for(let s of e){if(isOtelIntegration(s)){a=!0,o=!0,t.push(...s.spanProcessors),n.push(...s.metricReaders),s.runtimeContext!==void 0&&r.push(s.runtimeContext);continue}if(isOtelDeclaration(s)){if(i!==void 0)throw Error("Instrumentation declares `otel()` more than once. One process has one OpenTelemetry tracer provider, so it has one resource, one sampler, and one propagator set — declare them in a single `otel()`.");a=!0,i=s}}let s=i?.options??{},c={functionId:s.functionId,recordInputs:o,recordOutputs:o,traceChannelRequests:s.traceChannelRequests===!0};return s.tracePolicy!==void 0&&Object.assign(c,{tracePolicy:s.tracePolicy}),{declared:a,pipeline:{instrumentations:s.instrumentations,metricReaders:n.length>0?n:void 0,propagators:s.propagators,resource:s.resource,sampler:s.sampler,spanProcessors:t},runtimeContextResolvers:r,settings:c}}export{agentRunsIntegration,collectOtelPipeline,isOtelDeclaration,isOtelIntegration,managedOtelIntegration,otel,otelIntegration};