autotel-edge 3.16.0 → 3.16.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{chunk-YWMTEG63.js → chunk-D2WERTLK.js} +3 -3
- package/dist/{chunk-YWMTEG63.js.map → chunk-D2WERTLK.js.map} +1 -1
- package/dist/events.d.ts +2 -2
- package/dist/events.js +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/index.js +2 -2
- package/dist/logger.d.ts +7 -0
- package/dist/logger.js +15 -3
- package/dist/logger.js.map +1 -1
- package/dist/sampling.d.ts +1 -1
- package/dist/{types-BOs00OpG.d.ts → types-CZFcIjJ4.d.ts} +1 -1
- package/package.json +1 -1
- package/src/api/logger.test.ts +104 -2
- package/src/api/logger.ts +55 -17
|
@@ -5,7 +5,7 @@ import { ParentBasedSampler, AlwaysOnSampler } from '@opentelemetry/sdk-trace-ba
|
|
|
5
5
|
import { createContextKey, context } from '@opentelemetry/api';
|
|
6
6
|
|
|
7
7
|
// src/core/exporter.ts
|
|
8
|
-
var PACKAGE_VERSION = "3.16.
|
|
8
|
+
var PACKAGE_VERSION = "3.16.1";
|
|
9
9
|
var defaultHeaders = {
|
|
10
10
|
accept: "application/json",
|
|
11
11
|
"content-type": "application/json",
|
|
@@ -306,5 +306,5 @@ function createInitialiser(config) {
|
|
|
306
306
|
}
|
|
307
307
|
|
|
308
308
|
export { OTLPExporter, createInitialiser, getActiveConfig, parseConfig, setConfig };
|
|
309
|
-
//# sourceMappingURL=chunk-
|
|
310
|
-
//# sourceMappingURL=chunk-
|
|
309
|
+
//# sourceMappingURL=chunk-D2WERTLK.js.map
|
|
310
|
+
//# sourceMappingURL=chunk-D2WERTLK.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/core/exporter.ts","../src/types.ts","../src/core/spanprocessor.ts","../src/core/config.ts"],"names":["api_context"],"mappings":";;;;;;;AAiBA,IAAM,eAAA,GAAkB,QAAA;AAEx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AA,IAAe,EAAC;AAAA,IACpC,YAAY,MAAA,CAAO;AAAA,GACrB;AAEA,EAAA,OAAO,QAAA;AACT;AAKA,SAAS,yBAAyB,MAAA,EAAmC;AACnE,EAAA,MAAM,EAAE,KAAA,EAAO,YAAA,GAAe,IAAA,EAAK,GAAI,MAAA;AAGvC,EAAA,MAAM,YAAA,GAAe;AAAA,IACnB,cAAc,OAAO;AAAA,MACnB,QAAA,EAAU,IAAA,CAAK,MAAA,EAAO,GAAI,QAAQ,CAAA,GAAI,CAAA;AAAA;AAAA,MACtC,YAAY;AAAC,KACf,CAAA;AAAA,IACA,QAAA,EAAU,MAAM,CAAA,yBAAA,EAA4B,KAAK,CAAA,CAAA;AAAA,GACnD;AAEA,EAAA,IAAI,YAAA,EAAc;AAChB,IAAA,OAAO,IAAI,kBAAA,CAAmB,EAAE,IAAA,EAAM,cAAqB,CAAA;AAAA,EAC7D;AAEA,EAAA,OAAO,YAAA;AACT;AAKO,SAAS,kBAAkB,MAAA,EAA0C;AAC1E,EAAA,IAAI,OAAO,WAAW,UAAA,EAAY;AAChC,IAAA,OAAO,CAAC,KAAK,OAAA,KAAY;AACvB,MAAA,MAAM,IAAA,GAAO,WAAA,CAAY,MAAA,CAAO,GAAA,EAAK,OAAO,CAAC,CAAA;AAC7C,MAAA,OAAO,IAAA;AAAA,IACT,CAAA;AAAA,EACF,CAAA,MAAO;AACL,IAAA,MAAM,MAAA,GAAS,YAAY,MAAM,CAAA;AACjC,IAAA,OAAO,MAAM,MAAA;AAAA,EACf;AACF","file":"chunk-YWMTEG63.js","sourcesContent":["/**\n * Lightweight OTLP exporter for edge environments\n * Ported and adapted from @microlabs/\n *\n * This exporter is much smaller than the standard @opentelemetry/exporter-trace-otlp-http\n * because it uses fetch() directly instead of Node.js http/https modules.\n */\n\nimport type { ExportResult } from '@opentelemetry/core';\nimport { ExportResultCode } from '@opentelemetry/core';\nimport { OTLPExporterError } from '@opentelemetry/otlp-exporter-base';\nimport { JsonTraceSerializer } from '@opentelemetry/otlp-transformer';\nimport type { SpanExporter } from '@opentelemetry/sdk-trace-base';\nimport type { OTLPExporterConfig } from '../types';\n\n// Version is injected at build time via tsup define\n// This avoids runtime filesystem access which isn't available in edge environments\nconst PACKAGE_VERSION = process.env.AUTOTEL_EDGE_VERSION || '0.1.1';\n\nconst defaultHeaders: Record<string, string> = {\n accept: 'application/json',\n 'content-type': 'application/json',\n 'user-agent': `autotel-edge v${PACKAGE_VERSION}`,\n};\n\n/**\n * Minimal OTLP exporter using fetch()\n */\nexport class OTLPExporter implements SpanExporter {\n private headers: Record<string, string>;\n private url: string;\n\n constructor(config: OTLPExporterConfig) {\n this.url = config.url;\n this.headers = Object.assign({}, defaultHeaders, config.headers);\n }\n\n export(items: any[], resultCallback: (result: ExportResult) => void): void {\n this._export(items)\n .then(() => {\n resultCallback({ code: ExportResultCode.SUCCESS });\n })\n .catch((error) => {\n resultCallback({ code: ExportResultCode.FAILED, error });\n });\n }\n\n private _export(items: any[]): Promise<unknown> {\n return new Promise<void>((resolve, reject) => {\n try {\n this.send(items, resolve, reject);\n } catch (error) {\n reject(error);\n }\n });\n }\n\n send(\n items: any[],\n onSuccess: () => void,\n onError: (error: OTLPExporterError) => void,\n ): void {\n const decoder = new TextDecoder();\n const exportMessage = JsonTraceSerializer.serializeRequest(items);\n\n const body = decoder.decode(exportMessage);\n const params: RequestInit = {\n method: 'POST',\n headers: this.headers,\n body,\n };\n\n fetch(this.url, params)\n .then((response) => {\n if (response.ok) {\n onSuccess();\n } else {\n onError(\n new OTLPExporterError(\n `Exporter received a statusCode: ${response.status}`,\n ),\n );\n }\n })\n .catch((error) => {\n onError(\n new OTLPExporterError(\n `Exception during export: ${error.toString()}`,\n error.code,\n error.stack,\n ),\n );\n });\n }\n\n async shutdown(): Promise<void> {\n // No-op for edge environments\n }\n}\n","/**\n * Shared types for autotel-edge\n */\n\nimport type {\n Attributes,\n Context,\n Span,\n SpanOptions,\n TextMapPropagator,\n} from '@opentelemetry/api';\nimport type {\n ReadableSpan,\n Sampler,\n SpanExporter,\n SpanProcessor,\n} from '@opentelemetry/sdk-trace-base';\n\n// Re-export commonly used types\n\n\n/**\n * Extended SpanOptions with per-span sampler support\n */\nexport interface ExtendedSpanOptions extends SpanOptions {\n sampler?: Sampler;\n}\n\n/**\n * Trigger types for edge handlers\n * Can be a Request or any vendor-specific trigger type\n */\nexport type Trigger =\n | Request\n | DOConstructorTrigger\n | WorkflowTrigger\n | 'do-alarm'\n | unknown;\n\nexport interface DOConstructorTrigger {\n id: string;\n name?: string;\n}\n\nexport interface WorkflowTrigger {\n type: 'workflow';\n name: string;\n}\n\n/**\n * Config types\n */\nexport interface OTLPExporterConfig {\n url: string;\n headers?: Record<string, string>;\n}\n\nexport type ExporterConfig = OTLPExporterConfig | SpanExporter;\n\nexport interface ServiceConfig {\n name: string;\n namespace?: string;\n version?: string;\n}\n\nexport interface ParentRatioSamplingConfig {\n acceptRemote?: boolean;\n ratio: number;\n}\n\ntype HeadSamplerConf = Sampler | ParentRatioSamplingConfig;\n\nexport interface SamplingConfig<HS extends HeadSamplerConf = HeadSamplerConf> {\n headSampler?: HS;\n tailSampler?: TailSampleFn;\n}\n\nexport interface InstrumentationOptions {\n instrumentGlobalFetch?: boolean;\n instrumentGlobalCache?: boolean;\n /**\n * Disable instrumentation entirely (useful for local development)\n * When enabled, the handler is returned as-is without any instrumentation\n * @default false\n */\n disabled?: boolean;\n}\n\n/**\n * Utility types\n */\nexport type OrPromise<T> = T | Promise<T>;\n\n/**\n * Adapter event types\n */\nexport type FunnelStepStatus =\n | 'started'\n | 'completed'\n | 'abandoned'\n | 'failed'\n | (string & {});\n\nexport type OutcomeStatus =\n | 'success'\n | 'failure'\n | 'partial'\n | (string & {});\n\nexport interface EdgeEventBase {\n [key: string]: unknown;\n service: string;\n timestamp: number;\n attributes: Record<string, unknown>;\n traceId?: string;\n spanId?: string;\n correlationId?: string;\n name: string; // Normalized event name for easy access\n}\n\nexport interface EdgeTrackEvent extends EdgeEventBase {\n type: 'event';\n event: string;\n}\n\nexport interface EdgeFunnelStepEvent extends EdgeEventBase {\n type: 'funnel-step';\n funnel: string;\n status: FunnelStepStatus;\n}\n\nexport interface EdgeOutcomeEvent extends EdgeEventBase {\n type: 'outcome';\n operation: string;\n outcome: OutcomeStatus;\n}\n\nexport interface EdgeValueEvent extends EdgeEventBase {\n type: 'value';\n metric: string;\n value: number;\n}\n\nexport type EdgeEvent =\n | EdgeTrackEvent\n | EdgeFunnelStepEvent\n | EdgeOutcomeEvent\n | EdgeValueEvent;\n\nexport type EdgeSubscriber = (event: EdgeEvent) => OrPromise<void>;\n\nexport interface FetcherConfig {\n includeTraceContext?: boolean | ((request: Request) => boolean);\n}\n\nexport interface PostProcessParams {\n /**\n * The request object that was passed to the fetch handler.\n */\n request: Request;\n /**\n * The generated response object.\n */\n response: Response;\n /**\n * A readable version of the span object that can be used to access the span's attributes and events.\n */\n readable: ReadableSpan;\n}\n\nexport interface FetchHandlerConfig {\n /**\n * Whether to enable context propagation for incoming requests to `fetch`.\n * This enables or disables distributed tracing from W3C Trace Context headers.\n * @default true\n */\n acceptTraceContext?: boolean | ((request: Request) => boolean);\n /**\n * Allows further customization of the generated span, based on the request/response data.\n */\n postProcess?: (span: Span, ctx: PostProcessParams) => void;\n}\n\nexport interface HandlerConfig {\n fetch?: FetchHandlerConfig;\n}\n\nexport interface DataSafetyConfig {\n /** Redact query parameters from URL attributes (default: false) */\n redactQueryParams?: boolean;\n /** Control D1 SQL statement capture: 'full' (default), 'obfuscated', or 'off' */\n captureDbStatement?: 'off' | 'obfuscated' | 'full';\n /** Only capture these email headers (lowercase). When set, other headers are excluded. */\n emailHeaderAllowlist?: string[];\n}\n\ninterface EdgeConfigBase {\n service: ServiceConfig;\n handlers?: HandlerConfig;\n fetch?: FetcherConfig;\n postProcessor?: PostProcessorFn;\n sampling?: SamplingConfig;\n propagator?: TextMapPropagator;\n instrumentation?: InstrumentationOptions;\n subscribers?: EdgeSubscriber[];\n /** Opt-in data safety controls for sensitive attribute capture */\n dataSafety?: DataSafetyConfig;\n}\n\ninterface EdgeConfigExporter extends EdgeConfigBase {\n exporter: ExporterConfig;\n}\n\ninterface EdgeConfigSpanProcessors extends EdgeConfigBase {\n spanProcessors: SpanProcessor | SpanProcessor[];\n}\n\nexport type EdgeConfig = EdgeConfigExporter | EdgeConfigSpanProcessors;\n\nexport function isSpanProcessorConfig(\n config: EdgeConfig,\n): config is EdgeConfigSpanProcessors {\n return !!(config as EdgeConfigSpanProcessors).spanProcessors;\n}\n\nexport interface ResolvedEdgeConfig extends EdgeConfigBase {\n handlers: Required<HandlerConfig>;\n fetch: Required<FetcherConfig>;\n postProcessor: PostProcessorFn;\n sampling: Required<SamplingConfig<Sampler>>;\n spanProcessors: SpanProcessor[];\n propagator: TextMapPropagator;\n instrumentation: InstrumentationOptions;\n subscribers: EdgeSubscriber[];\n}\n\n/**\n * Function types\n */\nexport type ResolveConfigFn<Env = any> = (\n env: Env,\n trigger: Trigger,\n) => EdgeConfig;\nexport type ConfigurationOption = EdgeConfig | ResolveConfigFn;\n\nexport type PostProcessorFn = (spans: ReadableSpan[]) => ReadableSpan[];\nexport type TailSampleFn = (traceInfo: LocalTrace) => boolean;\n\nexport interface LocalTrace {\n traceId: string;\n spans: ReadableSpan[];\n localRootSpan: ReadableSpan;\n}\n\n/**\n * Span processor with flush support\n */\nexport type TraceFlushableSpanProcessor = SpanProcessor & {\n forceFlush: (traceId?: string) => Promise<void>;\n};\n\n/**\n * Handler instrumentation\n */\nexport interface InitialSpanInfo {\n name: string;\n options: SpanOptions;\n context?: Context;\n}\n\nexport interface HandlerInstrumentation<T extends Trigger, R extends any> {\n getInitialSpanInfo: (trigger: T) => InitialSpanInfo;\n getAttributesFromResult?: (result: Awaited<R>) => Attributes;\n instrumentTrigger?: (trigger: T) => T;\n executionSucces?: (span: Span, trigger: T, result: Awaited<R>) => void;\n executionFailed?: (span: Span, trigger: T, error?: any) => void;\n}\n\n/**\n * Utility types\n */\n\nexport {type Attributes, type Context, type Span, type SpanOptions} from '@opentelemetry/api';\nexport {type ReadableSpan} from '@opentelemetry/sdk-trace-base';","/**\n * Span processor with flush and tail sampling support\n */\n\nimport type { Context } from '@opentelemetry/api';\nimport type {\n ReadableSpan,\n Span,\n SpanExporter,\n SpanProcessor,\n} from '@opentelemetry/sdk-trace-base';\nimport type { PostProcessorFn, TailSampleFn, LocalTrace } from '../types';\n\n/**\n * Span processor that supports flush by trace ID and tail sampling\n */\nexport class SpanProcessorWithFlush implements SpanProcessor {\n private exporter: SpanExporter;\n private postProcessor?: PostProcessorFn;\n private spans: Map<string, ReadableSpan[]> = new Map();\n\n constructor(exporter: SpanExporter, postProcessor?: PostProcessorFn) {\n this.exporter = exporter;\n this.postProcessor = postProcessor;\n }\n\n onStart(_span: Span, _parentContext: Context): void {\n // No-op for now\n }\n\n onEnd(span: ReadableSpan): void {\n const traceId = span.spanContext().traceId;\n\n if (!this.spans.has(traceId)) {\n this.spans.set(traceId, []);\n }\n\n this.spans.get(traceId)!.push(span);\n }\n\n /**\n * Force flush spans for a specific trace\n */\n async forceFlush(traceId?: string): Promise<void> {\n if (traceId) {\n const spans = this.spans.get(traceId);\n if (spans && spans.length > 0) {\n await this.exportSpans(spans);\n this.spans.delete(traceId);\n }\n } else {\n // Flush all traces\n const promises: Promise<void>[] = [];\n for (const [id, spans] of this.spans.entries()) {\n promises.push(this.exportSpans(spans));\n this.spans.delete(id);\n }\n await Promise.all(promises);\n }\n }\n\n async shutdown(): Promise<void> {\n await this.forceFlush();\n if (this.exporter) {\n await this.exporter.shutdown();\n }\n }\n\n /**\n * Export spans with post-processing\n * Errors are caught and logged but don't throw to prevent worker instability\n */\n private async exportSpans(spans: ReadableSpan[]): Promise<void> {\n if (spans.length === 0) return;\n if (!this.exporter) return; // No exporter configured (e.g., in tests)\n\n let processedSpans = spans;\n\n if (this.postProcessor) {\n try {\n processedSpans = this.postProcessor(spans);\n } catch (error) {\n // Post-processor errors should not prevent export\n console.error('[autotel-edge] Post-processor error:', error);\n // Continue with original spans\n processedSpans = spans;\n }\n }\n\n return new Promise((resolve) => {\n this.exporter.export(processedSpans, (result) => {\n if (result.code === 0) {\n // SUCCESS\n resolve();\n } else {\n // Log but don't reject - exporter failures shouldn't crash the worker\n console.error(\n '[autotel-edge] Exporter error:',\n result.error?.message || 'Unknown error',\n );\n resolve(); // Resolve instead of reject to prevent unhandled promise rejection\n }\n });\n });\n }\n}\n\n/**\n * Span processor that supports tail sampling decisions\n */\nexport class TailSamplingSpanProcessor implements SpanProcessor {\n private wrapped: SpanProcessorWithFlush;\n private tailSampler?: TailSampleFn;\n private traces: Map<string, LocalTrace> = new Map();\n\n constructor(\n exporter: SpanExporter,\n postProcessor?: PostProcessorFn,\n tailSampler?: TailSampleFn,\n ) {\n this.wrapped = new SpanProcessorWithFlush(exporter, postProcessor);\n this.tailSampler = tailSampler;\n }\n\n onStart(span: Span, parentContext: Context): void {\n this.wrapped.onStart(span, parentContext);\n }\n\n onEnd(span: ReadableSpan): void {\n const traceId = span.spanContext().traceId;\n const spanId = span.spanContext().spanId;\n const parentSpanId = 'parentSpanId' in span ? span.parentSpanId : undefined;\n\n // Initialize trace if not exists\n if (!this.traces.has(traceId)) {\n this.traces.set(traceId, {\n traceId,\n spans: [],\n localRootSpan: undefined as any, // Will be set when we identify the local root\n });\n }\n\n const trace = this.traces.get(traceId)!;\n\n // Determine if this span is a local root by checking if its parent is in buffered spans\n // A span is a local root if:\n // 1. It has no parentSpanId (definitive root)\n // 2. Its parentSpanId doesn't match any already-buffered span (remote parent = distributed trace entry)\n const hasLocalParent = parentSpanId &&\n trace.spans.some(s => s.spanContext().spanId === parentSpanId);\n\n // Set localRootSpan if this is the local root (no local parent found in buffer)\n if (!hasLocalParent) {\n trace.localRootSpan = span;\n }\n\n trace.spans.push(span); // Buffer the span AFTER checking parent relationships\n\n // Auto-flush decision: only auto-flush for normal traces (no parentSpanId at all)\n // For distributed traces (parentSpanId present), we rely on explicit forceFlush() from instrument.ts\n // This ensures we don't trigger before all spans have been buffered\n const isDefinitiveRoot = !parentSpanId;\n const shouldAutoFlush = isDefinitiveRoot && trace.localRootSpan &&\n trace.localRootSpan.spanContext().spanId === spanId;\n\n if (shouldAutoFlush) {\n if (this.tailSampler) {\n const shouldKeep = this.tailSampler(trace);\n\n if (shouldKeep) {\n // Export ALL buffered spans in the trace\n for (const bufferedSpan of trace.spans) {\n this.wrapped.onEnd(bufferedSpan);\n }\n // Force flush to actually export the spans\n void this.wrapped.forceFlush(traceId);\n }\n // If not keeping, just drop all spans (don't export)\n } else {\n // No tail sampler, export all buffered spans\n for (const bufferedSpan of trace.spans) {\n this.wrapped.onEnd(bufferedSpan);\n }\n // Force flush to actually export the spans\n void this.wrapped.forceFlush(traceId);\n }\n\n // Clean up trace after decision\n this.traces.delete(traceId);\n }\n // If not local root span, just buffer it - don't export yet\n }\n\n async forceFlush(traceId?: string): Promise<void> {\n if (traceId) {\n // Make tail sampling decision for this specific trace before flushing\n const trace = this.traces.get(traceId);\n if (trace) {\n // Ensure localRootSpan is set (fallback to first span if not)\n // This handles distributed traces where no span has undefined parentSpanId\n if (!trace.localRootSpan && trace.spans.length > 0) {\n trace.localRootSpan = trace.spans[0];\n }\n\n if (this.tailSampler) {\n const shouldKeep = this.tailSampler(trace);\n\n if (shouldKeep) {\n // Export ALL buffered spans in the trace\n for (const bufferedSpan of trace.spans) {\n this.wrapped.onEnd(bufferedSpan);\n }\n }\n } else {\n // No tail sampler, export all buffered spans\n for (const bufferedSpan of trace.spans) {\n this.wrapped.onEnd(bufferedSpan);\n }\n }\n\n // Clean up trace after decision\n this.traces.delete(traceId);\n }\n }\n return this.wrapped.forceFlush(traceId);\n }\n\n async shutdown(): Promise<void> {\n this.traces.clear();\n return this.wrapped.shutdown();\n }\n}\n","/**\n * Configuration system for autotel-edge\n */\n\nimport { W3CTraceContextPropagator } from '@opentelemetry/core';\nimport { ParentBasedSampler, AlwaysOnSampler } from '@opentelemetry/sdk-trace-base';\nimport { context as api_context, createContextKey, type Context } from '@opentelemetry/api';\nimport type {\n EdgeConfig,\n ResolvedEdgeConfig,\n ConfigurationOption,\n Trigger,\n ParentRatioSamplingConfig,\n} from '../types';\nimport { isSpanProcessorConfig } from '../types';\nimport { OTLPExporter } from './exporter';\nimport { TailSamplingSpanProcessor } from './spanprocessor';\n\n/**\n * Type for config initialization function\n */\nexport type Initialiser = (env: any, trigger: Trigger) => ResolvedEdgeConfig;\n\n/**\n * Context key for storing config (isolates config per-request)\n */\nconst CONFIG_KEY = createContextKey('autotel-edge-config');\n\n/**\n * Get the currently active config from context\n *\n * This reads the config from the active context, ensuring each request\n * has its own isolated config even when multiple requests are in-flight.\n */\nexport function getActiveConfig(): ResolvedEdgeConfig | null {\n const value = api_context.active().getValue(CONFIG_KEY) as\n | ResolvedEdgeConfig\n | null\n | undefined;\n return value ?? null;\n}\n\n/**\n * Set the active config in context\n *\n * Returns a new context with the config stored. This context should be\n * used with api_context.with() to ensure the config is isolated per-request.\n *\n * @example\n * ```typescript\n * const config = parseConfig({ service: { name: 'my-service' } });\n * const context = setConfig(config);\n *\n * api_context.with(context, () => {\n * // Config is available here via getActiveConfig()\n * });\n * ```\n */\nexport function setConfig(config: ResolvedEdgeConfig): Context {\n return api_context.active().setValue(CONFIG_KEY, config);\n}\n\n/**\n * Parse and validate configuration\n */\nexport function parseConfig(config: EdgeConfig): ResolvedEdgeConfig {\n // Parse head sampler\n const headSampler =\n config.sampling?.headSampler ??\n new ParentBasedSampler({\n root: new AlwaysOnSampler(),\n });\n\n const parsedHeadSampler =\n typeof headSampler === 'object' && 'ratio' in headSampler\n ? createParentRatioSampler(headSampler)\n : headSampler;\n\n // Parse tail sampler (default: keep sampled or error traces)\n const tailSampler =\n config.sampling?.tailSampler ??\n ((traceInfo) => {\n const localRootSpan = traceInfo.localRootSpan;\n const ctx = localRootSpan.spanContext();\n // Keep if sampled or if root span has error\n return (ctx.traceFlags & 1) === 1 || localRootSpan.status.code === 2; // SAMPLED flag | ERROR status\n });\n\n // Parse exporter - use TailSamplingSpanProcessor when tail sampler is present\n const spanProcessors = isSpanProcessorConfig(config)\n ? Array.isArray(config.spanProcessors)\n ? config.spanProcessors\n : [config.spanProcessors]\n : [\n // Use TailSamplingSpanProcessor to enable tail sampling\n new TailSamplingSpanProcessor(\n typeof config.exporter === 'object' && 'url' in config.exporter\n ? new OTLPExporter(config.exporter)\n : config.exporter,\n config.postProcessor,\n tailSampler, // Wire up the tail sampler!\n ),\n ];\n\n // Build resolved config\n const resolved: ResolvedEdgeConfig = {\n service: config.service,\n handlers: {\n fetch: config.handlers?.fetch ?? {},\n },\n fetch: {\n includeTraceContext: config.fetch?.includeTraceContext ?? true,\n },\n postProcessor: config.postProcessor ?? ((spans) => spans),\n sampling: {\n headSampler: parsedHeadSampler,\n tailSampler,\n },\n spanProcessors,\n propagator: config.propagator ?? new W3CTraceContextPropagator(),\n instrumentation: {\n instrumentGlobalFetch: config.instrumentation?.instrumentGlobalFetch ?? true,\n instrumentGlobalCache: config.instrumentation?.instrumentGlobalCache ?? false,\n disabled: config.instrumentation?.disabled ?? false,\n },\n subscribers: config.subscribers ?? [],\n dataSafety: config.dataSafety,\n };\n\n return resolved;\n}\n\n/**\n * Create a parent-based ratio sampler\n */\nfunction createParentRatioSampler(config: ParentRatioSamplingConfig) {\n const { ratio, acceptRemote = true } = config;\n\n // Simple ratio sampler\n const ratioSampler = {\n shouldSample: () => ({\n decision: Math.random() < ratio ? 1 : 0, // RECORD_AND_SAMPLED : NOT_RECORD\n attributes: {},\n }),\n toString: () => `ParentRatioSampler{ratio=${ratio}}`,\n };\n\n if (acceptRemote) {\n return new ParentBasedSampler({ root: ratioSampler as any });\n }\n\n return ratioSampler;\n}\n\n/**\n * Create a config initializer function\n */\nexport function createInitialiser(config: ConfigurationOption): Initialiser {\n if (typeof config === 'function') {\n return (env, trigger) => {\n const conf = parseConfig(config(env, trigger));\n return conf;\n };\n } else {\n const parsed = parseConfig(config);\n return () => parsed;\n }\n}\n"]}
|
|
1
|
+
{"version":3,"sources":["../src/core/exporter.ts","../src/types.ts","../src/core/spanprocessor.ts","../src/core/config.ts"],"names":["api_context"],"mappings":";;;;;;;AAiBA,IAAM,eAAA,GAAkB,QAAA;AAExB,IAAM,cAAA,GAAyC;AAAA,EAC7C,MAAA,EAAQ,kBAAA;AAAA,EACR,cAAA,EAAgB,kBAAA;AAAA,EAChB,YAAA,EAAc,iBAAiB,eAAe,CAAA;AAChD,CAAA;AAKO,IAAM,eAAN,MAA2C;AAAA,EACxC,OAAA;AAAA,EACA,GAAA;AAAA,EAER,YAAY,MAAA,EAA4B;AACtC,IAAA,IAAA,CAAK,MAAM,MAAA,CAAO,GAAA;AAClB,IAAA,IAAA,CAAK,UAAU,MAAA,CAAO,MAAA,CAAO,EAAC,EAAG,cAAA,EAAgB,OAAO,OAAO,CAAA;AAAA,EACjE;AAAA,EAEA,MAAA,CAAO,OAAc,cAAA,EAAsD;AACzE,IAAA,IAAA,CAAK,OAAA,CAAQ,KAAK,CAAA,CACf,IAAA,CAAK,MAAM;AACV,MAAA,cAAA,CAAe,EAAE,IAAA,EAAM,gBAAA,CAAiB,OAAA,EAAS,CAAA;AAAA,IACnD,CAAC,CAAA,CACA,KAAA,CAAM,CAAC,KAAA,KAAU;AAChB,MAAA,cAAA,CAAe,EAAE,IAAA,EAAM,gBAAA,CAAiB,MAAA,EAAQ,OAAO,CAAA;AAAA,IACzD,CAAC,CAAA;AAAA,EACL;AAAA,EAEQ,QAAQ,KAAA,EAAgC;AAC9C,IAAA,OAAO,IAAI,OAAA,CAAc,CAAC,OAAA,EAAS,MAAA,KAAW;AAC5C,MAAA,IAAI;AACF,QAAA,IAAA,CAAK,IAAA,CAAK,KAAA,EAAO,OAAA,EAAS,MAAM,CAAA;AAAA,MAClC,SAAS,KAAA,EAAO;AACd,QAAA,MAAA,CAAO,KAAK,CAAA;AAAA,MACd;AAAA,IACF,CAAC,CAAA;AAAA,EACH;AAAA,EAEA,IAAA,CACE,KAAA,EACA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AAA,EAAiB,qBAAA,IAAyB,KAAA;AAAA,MACxE,QAAA,EAAU,MAAA,CAAO,eAAA,EAAiB,QAAA,IAAY;AAAA,KAChD;AAAA,IACA,WAAA,EAAa,MAAA,CAAO,WAAA,IAAe,EAAC;AAAA,IACpC,YAAY,MAAA,CAAO;AAAA,GACrB;AAEA,EAAA,OAAO,QAAA;AACT;AAKA,SAAS,yBAAyB,MAAA,EAAmC;AACnE,EAAA,MAAM,EAAE,KAAA,EAAO,YAAA,GAAe,IAAA,EAAK,GAAI,MAAA;AAGvC,EAAA,MAAM,YAAA,GAAe;AAAA,IACnB,cAAc,OAAO;AAAA,MACnB,QAAA,EAAU,IAAA,CAAK,MAAA,EAAO,GAAI,QAAQ,CAAA,GAAI,CAAA;AAAA;AAAA,MACtC,YAAY;AAAC,KACf,CAAA;AAAA,IACA,QAAA,EAAU,MAAM,CAAA,yBAAA,EAA4B,KAAK,CAAA,CAAA;AAAA,GACnD;AAEA,EAAA,IAAI,YAAA,EAAc;AAChB,IAAA,OAAO,IAAI,kBAAA,CAAmB,EAAE,IAAA,EAAM,cAAqB,CAAA;AAAA,EAC7D;AAEA,EAAA,OAAO,YAAA;AACT;AAKO,SAAS,kBAAkB,MAAA,EAA0C;AAC1E,EAAA,IAAI,OAAO,WAAW,UAAA,EAAY;AAChC,IAAA,OAAO,CAAC,KAAK,OAAA,KAAY;AACvB,MAAA,MAAM,IAAA,GAAO,WAAA,CAAY,MAAA,CAAO,GAAA,EAAK,OAAO,CAAC,CAAA;AAC7C,MAAA,OAAO,IAAA;AAAA,IACT,CAAA;AAAA,EACF,CAAA,MAAO;AACL,IAAA,MAAM,MAAA,GAAS,YAAY,MAAM,CAAA;AACjC,IAAA,OAAO,MAAM,MAAA;AAAA,EACf;AACF","file":"chunk-D2WERTLK.js","sourcesContent":["/**\n * Lightweight OTLP exporter for edge environments\n * Ported and adapted from @microlabs/\n *\n * This exporter is much smaller than the standard @opentelemetry/exporter-trace-otlp-http\n * because it uses fetch() directly instead of Node.js http/https modules.\n */\n\nimport type { ExportResult } from '@opentelemetry/core';\nimport { ExportResultCode } from '@opentelemetry/core';\nimport { OTLPExporterError } from '@opentelemetry/otlp-exporter-base';\nimport { JsonTraceSerializer } from '@opentelemetry/otlp-transformer';\nimport type { SpanExporter } from '@opentelemetry/sdk-trace-base';\nimport type { OTLPExporterConfig } from '../types';\n\n// Version is injected at build time via tsup define\n// This avoids runtime filesystem access which isn't available in edge environments\nconst PACKAGE_VERSION = process.env.AUTOTEL_EDGE_VERSION || '0.1.1';\n\nconst defaultHeaders: Record<string, string> = {\n accept: 'application/json',\n 'content-type': 'application/json',\n 'user-agent': `autotel-edge v${PACKAGE_VERSION}`,\n};\n\n/**\n * Minimal OTLP exporter using fetch()\n */\nexport class OTLPExporter implements SpanExporter {\n private headers: Record<string, string>;\n private url: string;\n\n constructor(config: OTLPExporterConfig) {\n this.url = config.url;\n this.headers = Object.assign({}, defaultHeaders, config.headers);\n }\n\n export(items: any[], resultCallback: (result: ExportResult) => void): void {\n this._export(items)\n .then(() => {\n resultCallback({ code: ExportResultCode.SUCCESS });\n })\n .catch((error) => {\n resultCallback({ code: ExportResultCode.FAILED, error });\n });\n }\n\n private _export(items: any[]): Promise<unknown> {\n return new Promise<void>((resolve, reject) => {\n try {\n this.send(items, resolve, reject);\n } catch (error) {\n reject(error);\n }\n });\n }\n\n send(\n items: any[],\n onSuccess: () => void,\n onError: (error: OTLPExporterError) => void,\n ): void {\n const decoder = new TextDecoder();\n const exportMessage = JsonTraceSerializer.serializeRequest(items);\n\n const body = decoder.decode(exportMessage);\n const params: RequestInit = {\n method: 'POST',\n headers: this.headers,\n body,\n };\n\n fetch(this.url, params)\n .then((response) => {\n if (response.ok) {\n onSuccess();\n } else {\n onError(\n new OTLPExporterError(\n `Exporter received a statusCode: ${response.status}`,\n ),\n );\n }\n })\n .catch((error) => {\n onError(\n new OTLPExporterError(\n `Exception during export: ${error.toString()}`,\n error.code,\n error.stack,\n ),\n );\n });\n }\n\n async shutdown(): Promise<void> {\n // No-op for edge environments\n }\n}\n","/**\n * Shared types for autotel-edge\n */\n\nimport type {\n Attributes,\n Context,\n Span,\n SpanOptions,\n TextMapPropagator,\n} from '@opentelemetry/api';\nimport type {\n ReadableSpan,\n Sampler,\n SpanExporter,\n SpanProcessor,\n} from '@opentelemetry/sdk-trace-base';\n\n// Re-export commonly used types\n\n\n/**\n * Extended SpanOptions with per-span sampler support\n */\nexport interface ExtendedSpanOptions extends SpanOptions {\n sampler?: Sampler;\n}\n\n/**\n * Trigger types for edge handlers\n * Can be a Request or any vendor-specific trigger type\n */\nexport type Trigger =\n | Request\n | DOConstructorTrigger\n | WorkflowTrigger\n | 'do-alarm'\n | unknown;\n\nexport interface DOConstructorTrigger {\n id: string;\n name?: string;\n}\n\nexport interface WorkflowTrigger {\n type: 'workflow';\n name: string;\n}\n\n/**\n * Config types\n */\nexport interface OTLPExporterConfig {\n url: string;\n headers?: Record<string, string>;\n}\n\nexport type ExporterConfig = OTLPExporterConfig | SpanExporter;\n\nexport interface ServiceConfig {\n name: string;\n namespace?: string;\n version?: string;\n}\n\nexport interface ParentRatioSamplingConfig {\n acceptRemote?: boolean;\n ratio: number;\n}\n\ntype HeadSamplerConf = Sampler | ParentRatioSamplingConfig;\n\nexport interface SamplingConfig<HS extends HeadSamplerConf = HeadSamplerConf> {\n headSampler?: HS;\n tailSampler?: TailSampleFn;\n}\n\nexport interface InstrumentationOptions {\n instrumentGlobalFetch?: boolean;\n instrumentGlobalCache?: boolean;\n /**\n * Disable instrumentation entirely (useful for local development)\n * When enabled, the handler is returned as-is without any instrumentation\n * @default false\n */\n disabled?: boolean;\n}\n\n/**\n * Utility types\n */\nexport type OrPromise<T> = T | Promise<T>;\n\n/**\n * Adapter event types\n */\nexport type FunnelStepStatus =\n | 'started'\n | 'completed'\n | 'abandoned'\n | 'failed'\n | (string & {});\n\nexport type OutcomeStatus =\n | 'success'\n | 'failure'\n | 'partial'\n | (string & {});\n\nexport interface EdgeEventBase {\n [key: string]: unknown;\n service: string;\n timestamp: number;\n attributes: Record<string, unknown>;\n traceId?: string;\n spanId?: string;\n correlationId?: string;\n name: string; // Normalized event name for easy access\n}\n\nexport interface EdgeTrackEvent extends EdgeEventBase {\n type: 'event';\n event: string;\n}\n\nexport interface EdgeFunnelStepEvent extends EdgeEventBase {\n type: 'funnel-step';\n funnel: string;\n status: FunnelStepStatus;\n}\n\nexport interface EdgeOutcomeEvent extends EdgeEventBase {\n type: 'outcome';\n operation: string;\n outcome: OutcomeStatus;\n}\n\nexport interface EdgeValueEvent extends EdgeEventBase {\n type: 'value';\n metric: string;\n value: number;\n}\n\nexport type EdgeEvent =\n | EdgeTrackEvent\n | EdgeFunnelStepEvent\n | EdgeOutcomeEvent\n | EdgeValueEvent;\n\nexport type EdgeSubscriber = (event: EdgeEvent) => OrPromise<void>;\n\nexport interface FetcherConfig {\n includeTraceContext?: boolean | ((request: Request) => boolean);\n}\n\nexport interface PostProcessParams {\n /**\n * The request object that was passed to the fetch handler.\n */\n request: Request;\n /**\n * The generated response object.\n */\n response: Response;\n /**\n * A readable version of the span object that can be used to access the span's attributes and events.\n */\n readable: ReadableSpan;\n}\n\nexport interface FetchHandlerConfig {\n /**\n * Whether to enable context propagation for incoming requests to `fetch`.\n * This enables or disables distributed tracing from W3C Trace Context headers.\n * @default true\n */\n acceptTraceContext?: boolean | ((request: Request) => boolean);\n /**\n * Allows further customization of the generated span, based on the request/response data.\n */\n postProcess?: (span: Span, ctx: PostProcessParams) => void;\n}\n\nexport interface HandlerConfig {\n fetch?: FetchHandlerConfig;\n}\n\nexport interface DataSafetyConfig {\n /** Redact query parameters from URL attributes (default: false) */\n redactQueryParams?: boolean;\n /** Control D1 SQL statement capture: 'full' (default), 'obfuscated', or 'off' */\n captureDbStatement?: 'off' | 'obfuscated' | 'full';\n /** Only capture these email headers (lowercase). When set, other headers are excluded. */\n emailHeaderAllowlist?: string[];\n}\n\ninterface EdgeConfigBase {\n service: ServiceConfig;\n handlers?: HandlerConfig;\n fetch?: FetcherConfig;\n postProcessor?: PostProcessorFn;\n sampling?: SamplingConfig;\n propagator?: TextMapPropagator;\n instrumentation?: InstrumentationOptions;\n subscribers?: EdgeSubscriber[];\n /** Opt-in data safety controls for sensitive attribute capture */\n dataSafety?: DataSafetyConfig;\n}\n\ninterface EdgeConfigExporter extends EdgeConfigBase {\n exporter: ExporterConfig;\n}\n\ninterface EdgeConfigSpanProcessors extends EdgeConfigBase {\n spanProcessors: SpanProcessor | SpanProcessor[];\n}\n\nexport type EdgeConfig = EdgeConfigExporter | EdgeConfigSpanProcessors;\n\nexport function isSpanProcessorConfig(\n config: EdgeConfig,\n): config is EdgeConfigSpanProcessors {\n return !!(config as EdgeConfigSpanProcessors).spanProcessors;\n}\n\nexport interface ResolvedEdgeConfig extends EdgeConfigBase {\n handlers: Required<HandlerConfig>;\n fetch: Required<FetcherConfig>;\n postProcessor: PostProcessorFn;\n sampling: Required<SamplingConfig<Sampler>>;\n spanProcessors: SpanProcessor[];\n propagator: TextMapPropagator;\n instrumentation: InstrumentationOptions;\n subscribers: EdgeSubscriber[];\n}\n\n/**\n * Function types\n */\nexport type ResolveConfigFn<Env = any> = (\n env: Env,\n trigger: Trigger,\n) => EdgeConfig;\nexport type ConfigurationOption = EdgeConfig | ResolveConfigFn;\n\nexport type PostProcessorFn = (spans: ReadableSpan[]) => ReadableSpan[];\nexport type TailSampleFn = (traceInfo: LocalTrace) => boolean;\n\nexport interface LocalTrace {\n traceId: string;\n spans: ReadableSpan[];\n localRootSpan: ReadableSpan;\n}\n\n/**\n * Span processor with flush support\n */\nexport type TraceFlushableSpanProcessor = SpanProcessor & {\n forceFlush: (traceId?: string) => Promise<void>;\n};\n\n/**\n * Handler instrumentation\n */\nexport interface InitialSpanInfo {\n name: string;\n options: SpanOptions;\n context?: Context;\n}\n\nexport interface HandlerInstrumentation<T extends Trigger, R extends any> {\n getInitialSpanInfo: (trigger: T) => InitialSpanInfo;\n getAttributesFromResult?: (result: Awaited<R>) => Attributes;\n instrumentTrigger?: (trigger: T) => T;\n executionSucces?: (span: Span, trigger: T, result: Awaited<R>) => void;\n executionFailed?: (span: Span, trigger: T, error?: any) => void;\n}\n\n/**\n * Utility types\n */\n\nexport {type Attributes, type Context, type Span, type SpanOptions} from '@opentelemetry/api';\nexport {type ReadableSpan} from '@opentelemetry/sdk-trace-base';","/**\n * Span processor with flush and tail sampling support\n */\n\nimport type { Context } from '@opentelemetry/api';\nimport type {\n ReadableSpan,\n Span,\n SpanExporter,\n SpanProcessor,\n} from '@opentelemetry/sdk-trace-base';\nimport type { PostProcessorFn, TailSampleFn, LocalTrace } from '../types';\n\n/**\n * Span processor that supports flush by trace ID and tail sampling\n */\nexport class SpanProcessorWithFlush implements SpanProcessor {\n private exporter: SpanExporter;\n private postProcessor?: PostProcessorFn;\n private spans: Map<string, ReadableSpan[]> = new Map();\n\n constructor(exporter: SpanExporter, postProcessor?: PostProcessorFn) {\n this.exporter = exporter;\n this.postProcessor = postProcessor;\n }\n\n onStart(_span: Span, _parentContext: Context): void {\n // No-op for now\n }\n\n onEnd(span: ReadableSpan): void {\n const traceId = span.spanContext().traceId;\n\n if (!this.spans.has(traceId)) {\n this.spans.set(traceId, []);\n }\n\n this.spans.get(traceId)!.push(span);\n }\n\n /**\n * Force flush spans for a specific trace\n */\n async forceFlush(traceId?: string): Promise<void> {\n if (traceId) {\n const spans = this.spans.get(traceId);\n if (spans && spans.length > 0) {\n await this.exportSpans(spans);\n this.spans.delete(traceId);\n }\n } else {\n // Flush all traces\n const promises: Promise<void>[] = [];\n for (const [id, spans] of this.spans.entries()) {\n promises.push(this.exportSpans(spans));\n this.spans.delete(id);\n }\n await Promise.all(promises);\n }\n }\n\n async shutdown(): Promise<void> {\n await this.forceFlush();\n if (this.exporter) {\n await this.exporter.shutdown();\n }\n }\n\n /**\n * Export spans with post-processing\n * Errors are caught and logged but don't throw to prevent worker instability\n */\n private async exportSpans(spans: ReadableSpan[]): Promise<void> {\n if (spans.length === 0) return;\n if (!this.exporter) return; // No exporter configured (e.g., in tests)\n\n let processedSpans = spans;\n\n if (this.postProcessor) {\n try {\n processedSpans = this.postProcessor(spans);\n } catch (error) {\n // Post-processor errors should not prevent export\n console.error('[autotel-edge] Post-processor error:', error);\n // Continue with original spans\n processedSpans = spans;\n }\n }\n\n return new Promise((resolve) => {\n this.exporter.export(processedSpans, (result) => {\n if (result.code === 0) {\n // SUCCESS\n resolve();\n } else {\n // Log but don't reject - exporter failures shouldn't crash the worker\n console.error(\n '[autotel-edge] Exporter error:',\n result.error?.message || 'Unknown error',\n );\n resolve(); // Resolve instead of reject to prevent unhandled promise rejection\n }\n });\n });\n }\n}\n\n/**\n * Span processor that supports tail sampling decisions\n */\nexport class TailSamplingSpanProcessor implements SpanProcessor {\n private wrapped: SpanProcessorWithFlush;\n private tailSampler?: TailSampleFn;\n private traces: Map<string, LocalTrace> = new Map();\n\n constructor(\n exporter: SpanExporter,\n postProcessor?: PostProcessorFn,\n tailSampler?: TailSampleFn,\n ) {\n this.wrapped = new SpanProcessorWithFlush(exporter, postProcessor);\n this.tailSampler = tailSampler;\n }\n\n onStart(span: Span, parentContext: Context): void {\n this.wrapped.onStart(span, parentContext);\n }\n\n onEnd(span: ReadableSpan): void {\n const traceId = span.spanContext().traceId;\n const spanId = span.spanContext().spanId;\n const parentSpanId = 'parentSpanId' in span ? span.parentSpanId : undefined;\n\n // Initialize trace if not exists\n if (!this.traces.has(traceId)) {\n this.traces.set(traceId, {\n traceId,\n spans: [],\n localRootSpan: undefined as any, // Will be set when we identify the local root\n });\n }\n\n const trace = this.traces.get(traceId)!;\n\n // Determine if this span is a local root by checking if its parent is in buffered spans\n // A span is a local root if:\n // 1. It has no parentSpanId (definitive root)\n // 2. Its parentSpanId doesn't match any already-buffered span (remote parent = distributed trace entry)\n const hasLocalParent = parentSpanId &&\n trace.spans.some(s => s.spanContext().spanId === parentSpanId);\n\n // Set localRootSpan if this is the local root (no local parent found in buffer)\n if (!hasLocalParent) {\n trace.localRootSpan = span;\n }\n\n trace.spans.push(span); // Buffer the span AFTER checking parent relationships\n\n // Auto-flush decision: only auto-flush for normal traces (no parentSpanId at all)\n // For distributed traces (parentSpanId present), we rely on explicit forceFlush() from instrument.ts\n // This ensures we don't trigger before all spans have been buffered\n const isDefinitiveRoot = !parentSpanId;\n const shouldAutoFlush = isDefinitiveRoot && trace.localRootSpan &&\n trace.localRootSpan.spanContext().spanId === spanId;\n\n if (shouldAutoFlush) {\n if (this.tailSampler) {\n const shouldKeep = this.tailSampler(trace);\n\n if (shouldKeep) {\n // Export ALL buffered spans in the trace\n for (const bufferedSpan of trace.spans) {\n this.wrapped.onEnd(bufferedSpan);\n }\n // Force flush to actually export the spans\n void this.wrapped.forceFlush(traceId);\n }\n // If not keeping, just drop all spans (don't export)\n } else {\n // No tail sampler, export all buffered spans\n for (const bufferedSpan of trace.spans) {\n this.wrapped.onEnd(bufferedSpan);\n }\n // Force flush to actually export the spans\n void this.wrapped.forceFlush(traceId);\n }\n\n // Clean up trace after decision\n this.traces.delete(traceId);\n }\n // If not local root span, just buffer it - don't export yet\n }\n\n async forceFlush(traceId?: string): Promise<void> {\n if (traceId) {\n // Make tail sampling decision for this specific trace before flushing\n const trace = this.traces.get(traceId);\n if (trace) {\n // Ensure localRootSpan is set (fallback to first span if not)\n // This handles distributed traces where no span has undefined parentSpanId\n if (!trace.localRootSpan && trace.spans.length > 0) {\n trace.localRootSpan = trace.spans[0];\n }\n\n if (this.tailSampler) {\n const shouldKeep = this.tailSampler(trace);\n\n if (shouldKeep) {\n // Export ALL buffered spans in the trace\n for (const bufferedSpan of trace.spans) {\n this.wrapped.onEnd(bufferedSpan);\n }\n }\n } else {\n // No tail sampler, export all buffered spans\n for (const bufferedSpan of trace.spans) {\n this.wrapped.onEnd(bufferedSpan);\n }\n }\n\n // Clean up trace after decision\n this.traces.delete(traceId);\n }\n }\n return this.wrapped.forceFlush(traceId);\n }\n\n async shutdown(): Promise<void> {\n this.traces.clear();\n return this.wrapped.shutdown();\n }\n}\n","/**\n * Configuration system for autotel-edge\n */\n\nimport { W3CTraceContextPropagator } from '@opentelemetry/core';\nimport { ParentBasedSampler, AlwaysOnSampler } from '@opentelemetry/sdk-trace-base';\nimport { context as api_context, createContextKey, type Context } from '@opentelemetry/api';\nimport type {\n EdgeConfig,\n ResolvedEdgeConfig,\n ConfigurationOption,\n Trigger,\n ParentRatioSamplingConfig,\n} from '../types';\nimport { isSpanProcessorConfig } from '../types';\nimport { OTLPExporter } from './exporter';\nimport { TailSamplingSpanProcessor } from './spanprocessor';\n\n/**\n * Type for config initialization function\n */\nexport type Initialiser = (env: any, trigger: Trigger) => ResolvedEdgeConfig;\n\n/**\n * Context key for storing config (isolates config per-request)\n */\nconst CONFIG_KEY = createContextKey('autotel-edge-config');\n\n/**\n * Get the currently active config from context\n *\n * This reads the config from the active context, ensuring each request\n * has its own isolated config even when multiple requests are in-flight.\n */\nexport function getActiveConfig(): ResolvedEdgeConfig | null {\n const value = api_context.active().getValue(CONFIG_KEY) as\n | ResolvedEdgeConfig\n | null\n | undefined;\n return value ?? null;\n}\n\n/**\n * Set the active config in context\n *\n * Returns a new context with the config stored. This context should be\n * used with api_context.with() to ensure the config is isolated per-request.\n *\n * @example\n * ```typescript\n * const config = parseConfig({ service: { name: 'my-service' } });\n * const context = setConfig(config);\n *\n * api_context.with(context, () => {\n * // Config is available here via getActiveConfig()\n * });\n * ```\n */\nexport function setConfig(config: ResolvedEdgeConfig): Context {\n return api_context.active().setValue(CONFIG_KEY, config);\n}\n\n/**\n * Parse and validate configuration\n */\nexport function parseConfig(config: EdgeConfig): ResolvedEdgeConfig {\n // Parse head sampler\n const headSampler =\n config.sampling?.headSampler ??\n new ParentBasedSampler({\n root: new AlwaysOnSampler(),\n });\n\n const parsedHeadSampler =\n typeof headSampler === 'object' && 'ratio' in headSampler\n ? createParentRatioSampler(headSampler)\n : headSampler;\n\n // Parse tail sampler (default: keep sampled or error traces)\n const tailSampler =\n config.sampling?.tailSampler ??\n ((traceInfo) => {\n const localRootSpan = traceInfo.localRootSpan;\n const ctx = localRootSpan.spanContext();\n // Keep if sampled or if root span has error\n return (ctx.traceFlags & 1) === 1 || localRootSpan.status.code === 2; // SAMPLED flag | ERROR status\n });\n\n // Parse exporter - use TailSamplingSpanProcessor when tail sampler is present\n const spanProcessors = isSpanProcessorConfig(config)\n ? Array.isArray(config.spanProcessors)\n ? config.spanProcessors\n : [config.spanProcessors]\n : [\n // Use TailSamplingSpanProcessor to enable tail sampling\n new TailSamplingSpanProcessor(\n typeof config.exporter === 'object' && 'url' in config.exporter\n ? new OTLPExporter(config.exporter)\n : config.exporter,\n config.postProcessor,\n tailSampler, // Wire up the tail sampler!\n ),\n ];\n\n // Build resolved config\n const resolved: ResolvedEdgeConfig = {\n service: config.service,\n handlers: {\n fetch: config.handlers?.fetch ?? {},\n },\n fetch: {\n includeTraceContext: config.fetch?.includeTraceContext ?? true,\n },\n postProcessor: config.postProcessor ?? ((spans) => spans),\n sampling: {\n headSampler: parsedHeadSampler,\n tailSampler,\n },\n spanProcessors,\n propagator: config.propagator ?? new W3CTraceContextPropagator(),\n instrumentation: {\n instrumentGlobalFetch: config.instrumentation?.instrumentGlobalFetch ?? true,\n instrumentGlobalCache: config.instrumentation?.instrumentGlobalCache ?? false,\n disabled: config.instrumentation?.disabled ?? false,\n },\n subscribers: config.subscribers ?? [],\n dataSafety: config.dataSafety,\n };\n\n return resolved;\n}\n\n/**\n * Create a parent-based ratio sampler\n */\nfunction createParentRatioSampler(config: ParentRatioSamplingConfig) {\n const { ratio, acceptRemote = true } = config;\n\n // Simple ratio sampler\n const ratioSampler = {\n shouldSample: () => ({\n decision: Math.random() < ratio ? 1 : 0, // RECORD_AND_SAMPLED : NOT_RECORD\n attributes: {},\n }),\n toString: () => `ParentRatioSampler{ratio=${ratio}}`,\n };\n\n if (acceptRemote) {\n return new ParentBasedSampler({ root: ratioSampler as any });\n }\n\n return ratioSampler;\n}\n\n/**\n * Create a config initializer function\n */\nexport function createInitialiser(config: ConfigurationOption): Initialiser {\n if (typeof config === 'function') {\n return (env, trigger) => {\n const conf = parseConfig(config(env, trigger));\n return conf;\n };\n } else {\n const parsed = parseConfig(config);\n return () => parsed;\n }\n}\n"]}
|
package/dist/events.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { E as EdgeEvent, O as OrPromise, F as FunnelStepStatus, a as OutcomeStatus } from './types-
|
|
2
|
-
export {
|
|
1
|
+
import { E as EdgeEvent, O as OrPromise, F as FunnelStepStatus, a as OutcomeStatus } from './types-CZFcIjJ4.js';
|
|
2
|
+
export { b as EdgeFunnelStepEvent, c as EdgeOutcomeEvent, d as EdgeTrackEvent, e as EdgeValueEvent } from './types-CZFcIjJ4.js';
|
|
3
3
|
import '@opentelemetry/api';
|
|
4
4
|
import '@opentelemetry/sdk-trace-base';
|
|
5
5
|
|
package/dist/events.js
CHANGED
package/dist/index.d.ts
CHANGED
|
@@ -5,8 +5,8 @@ import { Resource } from '@opentelemetry/resources';
|
|
|
5
5
|
import { ReadableSpan, TimedEvent, SpanProcessor, SpanExporter, TracerConfig, Sampler } from '@opentelemetry/sdk-trace-base';
|
|
6
6
|
export { ReadableSpan } from '@opentelemetry/sdk-trace-base';
|
|
7
7
|
import { OTLPExporterError } from '@opentelemetry/otlp-exporter-base';
|
|
8
|
-
import { f as OTLPExporterConfig, g as
|
|
9
|
-
export { D as DOConstructorTrigger,
|
|
8
|
+
import { f as OTLPExporterConfig, g as Trigger, R as ResolvedEdgeConfig, C as ConfigurationOption, h as EdgeConfig } from './types-CZFcIjJ4.js';
|
|
9
|
+
export { D as DOConstructorTrigger, i as DataSafetyConfig, j as EdgeSubscriber, k as ExporterConfig, H as HandlerInstrumentation, I as InitialSpanInfo, l as InstrumentationOptions, L as LocalTrace, P as PostProcessorFn, m as ResolveConfigFn, S as SamplingConfig, n as ServiceConfig, T as TailSampleFn, o as TraceFlushableSpanProcessor, W as WorkflowTrigger } from './types-CZFcIjJ4.js';
|
|
10
10
|
export { Buffer } from 'node:buffer';
|
|
11
11
|
export { ParsedError, parseError } from './parse-error.js';
|
|
12
12
|
|
package/dist/index.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
export { OTLPExporter, createInitialiser, getActiveConfig, parseConfig, setConfig } from './chunk-
|
|
1
|
+
export { OTLPExporter, createInitialiser, getActiveConfig, parseConfig, setConfig } from './chunk-D2WERTLK.js';
|
|
2
2
|
export { parseError } from './chunk-M7Z4P5MC.js';
|
|
3
3
|
import { sanitizeAttributes, isAttributeValue, isTimeInput, hrTimeDuration } from '@opentelemetry/core';
|
|
4
4
|
import { SEMATTRS_EXCEPTION_MESSAGE, SEMATTRS_EXCEPTION_TYPE, SEMATTRS_EXCEPTION_STACKTRACE } from '@opentelemetry/semantic-conventions';
|
|
5
|
-
import {
|
|
5
|
+
import { trace, context, ROOT_CONTEXT, SpanStatusCode } from '@opentelemetry/api';
|
|
6
6
|
export { context, propagation } from '@opentelemetry/api';
|
|
7
7
|
import { RandomIdGenerator, SamplingDecision } from '@opentelemetry/sdk-trace-base';
|
|
8
8
|
import { AsyncLocalStorage } from 'async_hooks';
|
package/dist/logger.d.ts
CHANGED
|
@@ -16,6 +16,12 @@ interface EdgeLogger {
|
|
|
16
16
|
error(msg: string, error?: Error | unknown, attrs?: Record<string, any>): void;
|
|
17
17
|
warn(msg: string, attrs?: Record<string, any>): void;
|
|
18
18
|
debug(msg: string, attrs?: Record<string, any>): void;
|
|
19
|
+
/**
|
|
20
|
+
* Create a child logger with merged bindings.
|
|
21
|
+
* Like pino's child() — every log call from the child
|
|
22
|
+
* includes the parent's attrs plus the child's bindings.
|
|
23
|
+
*/
|
|
24
|
+
child(bindings: Record<string, any>): EdgeLogger;
|
|
19
25
|
}
|
|
20
26
|
/**
|
|
21
27
|
* Get the active log level from context (if set)
|
|
@@ -66,6 +72,7 @@ declare function runWithLogLevel<T>(level: LogLevel, callback: () => T): T;
|
|
|
66
72
|
declare function createEdgeLogger(service: string, options?: {
|
|
67
73
|
level?: LogLevel;
|
|
68
74
|
pretty?: boolean;
|
|
75
|
+
bindings?: Record<string, any>;
|
|
69
76
|
}): EdgeLogger;
|
|
70
77
|
/**
|
|
71
78
|
* Helper to get trace context (useful for BYOL - Bring Your Own Logger)
|
package/dist/logger.js
CHANGED
|
@@ -23,6 +23,7 @@ function getTraceContext() {
|
|
|
23
23
|
function createEdgeLogger(service, options) {
|
|
24
24
|
const defaultLevel = options?.level || "info";
|
|
25
25
|
const pretty = options?.pretty || false;
|
|
26
|
+
const defaultBindings = options?.bindings || {};
|
|
26
27
|
const levelPriority = {
|
|
27
28
|
none: -1,
|
|
28
29
|
debug: 0,
|
|
@@ -42,6 +43,7 @@ function createEdgeLogger(service, options) {
|
|
|
42
43
|
level,
|
|
43
44
|
service,
|
|
44
45
|
msg,
|
|
46
|
+
...defaultBindings,
|
|
45
47
|
...attrs,
|
|
46
48
|
...ctx,
|
|
47
49
|
// Auto-inject traceId, spanId, correlationId
|
|
@@ -49,15 +51,19 @@ function createEdgeLogger(service, options) {
|
|
|
49
51
|
};
|
|
50
52
|
if (pretty) {
|
|
51
53
|
const traceInfo = ctx ? ` [${ctx.traceId.slice(0, 8)}.../${ctx.spanId.slice(0, 8)}...]` : "";
|
|
54
|
+
const prettyAttrs = {
|
|
55
|
+
...defaultBindings,
|
|
56
|
+
...attrs
|
|
57
|
+
};
|
|
52
58
|
console.log(
|
|
53
59
|
`[${level.toUpperCase()}]${traceInfo} ${service}: ${msg}`,
|
|
54
|
-
|
|
60
|
+
Object.keys(prettyAttrs).length > 0 ? prettyAttrs : ""
|
|
55
61
|
);
|
|
56
62
|
} else {
|
|
57
63
|
console.log(JSON.stringify(logEntry));
|
|
58
64
|
}
|
|
59
65
|
};
|
|
60
|
-
|
|
66
|
+
const logger = {
|
|
61
67
|
info: (msg, attrs) => log("info", msg, attrs),
|
|
62
68
|
error: (msg, error, attrs) => {
|
|
63
69
|
const errorAttrs = error instanceof Error ? {
|
|
@@ -69,8 +75,14 @@ function createEdgeLogger(service, options) {
|
|
|
69
75
|
log("error", msg, errorAttrs);
|
|
70
76
|
},
|
|
71
77
|
warn: (msg, attrs) => log("warn", msg, attrs),
|
|
72
|
-
debug: (msg, attrs) => log("debug", msg, attrs)
|
|
78
|
+
debug: (msg, attrs) => log("debug", msg, attrs),
|
|
79
|
+
child: (bindings) => createEdgeLogger(service, {
|
|
80
|
+
level: defaultLevel,
|
|
81
|
+
pretty,
|
|
82
|
+
bindings: { ...defaultBindings, ...bindings }
|
|
83
|
+
})
|
|
73
84
|
};
|
|
85
|
+
return logger;
|
|
74
86
|
}
|
|
75
87
|
function getEdgeTraceContext() {
|
|
76
88
|
return getTraceContext();
|
package/dist/logger.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/api/logger.ts"],"names":["api_context"],"mappings":";;;
|
|
1
|
+
{"version":3,"sources":["../src/api/logger.ts"],"names":["api_context"],"mappings":";;;AAwBA,IAAM,aAAA,GAAgB,iBAAiB,wBAAwB,CAAA;AAuBxD,SAAS,iBAAA,GAA0C;AACxD,EAAA,OAAOA,OAAA,CAAY,MAAA,EAAO,CAAE,QAAA,CAAS,aAAa,CAAA;AACpD;AAsBO,SAAS,eAAA,CAAmB,OAAiB,QAAA,EAAsB;AACxE,EAAA,MAAM,MAAMA,OAAA,CAAY,MAAA,EAAO,CAAE,QAAA,CAAS,eAAe,KAAK,CAAA;AAC9D,EAAA,OAAOA,OAAA,CAAY,IAAA,CAAK,GAAA,EAAK,QAAQ,CAAA;AACvC;AAKA,SAAS,eAAA,GAIA;AACP,EAAA,MAAM,IAAA,GAAO,MAAM,aAAA,EAAc;AACjC,EAAA,IAAI,CAAC,MAAM,OAAO,IAAA;AAElB,EAAA,MAAM,GAAA,GAAM,KAAK,WAAA,EAAY;AAC7B,EAAA,OAAO;AAAA,IACL,SAAS,GAAA,CAAI,OAAA;AAAA,IACb,QAAQ,GAAA,CAAI,MAAA;AAAA,IACZ,a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AK,KAAK,CAAA;AAAA,IAEzB,KAAA,EAAO,CAAC,QAAA,KACN,gBAAA,CAAiB,OAAA,EAAS;AAAA,MACxB,KAAA,EAAO,YAAA;AAAA,MACP,MAAA;AAAA,MACA,QAAA,EAAU,EAAE,GAAG,eAAA,EAAiB,GAAG,QAAA;AAAS,KAC7C;AAAA,GACL;AAEA,EAAA,OAAO,MAAA;AACT;AAeO,SAAS,mBAAA,GAAsB;AACpC,EAAA,OAAO,eAAA,EAAgB;AACzB","file":"logger.js","sourcesContent":["/**\n * Zero-dependency structured logger for edge environments\n *\n * This logger is ~100 LOC and provides:\n * - Structured JSON logging\n * - Auto trace context injection (traceId, spanId)\n * - Dynamic log level control (per-request via context)\n * - Level support (info, error, warn, debug)\n * - Zero dependencies (console-based)\n *\n * Unlike Pino/Winston (~500KB), this is <1KB minified!\n */\n\nimport {\n trace,\n context as api_context,\n createContextKey,\n} from '@opentelemetry/api';\n\nexport type LogLevel = 'debug' | 'info' | 'warn' | 'error' | 'none';\n\n/**\n * Context key for storing active log level (enables per-request log levels)\n */\nconst LOG_LEVEL_KEY = createContextKey('autotel-edge-log-level');\n\nexport interface EdgeLogger {\n info(msg: string, attrs?: Record<string, any>): void;\n error(\n msg: string,\n error?: Error | unknown,\n attrs?: Record<string, any>,\n ): void;\n warn(msg: string, attrs?: Record<string, any>): void;\n debug(msg: string, attrs?: Record<string, any>): void;\n /**\n * Create a child logger with merged bindings.\n * Like pino's child() — every log call from the child\n * includes the parent's attrs plus the child's bindings.\n */\n child(bindings: Record<string, any>): EdgeLogger;\n}\n\n/**\n * Get the active log level from context (if set)\n * Falls back to undefined if no log level is set in context\n */\nexport function getActiveLogLevel(): LogLevel | undefined {\n return api_context.active().getValue(LOG_LEVEL_KEY) as LogLevel | undefined;\n}\n\n/**\n * Run a function with a specific log level\n * The log level is stored in OpenTelemetry context and applies to all logger calls within the callback\n *\n * This works in edge runtimes (uses OTel context, not Node.js AsyncLocalStorage)\n *\n * @example\n * ```typescript\n * // Enable debug logging for a specific request\n * runWithLogLevel('debug', () => {\n * log.debug('This will be logged')\n * processRequest()\n * })\n *\n * // Disable logging temporarily\n * runWithLogLevel('none', () => {\n * log.info('This will NOT be logged')\n * })\n * ```\n */\nexport function runWithLogLevel<T>(level: LogLevel, callback: () => T): T {\n const ctx = api_context.active().setValue(LOG_LEVEL_KEY, level);\n return api_context.with(ctx, callback);\n}\n\n/**\n * Get current trace context from active span\n */\nfunction getTraceContext(): {\n traceId: string;\n spanId: string;\n correlationId: string;\n} | null {\n const span = trace.getActiveSpan();\n if (!span) return null;\n\n const ctx = span.spanContext();\n return {\n traceId: ctx.traceId,\n spanId: ctx.spanId,\n correlationId: ctx.traceId.slice(0, 16), // First 16 chars for grouping\n };\n}\n\n/**\n * Create a lightweight structured logger\n *\n * @param service - Service name for logging\n * @param options - Optional configuration\n *\n * @example\n * ```typescript\n * const log = createEdgeLogger('user-service')\n *\n * log.info('Creating user', { email: 'test@example.com' })\n * // Output: {\"level\":\"info\",\"service\":\"user-service\",\"msg\":\"Creating user\",\n * // \"email\":\"test@example.com\",\"traceId\":\"...\",\"spanId\":\"...\"}\n *\n * // Dynamic log level control per-request\n * runWithLogLevel('debug', () => {\n * log.debug('This will be logged even if logger was created with level: \"info\"')\n * })\n * ```\n */\nexport function createEdgeLogger(\n service: string,\n options?: {\n level?: LogLevel;\n pretty?: boolean; // For development\n bindings?: Record<string, any>; // Default attributes merged into every log (used by child())\n },\n): EdgeLogger {\n const defaultLevel = options?.level || 'info';\n const pretty = options?.pretty || false;\n const defaultBindings = options?.bindings || {};\n\n const levelPriority: Record<LogLevel, number> = {\n none: -1,\n debug: 0,\n info: 1,\n warn: 2,\n error: 3,\n };\n\n const shouldLog = (level: LogLevel): boolean => {\n // Priority: context level > options level > 'info' default\n const activeLevel = getActiveLogLevel() ?? defaultLevel;\n\n // 'none' means suppress all logging\n if (activeLevel === 'none') return false;\n\n return levelPriority[level] >= levelPriority[activeLevel];\n };\n\n const log = (\n level: 'info' | 'error' | 'warn' | 'debug',\n msg: string,\n attrs?: Record<string, any>,\n ) => {\n if (!shouldLog(level)) return;\n\n const ctx = getTraceContext();\n const logEntry: Record<string, any> = {\n level,\n service,\n msg,\n ...defaultBindings,\n ...attrs,\n ...ctx, // Auto-inject traceId, spanId, correlationId\n timestamp: new Date().toISOString(),\n };\n\n if (pretty) {\n // Pretty print for development\n const traceInfo = ctx\n ? ` [${ctx.traceId.slice(0, 8)}.../${ctx.spanId.slice(0, 8)}...]`\n : '';\n const prettyAttrs = {\n ...defaultBindings,\n ...attrs,\n };\n console.log(\n `[${level.toUpperCase()}]${traceInfo} ${service}: ${msg}`,\n Object.keys(prettyAttrs).length > 0 ? prettyAttrs : '',\n );\n } else {\n // Structured JSON for production\n console.log(JSON.stringify(logEntry));\n }\n };\n\n const logger: EdgeLogger = {\n info: (msg: string, attrs?: Record<string, any>) => log('info', msg, attrs),\n\n error: (\n msg: string,\n error?: Error | unknown,\n attrs?: Record<string, any>,\n ) => {\n const errorAttrs =\n error instanceof Error\n ? {\n error: error.message,\n stack: error.stack,\n name: error.name,\n ...attrs,\n }\n : { error: String(error), ...attrs };\n\n log('error', msg, errorAttrs);\n },\n\n warn: (msg: string, attrs?: Record<string, any>) => log('warn', msg, attrs),\n\n debug: (msg: string, attrs?: Record<string, any>) =>\n log('debug', msg, attrs),\n\n child: (bindings: Record<string, any>) =>\n createEdgeLogger(service, {\n level: defaultLevel,\n pretty,\n bindings: { ...defaultBindings, ...bindings },\n }),\n };\n\n return logger;\n}\n\n/**\n * Helper to get trace context (useful for BYOL - Bring Your Own Logger)\n *\n * @example\n * ```typescript\n * import bunyan from 'bunyan'\n * import { getEdgeTraceContext } from 'autotel-edge/api/logger'\n *\n * const bunyanLogger = bunyan.createLogger({ name: 'myapp' })\n * const ctx = getEdgeTraceContext()\n * bunyanLogger.info({ ...ctx, email: 'test@example.com' }, 'Creating user')\n * ```\n */\nexport function getEdgeTraceContext() {\n return getTraceContext();\n}\n"]}
|
package/dist/sampling.d.ts
CHANGED
|
@@ -193,4 +193,4 @@ interface HandlerInstrumentation<T extends Trigger, R extends any> {
|
|
|
193
193
|
executionFailed?: (span: Span, trigger: T, error?: any) => void;
|
|
194
194
|
}
|
|
195
195
|
|
|
196
|
-
export type { ConfigurationOption as C, DOConstructorTrigger as D, EdgeEvent as E, FunnelStepStatus as F, HandlerInstrumentation as H,
|
|
196
|
+
export type { ConfigurationOption as C, DOConstructorTrigger as D, EdgeEvent as E, FunnelStepStatus as F, HandlerInstrumentation as H, InitialSpanInfo as I, LocalTrace as L, OrPromise as O, PostProcessorFn as P, ResolvedEdgeConfig as R, SamplingConfig as S, TailSampleFn as T, WorkflowTrigger as W, OutcomeStatus as a, EdgeFunnelStepEvent as b, EdgeOutcomeEvent as c, EdgeTrackEvent as d, EdgeValueEvent as e, OTLPExporterConfig as f, Trigger as g, EdgeConfig as h, DataSafetyConfig as i, EdgeSubscriber as j, ExporterConfig as k, InstrumentationOptions as l, ResolveConfigFn as m, ServiceConfig as n, TraceFlushableSpanProcessor as o };
|
package/package.json
CHANGED
package/src/api/logger.test.ts
CHANGED
|
@@ -123,7 +123,9 @@ describe('Edge Logger', () => {
|
|
|
123
123
|
};
|
|
124
124
|
|
|
125
125
|
// Mock trace.getActiveSpan to return our span
|
|
126
|
-
const getActiveSpanSpy = vi
|
|
126
|
+
const getActiveSpanSpy = vi
|
|
127
|
+
.spyOn(trace, 'getActiveSpan')
|
|
128
|
+
.mockReturnValue(mockSpan as any);
|
|
127
129
|
|
|
128
130
|
logger.info('message with trace');
|
|
129
131
|
|
|
@@ -195,7 +197,9 @@ describe('Edge Logger', () => {
|
|
|
195
197
|
expect(consoleLogSpy).toHaveBeenCalledOnce();
|
|
196
198
|
const logOutput = JSON.parse(consoleLogSpy.mock.calls[0][0]);
|
|
197
199
|
|
|
198
|
-
expect(logOutput.timestamp).toMatch(
|
|
200
|
+
expect(logOutput.timestamp).toMatch(
|
|
201
|
+
/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\.\d{3}Z$/,
|
|
202
|
+
);
|
|
199
203
|
});
|
|
200
204
|
});
|
|
201
205
|
|
|
@@ -264,6 +268,104 @@ describe('Edge Logger', () => {
|
|
|
264
268
|
});
|
|
265
269
|
});
|
|
266
270
|
|
|
271
|
+
describe('child()', () => {
|
|
272
|
+
it('should create a child logger with merged bindings', () => {
|
|
273
|
+
const logger = createEdgeLogger('test-service');
|
|
274
|
+
const child = logger.child({ requestId: 'req-123' });
|
|
275
|
+
|
|
276
|
+
child.info('child message', { extra: 'data' });
|
|
277
|
+
|
|
278
|
+
expect(consoleLogSpy).toHaveBeenCalledOnce();
|
|
279
|
+
const logOutput = JSON.parse(consoleLogSpy.mock.calls[0][0]);
|
|
280
|
+
|
|
281
|
+
expect(logOutput).toMatchObject({
|
|
282
|
+
level: 'info',
|
|
283
|
+
service: 'test-service',
|
|
284
|
+
msg: 'child message',
|
|
285
|
+
requestId: 'req-123',
|
|
286
|
+
extra: 'data',
|
|
287
|
+
});
|
|
288
|
+
});
|
|
289
|
+
|
|
290
|
+
it('should merge parent bindings with child bindings', () => {
|
|
291
|
+
const logger = createEdgeLogger('test-service');
|
|
292
|
+
const child = logger.child({ requestId: 'req-123' });
|
|
293
|
+
const grandchild = child.child({ userId: 'user-456' });
|
|
294
|
+
|
|
295
|
+
grandchild.info('deep message');
|
|
296
|
+
|
|
297
|
+
expect(consoleLogSpy).toHaveBeenCalledOnce();
|
|
298
|
+
const logOutput = JSON.parse(consoleLogSpy.mock.calls[0][0]);
|
|
299
|
+
|
|
300
|
+
expect(logOutput).toMatchObject({
|
|
301
|
+
msg: 'deep message',
|
|
302
|
+
requestId: 'req-123',
|
|
303
|
+
userId: 'user-456',
|
|
304
|
+
});
|
|
305
|
+
});
|
|
306
|
+
|
|
307
|
+
it('should allow child attrs to override bindings', () => {
|
|
308
|
+
const logger = createEdgeLogger('test-service');
|
|
309
|
+
const child = logger.child({ env: 'staging' });
|
|
310
|
+
|
|
311
|
+
child.info('override', { env: 'production' });
|
|
312
|
+
|
|
313
|
+
expect(consoleLogSpy).toHaveBeenCalledOnce();
|
|
314
|
+
const logOutput = JSON.parse(consoleLogSpy.mock.calls[0][0]);
|
|
315
|
+
|
|
316
|
+
// Call-time attrs override bindings
|
|
317
|
+
expect(logOutput.env).toBe('production');
|
|
318
|
+
});
|
|
319
|
+
|
|
320
|
+
it('should return an EdgeLogger from child()', () => {
|
|
321
|
+
const logger = createEdgeLogger('test-service');
|
|
322
|
+
const child = logger.child({ key: 'val' });
|
|
323
|
+
|
|
324
|
+
expect(child.info).toBeDefined();
|
|
325
|
+
expect(child.error).toBeDefined();
|
|
326
|
+
expect(child.warn).toBeDefined();
|
|
327
|
+
expect(child.debug).toBeDefined();
|
|
328
|
+
expect(child.child).toBeDefined();
|
|
329
|
+
});
|
|
330
|
+
|
|
331
|
+
it('should chain child() calls', () => {
|
|
332
|
+
const logger = createEdgeLogger('test-service');
|
|
333
|
+
const child = logger.child({ a: 1 }).child({ b: 2 }).child({ c: 3 });
|
|
334
|
+
|
|
335
|
+
child.info('chained');
|
|
336
|
+
|
|
337
|
+
expect(consoleLogSpy).toHaveBeenCalledOnce();
|
|
338
|
+
const logOutput = JSON.parse(consoleLogSpy.mock.calls[0][0]);
|
|
339
|
+
|
|
340
|
+
expect(logOutput).toMatchObject({ a: 1, b: 2, c: 3 });
|
|
341
|
+
});
|
|
342
|
+
|
|
343
|
+
it('should not affect parent logger', () => {
|
|
344
|
+
const logger = createEdgeLogger('test-service');
|
|
345
|
+
const child = logger.child({ childOnly: 'yes' });
|
|
346
|
+
|
|
347
|
+
logger.info('parent message');
|
|
348
|
+
|
|
349
|
+
expect(consoleLogSpy).toHaveBeenCalledOnce();
|
|
350
|
+
const logOutput = JSON.parse(consoleLogSpy.mock.calls[0][0]);
|
|
351
|
+
|
|
352
|
+
expect(logOutput.childOnly).toBeUndefined();
|
|
353
|
+
});
|
|
354
|
+
|
|
355
|
+
it('should include child bindings in pretty mode', () => {
|
|
356
|
+
const logger = createEdgeLogger('test-service', { pretty: true });
|
|
357
|
+
const child = logger.child({ requestId: 'req-123' });
|
|
358
|
+
|
|
359
|
+
child.info('pretty child', { extra: 'data' });
|
|
360
|
+
|
|
361
|
+
expect(consoleLogSpy).toHaveBeenCalledOnce();
|
|
362
|
+
expect(consoleLogSpy.mock.calls[0][1]).toMatchObject({
|
|
363
|
+
requestId: 'req-123',
|
|
364
|
+
extra: 'data',
|
|
365
|
+
});
|
|
366
|
+
});
|
|
367
|
+
});
|
|
368
|
+
|
|
267
369
|
describe('Dynamic log level control', () => {
|
|
268
370
|
it('should override log level via runWithLogLevel', () => {
|
|
269
371
|
const logger = createEdgeLogger('test-service', { level: 'info' });
|
package/src/api/logger.ts
CHANGED
|
@@ -11,7 +11,11 @@
|
|
|
11
11
|
* Unlike Pino/Winston (~500KB), this is <1KB minified!
|
|
12
12
|
*/
|
|
13
13
|
|
|
14
|
-
import {
|
|
14
|
+
import {
|
|
15
|
+
trace,
|
|
16
|
+
context as api_context,
|
|
17
|
+
createContextKey,
|
|
18
|
+
} from '@opentelemetry/api';
|
|
15
19
|
|
|
16
20
|
export type LogLevel = 'debug' | 'info' | 'warn' | 'error' | 'none';
|
|
17
21
|
|
|
@@ -22,9 +26,19 @@ const LOG_LEVEL_KEY = createContextKey('autotel-edge-log-level');
|
|
|
22
26
|
|
|
23
27
|
export interface EdgeLogger {
|
|
24
28
|
info(msg: string, attrs?: Record<string, any>): void;
|
|
25
|
-
error(
|
|
29
|
+
error(
|
|
30
|
+
msg: string,
|
|
31
|
+
error?: Error | unknown,
|
|
32
|
+
attrs?: Record<string, any>,
|
|
33
|
+
): void;
|
|
26
34
|
warn(msg: string, attrs?: Record<string, any>): void;
|
|
27
35
|
debug(msg: string, attrs?: Record<string, any>): void;
|
|
36
|
+
/**
|
|
37
|
+
* Create a child logger with merged bindings.
|
|
38
|
+
* Like pino's child() — every log call from the child
|
|
39
|
+
* includes the parent's attrs plus the child's bindings.
|
|
40
|
+
*/
|
|
41
|
+
child(bindings: Record<string, any>): EdgeLogger;
|
|
28
42
|
}
|
|
29
43
|
|
|
30
44
|
/**
|
|
@@ -63,9 +77,11 @@ export function runWithLogLevel<T>(level: LogLevel, callback: () => T): T {
|
|
|
63
77
|
/**
|
|
64
78
|
* Get current trace context from active span
|
|
65
79
|
*/
|
|
66
|
-
function getTraceContext():
|
|
67
|
-
|
|
68
|
-
|
|
80
|
+
function getTraceContext(): {
|
|
81
|
+
traceId: string;
|
|
82
|
+
spanId: string;
|
|
83
|
+
correlationId: string;
|
|
84
|
+
} | null {
|
|
69
85
|
const span = trace.getActiveSpan();
|
|
70
86
|
if (!span) return null;
|
|
71
87
|
|
|
@@ -102,10 +118,12 @@ export function createEdgeLogger(
|
|
|
102
118
|
options?: {
|
|
103
119
|
level?: LogLevel;
|
|
104
120
|
pretty?: boolean; // For development
|
|
121
|
+
bindings?: Record<string, any>; // Default attributes merged into every log (used by child())
|
|
105
122
|
},
|
|
106
123
|
): EdgeLogger {
|
|
107
124
|
const defaultLevel = options?.level || 'info';
|
|
108
125
|
const pretty = options?.pretty || false;
|
|
126
|
+
const defaultBindings = options?.bindings || {};
|
|
109
127
|
|
|
110
128
|
const levelPriority: Record<LogLevel, number> = {
|
|
111
129
|
none: -1,
|
|
@@ -137,6 +155,7 @@ export function createEdgeLogger(
|
|
|
137
155
|
level,
|
|
138
156
|
service,
|
|
139
157
|
msg,
|
|
158
|
+
...defaultBindings,
|
|
140
159
|
...attrs,
|
|
141
160
|
...ctx, // Auto-inject traceId, spanId, correlationId
|
|
142
161
|
timestamp: new Date().toISOString(),
|
|
@@ -147,9 +166,13 @@ export function createEdgeLogger(
|
|
|
147
166
|
const traceInfo = ctx
|
|
148
167
|
? ` [${ctx.traceId.slice(0, 8)}.../${ctx.spanId.slice(0, 8)}...]`
|
|
149
168
|
: '';
|
|
169
|
+
const prettyAttrs = {
|
|
170
|
+
...defaultBindings,
|
|
171
|
+
...attrs,
|
|
172
|
+
};
|
|
150
173
|
console.log(
|
|
151
174
|
`[${level.toUpperCase()}]${traceInfo} ${service}: ${msg}`,
|
|
152
|
-
|
|
175
|
+
Object.keys(prettyAttrs).length > 0 ? prettyAttrs : '',
|
|
153
176
|
);
|
|
154
177
|
} else {
|
|
155
178
|
// Structured JSON for production
|
|
@@ -157,26 +180,41 @@ export function createEdgeLogger(
|
|
|
157
180
|
}
|
|
158
181
|
};
|
|
159
182
|
|
|
160
|
-
|
|
183
|
+
const logger: EdgeLogger = {
|
|
161
184
|
info: (msg: string, attrs?: Record<string, any>) => log('info', msg, attrs),
|
|
162
185
|
|
|
163
|
-
error: (
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
186
|
+
error: (
|
|
187
|
+
msg: string,
|
|
188
|
+
error?: Error | unknown,
|
|
189
|
+
attrs?: Record<string, any>,
|
|
190
|
+
) => {
|
|
191
|
+
const errorAttrs =
|
|
192
|
+
error instanceof Error
|
|
193
|
+
? {
|
|
194
|
+
error: error.message,
|
|
195
|
+
stack: error.stack,
|
|
196
|
+
name: error.name,
|
|
197
|
+
...attrs,
|
|
198
|
+
}
|
|
199
|
+
: { error: String(error), ...attrs };
|
|
172
200
|
|
|
173
201
|
log('error', msg, errorAttrs);
|
|
174
202
|
},
|
|
175
203
|
|
|
176
204
|
warn: (msg: string, attrs?: Record<string, any>) => log('warn', msg, attrs),
|
|
177
205
|
|
|
178
|
-
debug: (msg: string, attrs?: Record<string, any>) =>
|
|
206
|
+
debug: (msg: string, attrs?: Record<string, any>) =>
|
|
207
|
+
log('debug', msg, attrs),
|
|
208
|
+
|
|
209
|
+
child: (bindings: Record<string, any>) =>
|
|
210
|
+
createEdgeLogger(service, {
|
|
211
|
+
level: defaultLevel,
|
|
212
|
+
pretty,
|
|
213
|
+
bindings: { ...defaultBindings, ...bindings },
|
|
214
|
+
}),
|
|
179
215
|
};
|
|
216
|
+
|
|
217
|
+
return logger;
|
|
180
218
|
}
|
|
181
219
|
|
|
182
220
|
/**
|