UNPKG

eve

Version:

Filesystem-first framework for durable backend AI agents that run anywhere.

1 lines • 2.81 kB
import{resolveInstalledPackageInfo}from"#internal/application/package.js";import{getInstrumentationRuntime}from"#instrumentation/runtime.js";import{DEVELOPMENT_WORKER_APP_ROOT_ENV}from"#internal/workflow/development-world-protocol.js";import{createInstrumentationSetupContext}from"#instrumentation/setup-context.js";import{agentRuns,localTraces}from"#public/instrumentation/otel.js";import{installInstrumentationRuntime}from"#tracing/install-instrumentation-runtime.js";import{collectOtelPipeline}from"#tracing/otel-declaration.js";import{isInstrumentationDisabled,isInstrumentationProvider}from"#public/instrumentation/provider.js";const INSTRUMENTATION_PROVIDERS_GLOBAL_KEY=Symbol.for(`eve.harness-instrumentation-providers`),globalContainer=globalThis;function providerRegistry(){let e=globalContainer[INSTRUMENTATION_PROVIDERS_GLOBAL_KEY];if(e!==void 0)return e;let t=new Map;return globalContainer[INSTRUMENTATION_PROVIDERS_GLOBAL_KEY]=t,t}function seedInstrumentationProviders(){let e=providerRegistry();(process.env.VERCEL_ENV===`preview`||process.env.VERCEL_ENV===`production`)&&e.set(`agent-runs`,agentRuns()),process.env[DEVELOPMENT_WORKER_APP_ROOT_ENV]!==void 0&&e.set(`local`,localTraces())}async function registerInstrumentationProvider(e){if(isInstrumentationDisabled(e.value)){providerRegistry().delete(e.slot);return}if(!isInstrumentationProvider(e.value))throw Error(`The default export of "instrumentation/${e.slot}" is not an instrumentation provider. Return the result of \`defineInstrumentation\` or \`disableInstrumentation\` from it.`);if(Object.hasOwn(e.value,`capture`))throw Error(`The instrumentation provider "instrumentation/${e.slot}" no longer supports \`capture\`. Use \`tracePolicy\` to configure content capture.`);providerRegistry().set(e.slot,e.value),await e.value.setup?.(createInstrumentationSetupContext(e.agentName))}function getInstrumentationProviders(){return[...providerRegistry()].sort(([e],[t])=>e.localeCompare(t)).map(([e,t])=>({provider:t,slot:e}))}function finalizeInstrumentationProviders(e){let t=getInstrumentationProviders(),n=t.map(toProviderDefinition),r=collectOtelPipeline(t.map(e=>e.provider));return installInstrumentationRuntime({collected:r,frameworkVersion:resolveInstalledPackageInfo().version,providers:n,runtimeContextResolvers:r.runtimeContextResolvers,serviceName:e.serviceName})}async function shutdownInstrumentationProviders(){await getInstrumentationRuntime()?.shutdown()}function toProviderDefinition(e){return{events:e.provider.events,flush:e.provider.flush,name:e.slot,shutdown:e.provider.shutdown,stateNamespace:`authored:${e.slot}`,tracePolicy:e.provider.tracePolicy}}export{finalizeInstrumentationProviders,getInstrumentationProviders,registerInstrumentationProvider,seedInstrumentationProviders,shutdownInstrumentationProviders};