@safaricom-mxl/effect-sdk 0.0.16 → 0.0.17
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/browser/index.d.ts.map +1 -1
- package/dist/browser/index.js +1 -39
- package/dist/browser/index.js.map +1 -1
- package/dist/cloudflare/index.js +48 -8
- package/dist/cloudflare/index.js.map +1 -1
- package/dist/{index-BF4-zL-9.d.mts → index-BmEukuO2.d.mts} +14 -4
- package/dist/index-BmEukuO2.d.mts.map +1 -0
- package/dist/index.server.d.mts +1 -1
- package/dist/index.server.mjs +1 -1
- package/dist/server/index.d.mts +1 -1
- package/dist/server/index.mjs +1 -1
- package/dist/{server-DU685moi.mjs → server-BcUHBdnP.mjs} +43 -9
- package/dist/server-BcUHBdnP.mjs.map +1 -0
- package/package.json +15 -14
- package/LICENSE +0 -201
- package/dist/index-BF4-zL-9.d.mts.map +0 -1
- package/dist/server-DU685moi.mjs.map +0 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"server-BcUHBdnP.mjs","names":["stringOrUndefined","uuidv7","EnvConfig.sdkDisabled","EnvConfig.endpoint","endpoint","EnvConfig.otlpHeaders","EnvConfig.serviceVersion","serviceVersion","EnvConfig.environment","environment","EnvConfig.otelServiceName","EnvConfig.otelResourceAttributes","layer","make","otelLayer","eventsLayer","traceApi","otelContext","Option","headerValue","traceApi","otelContext","Option","traceApi","otelContext"],"sources":["../src/server/otel-context-bridge.ts","../src/server/otlp.ts","../src/server/config.ts","../src/server/platform.ts","../src/server/resource.ts","../src/server/layer.ts","../src/shared/product-event.ts","../src/version.ts","../src/server/events.ts","../src/server/flushable.ts","../src/server/http-middleware.ts","../src/server/trace-correlation.ts","../src/server/logging.ts","../src/server/http-tracing.ts","../src/server/jobs.ts","../src/server/evlog-bridge.ts","../src/shared/dependency-spans.ts"],"sourcesContent":["import { AsyncLocalStorageContextManager } from \"@opentelemetry/context-async-hooks\";\nimport * as Otel from \"@opentelemetry/api\";\nimport { Effect, Layer } from \"effect\";\nimport * as Tracer from \"effect/Tracer\";\n\nconst evaluate = \"~effect/Effect/evaluate\" as const;\n\nlet contextManagerInstalled = false;\n\n/**\n * Install AsyncLocalStorage so `Otel.context.with` actually propagates.\n * Does not replace a context manager the host app already registered.\n */\nexport function ensureOtelContextManager(): void {\n if (contextManagerInstalled) return;\n const manager = new AsyncLocalStorageContextManager();\n manager.enable();\n if (!Otel.context.setGlobalContextManager(manager)) {\n manager.disable();\n contextManagerInstalled = true;\n return;\n }\n contextManagerInstalled = true;\n}\n\nexport function formatTraceparent(span: Tracer.AnySpan): string {\n const flags = span.sampled ? \"01\" : \"00\";\n return `00-${span.traceId}-${span.spanId}-${flags}`;\n}\n\nexport function buildTraceCarrierFromSpan(\n span: Tracer.AnySpan,\n headers?: Record<string, string>\n): Record<string, string> {\n const carrier: Record<string, string> = {\n traceparent: formatTraceparent(span),\n };\n\n if (headers?.tracestate) {\n carrier.tracestate = headers.tracestate;\n }\n if (headers?.baggage) {\n carrier.baggage = headers.baggage;\n }\n\n return carrier;\n}\n\n/**\n * Put Effect span ids on the global OpenTelemetry context.\n *\n * Id-only `setSpanContext`. Live `Otel.Span` objects come from\n * `OtelTracer.currentOtelSpan` in Effect space, not from a private TypeId.\n */\nexport function effectSpanToOtelContext(\n activeContext: Otel.Context,\n span: Tracer.AnySpan\n): Otel.Context {\n return Otel.trace.setSpanContext(activeContext, {\n isRemote: span._tag === \"ExternalSpan\",\n spanId: span.spanId,\n traceFlags: span.sampled ? Otel.TraceFlags.SAMPLED : Otel.TraceFlags.NONE,\n traceId: span.traceId,\n });\n}\n\n/**\n * Wrap a tracer so Effect spans activate global `@opentelemetry/api` context.\n *\n * Prefer this over `Otlp.layerJson({ tracerContext })`. That callback receives\n * `(primitive, span)` and must return the evaluation, but `EffectPrimitive`\n * only evaluates with a `fiber`. Keep this wrap until Effect passes fiber.\n */\nexport function wrapTracerWithOtelContextBridge(\n base: Tracer.Tracer\n): Tracer.Tracer {\n ensureOtelContextManager();\n const existingContext = base.context;\n\n return Tracer.make({\n span(options) {\n return base.span(options);\n },\n context(primitive, fiber) {\n if (fiber.cache.span === undefined) {\n if (existingContext) {\n return existingContext(primitive, fiber);\n }\n return primitive[evaluate](fiber);\n }\n\n return Otel.context.with(\n effectSpanToOtelContext(Otel.context.active(), fiber.cache.span),\n () => {\n if (existingContext) {\n return existingContext(primitive, fiber);\n }\n return primitive[evaluate](fiber);\n }\n );\n },\n });\n}\n\n/**\n * Layer that wraps the configured Effect tracer with a global OTel context bridge.\n *\n * Must be provided over `Otlp.layerJson` so queue propagation, log correlation,\n * and outbound W3C headers see the active server span.\n */\nexport const otelGlobalContextBridgeLayer = Layer.effect(\n Tracer.Tracer,\n Effect.gen(function* () {\n const base = yield* Tracer.Tracer;\n return wrapTracerWithOtelContextBridge(base);\n })\n);\n","export function normalizeOtlpBaseUrl(url: string): string {\n const trimmed = url.replace(/\\/$/, \"\");\n if (trimmed.endsWith(\"/v1/traces\") || trimmed.endsWith(\"/v1/logs\")) {\n return trimmed.replace(/\\/v1\\/(traces|logs|metrics)$/, \"\");\n }\n return trimmed;\n}\n","import { Config, Effect, Option } from \"effect\";\n\nconst DEFAULT_OTLP_ENDPOINT = \"http://127.0.0.1:4318\";\n\n/** Resolve the OTLP exporter endpoint from standard env vars. */\nexport const endpoint = Effect.gen(function* () {\n const otlp = yield* Config.option(\n Config.String(\"OTEL_EXPORTER_OTLP_ENDPOINT\")\n );\n if (Option.isSome(otlp)) return otlp;\n return yield* Config.option(Config.String(\"OTLP_ENDPOINT\"));\n});\n\nexport const defaultOtlpEndpoint = DEFAULT_OTLP_ENDPOINT;\n\nexport const sdkDisabled = Config.Boolean(\"OTEL_SDK_DISABLED\").pipe(\n Config.withDefault(false)\n);\n\n/**\n * Resolve service version / commit SHA from platform-specific env vars.\n *\n * Priority: npm_package_version > COMMIT_SHA > RAILWAY_GIT_COMMIT_SHA >\n * VERCEL_GIT_COMMIT_SHA > CF_PAGES_COMMIT_SHA > RENDER_GIT_COMMIT\n */\nexport const serviceVersion = Config.option(\n Config.String(\"npm_package_version\").pipe(\n Config.orElse(() => Config.String(\"COMMIT_SHA\")),\n Config.orElse(() => Config.String(\"RAILWAY_GIT_COMMIT_SHA\")),\n Config.orElse(() => Config.String(\"VERCEL_GIT_COMMIT_SHA\")),\n Config.orElse(() => Config.String(\"CF_PAGES_COMMIT_SHA\")),\n Config.orElse(() => Config.String(\"RENDER_GIT_COMMIT\"))\n )\n);\n\n/**\n * Resolve deployment environment from env vars.\n *\n * Priority: NODE_ENV > DEPLOYMENT_ENV > \"development\"\n */\nexport const environment = Config.String(\"NODE_ENV\").pipe(\n Config.orElse(() => Config.String(\"DEPLOYMENT_ENV\")),\n Config.withDefault(\"development\")\n);\n\n/** OTel-standard service name override. */\nexport const otelServiceName = Config.option(\n Config.String(\"OTEL_SERVICE_NAME\")\n);\n\n/**\n * Parse the OTel-standard `OTEL_RESOURCE_ATTRIBUTES` env var.\n *\n * Format per the OTel spec: comma-separated `key=value` pairs, values may be\n * URL-encoded.\n */\nexport const parseOtelResourceAttributes = (\n input: string\n): Record<string, string> => {\n const result: Record<string, string> = {};\n for (const pair of input.split(\",\")) {\n const eq = pair.indexOf(\"=\");\n if (eq === -1) continue;\n const key = pair.slice(0, eq).trim();\n if (!key) continue;\n const raw = pair.slice(eq + 1).trim();\n let value = raw;\n try {\n value = decodeURIComponent(raw);\n } catch {\n // Fall back to raw string when decoding fails.\n }\n result[key] = value;\n }\n return result;\n};\n\n/** Resolve and parse `OTEL_RESOURCE_ATTRIBUTES`. */\nexport const otelResourceAttributes = Effect.gen(function* () {\n const raw = yield* Config.option(Config.String(\"OTEL_RESOURCE_ATTRIBUTES\"));\n return Option.match(raw, {\n onNone: () => ({}) as Record<string, string>,\n onSome: (value) => parseOtelResourceAttributes(value),\n });\n});\n\n/**\n * Parse `OTEL_EXPORTER_OTLP_HEADERS` (`key=value,key2=value2`) into a header map.\n */\nexport const parseOtlpHeaders = (input: string): Record<string, string> => {\n const result: Record<string, string> = {};\n for (const pair of input.split(\",\")) {\n const eq = pair.indexOf(\"=\");\n if (eq === -1) continue;\n const key = pair.slice(0, eq).trim();\n if (!key) continue;\n const raw = pair.slice(eq + 1).trim();\n try {\n result[key] = decodeURIComponent(raw);\n } catch {\n result[key] = raw;\n }\n }\n return result;\n};\n\n/** Resolve OTLP export headers from env. */\nexport const otlpHeaders = Effect.gen(function* () {\n const raw = yield* Config.option(Config.String(\"OTEL_EXPORTER_OTLP_HEADERS\"));\n return Option.match(raw, {\n onNone: () => ({}) as Record<string, string>,\n onSome: (value) => parseOtlpHeaders(value),\n });\n});\n","import { Match } from \"effect\";\nimport { platform, provider, runtime } from \"std-env\";\n\nexport interface PlatformInputs {\n readonly runtime: string;\n readonly provider: string;\n readonly platform: string;\n readonly arch: string;\n readonly env: Readonly<Record<string, string | undefined>>;\n}\n\ntype Attrs = Record<string, string>;\nconst empty: Attrs = {};\n\nconst runtimeAttrs = (rt: string): Attrs =>\n Match.value(rt).pipe(\n Match.when(\"node\", () => ({ \"process.runtime.name\": \"nodejs\" })),\n Match.whenOr(\"bun\", \"deno\", \"workerd\", \"edge-light\", \"fastly\", (name) => ({\n \"process.runtime.name\": name,\n })),\n Match.orElse((): Attrs => empty)\n );\n\nconst osAttrs = (plat: string): Attrs =>\n Match.value(plat).pipe(\n Match.when(\"win32\", () => ({ \"os.type\": \"windows\" })),\n Match.whenOr(\"darwin\", \"linux\", \"freebsd\", \"openbsd\", \"netbsd\", (p) => ({\n \"os.type\": p,\n })),\n Match.orElse((): Attrs => empty)\n );\n\nconst archAttrs = (a: string): Attrs =>\n a === \"\"\n ? empty\n : {\n \"host.arch\": Match.value(a).pipe(\n Match.when(\"x64\", () => \"amd64\"),\n Match.when(\"ia32\", () => \"x86\"),\n Match.orElse((other) => other)\n ),\n };\n\nconst lambdaAttrs = (env: PlatformInputs[\"env\"]): Attrs => ({\n \"cloud.provider\": \"aws\",\n \"cloud.platform\": \"aws_lambda\",\n \"faas.name\": env.AWS_LAMBDA_FUNCTION_NAME!,\n ...(env.AWS_LAMBDA_FUNCTION_VERSION && {\n \"faas.version\": env.AWS_LAMBDA_FUNCTION_VERSION,\n }),\n ...(env.AWS_LAMBDA_LOG_STREAM_NAME && {\n \"faas.instance\": env.AWS_LAMBDA_LOG_STREAM_NAME,\n }),\n ...(env.AWS_REGION\n ? { \"cloud.region\": env.AWS_REGION }\n : env.AWS_DEFAULT_REGION\n ? { \"cloud.region\": env.AWS_DEFAULT_REGION }\n : {}),\n});\n\nconst providerAttrs = (prov: string, env: PlatformInputs[\"env\"]): Attrs =>\n Match.value(prov).pipe(\n Match.when(\"cloudflare_workers\", (): Attrs => ({\n \"cloud.provider\": \"cloudflare\",\n \"cloud.platform\": \"cloudflare.workers\",\n })),\n Match.when(\"cloudflare_pages\", (): Attrs => ({\n \"cloud.provider\": \"cloudflare\",\n \"cloud.platform\": \"cloudflare.pages\",\n })),\n Match.when(\"vercel\", (): Attrs => ({\n \"cloud.provider\": \"vercel\",\n \"cloud.platform\": \"vercel\",\n ...(env.VERCEL_REGION && { \"cloud.region\": env.VERCEL_REGION }),\n ...(env.VERCEL_DEPLOYMENT_ID && {\n \"faas.instance\": env.VERCEL_DEPLOYMENT_ID,\n }),\n })),\n Match.when(\"netlify\", (): Attrs => ({\n \"cloud.provider\": \"netlify\",\n \"cloud.platform\": \"netlify\",\n })),\n Match.whenOr(\"google_cloudrun\", \"google_cloudrun_job\", (): Attrs => ({\n \"cloud.provider\": \"gcp\",\n \"cloud.platform\": \"gcp_cloud_run\",\n ...(env.K_SERVICE && { \"faas.name\": env.K_SERVICE }),\n ...(env.K_REVISION && { \"faas.version\": env.K_REVISION }),\n ...(env.CLOUD_RUN_REGION && { \"cloud.region\": env.CLOUD_RUN_REGION }),\n })),\n Match.when(\"firebase_app_hosting\", (): Attrs => ({\n \"cloud.provider\": \"gcp\",\n \"cloud.platform\": \"gcp_firebase_app_hosting\",\n })),\n Match.when(\"aws_amplify\", (): Attrs => ({\n \"cloud.provider\": \"aws\",\n \"cloud.platform\": \"aws_amplify\",\n })),\n Match.when(\"deno-deploy\", (): Attrs => ({\n \"cloud.provider\": \"deno\",\n \"cloud.platform\": \"deno_deploy\",\n ...(env.DENO_REGION && { \"cloud.region\": env.DENO_REGION }),\n ...(env.DENO_DEPLOYMENT_ID && {\n \"faas.instance\": env.DENO_DEPLOYMENT_ID,\n }),\n })),\n Match.when(\"render\", (): Attrs => ({\n \"cloud.provider\": \"render\",\n \"cloud.platform\": \"render\",\n ...(env.RENDER_INSTANCE_ID && {\n \"faas.instance\": env.RENDER_INSTANCE_ID,\n }),\n })),\n Match.when(\"railway\", (): Attrs => ({\n \"cloud.provider\": \"railway\",\n \"cloud.platform\": \"railway\",\n ...(env.RAILWAY_REPLICA_ID && {\n \"faas.instance\": env.RAILWAY_REPLICA_ID,\n }),\n })),\n Match.when(\"edgeone_pages\", (): Attrs => ({\n \"cloud.provider\": \"tencent_cloud\",\n \"cloud.platform\": \"tencent_edgeone_pages\",\n })),\n Match.orElse((): Attrs => empty)\n );\n\nconst workerdFallback = (rt: string, alreadyResolved: boolean): Attrs =>\n rt === \"workerd\" && !alreadyResolved\n ? {\n \"cloud.provider\": \"cloudflare\",\n \"cloud.platform\": \"cloudflare.workers\",\n }\n : empty;\n\nconst vercelEdgeFallback = (\n rt: string,\n alreadyResolved: boolean,\n env: PlatformInputs[\"env\"]\n): Attrs =>\n rt === \"edge-light\" && !alreadyResolved && env.VERCEL\n ? { \"cloud.provider\": \"vercel\", \"cloud.platform\": \"vercel\" }\n : empty;\n\nexport const derivePlatformAttributes = (\n inputs: PlatformInputs\n): PlatformAttributes => {\n const { runtime: rt, provider: prov, platform: plat, arch, env } = inputs;\n\n const cloudAttrs = env.AWS_LAMBDA_FUNCTION_NAME\n ? lambdaAttrs(env)\n : providerAttrs(prov, env);\n const cloudResolved = \"cloud.provider\" in cloudAttrs;\n\n return {\n ...(rt && { \"mxl.runtime\": rt }),\n ...(prov && { \"mxl.provider\": prov }),\n ...runtimeAttrs(rt),\n ...osAttrs(plat),\n ...archAttrs(arch),\n ...cloudAttrs,\n ...workerdFallback(rt, cloudResolved),\n ...vercelEdgeFallback(rt, cloudResolved, env),\n };\n};\n\nexport type PlatformAttributes = Attrs;\n\nconst PLATFORM_ENV_KEYS = [\n \"AWS_LAMBDA_FUNCTION_NAME\",\n \"AWS_LAMBDA_FUNCTION_VERSION\",\n \"AWS_LAMBDA_LOG_STREAM_NAME\",\n \"AWS_REGION\",\n \"AWS_DEFAULT_REGION\",\n \"VERCEL\",\n \"VERCEL_REGION\",\n \"VERCEL_DEPLOYMENT_ID\",\n \"K_SERVICE\",\n \"K_REVISION\",\n \"CLOUD_RUN_REGION\",\n \"DENO_REGION\",\n \"DENO_DEPLOYMENT_ID\",\n \"RENDER_INSTANCE_ID\",\n \"RAILWAY_REPLICA_ID\",\n] as const;\n\nexport const getAutoPlatformAttributes = (): PlatformAttributes => {\n const proc = (\n globalThis as { process?: { env?: Record<string, string>; arch?: string } }\n ).process;\n const procEnv = proc?.env ?? {};\n const env: Record<string, string | undefined> = {};\n for (const key of PLATFORM_ENV_KEYS) env[key] = procEnv[key];\n\n return derivePlatformAttributes({\n runtime: runtime ?? \"\",\n provider: provider ?? \"\",\n platform: platform ?? \"\",\n arch: proc?.arch ?? \"\",\n env,\n });\n};\n","import { v7 as uuidv7 } from \"uuid\";\nimport { Effect, Option } from \"effect\";\n\nimport * as EnvConfig from \"./config.js\";\nimport { getAutoPlatformAttributes } from \"./platform.js\";\n\nconst stringOrUndefined = (value: unknown): string | undefined =>\n typeof value === \"string\" && value.length > 0 ? value : undefined;\n\nconst DEFAULT_VCS_REPOSITORY_URL =\n \"https://gitlab.safaricom.co.ke/mxl/apm/mxl-effect-sdk\";\n\nfunction resolveCommitRevision(): string | undefined {\n return (\n stringOrUndefined(process.env.COMMIT_SHA) ??\n stringOrUndefined(process.env.VERCEL_GIT_COMMIT_SHA) ??\n stringOrUndefined(process.env.GITHUB_SHA) ??\n stringOrUndefined(process.env.RAILWAY_GIT_COMMIT_SHA) ??\n stringOrUndefined(process.env.CF_PAGES_COMMIT_SHA) ??\n stringOrUndefined(process.env.RENDER_GIT_COMMIT)\n );\n}\n\nlet serviceInstanceId: string | undefined;\nconst getServiceInstanceId = (): string => (serviceInstanceId ??= uuidv7());\n\nexport interface ResourceConfigInput {\n readonly serviceName?: string | undefined;\n readonly serviceVersion?: string | undefined;\n readonly environment?: string | undefined;\n readonly endpoint?: string | undefined;\n readonly headers?: Record<string, string> | undefined;\n readonly attributes?: Record<string, string> | undefined;\n readonly sdkType?: \"server\" | undefined;\n}\n\nexport interface ResolvedResource {\n readonly endpoint: string | undefined;\n readonly headers: Record<string, string> | undefined;\n readonly resource: {\n readonly serviceName: string;\n readonly serviceVersion: string | undefined;\n readonly attributes: Record<string, string>;\n };\n readonly environment: string | undefined;\n}\n\nexport const resolveResource = (\n config: ResourceConfigInput\n): Effect.Effect<ResolvedResource> =>\n Effect.gen(function* () {\n const disabled = yield* EnvConfig.sdkDisabled;\n if (disabled) {\n return {\n endpoint: undefined,\n environment: undefined,\n headers: undefined,\n resource: {\n attributes: {},\n serviceName: config.serviceName ?? \"unknown\",\n serviceVersion: undefined,\n },\n } satisfies ResolvedResource;\n }\n\n const envEndpoint = yield* EnvConfig.endpoint;\n const endpoint =\n config.endpoint ??\n Option.getOrUndefined(envEndpoint) ??\n EnvConfig.defaultOtlpEndpoint;\n\n const envHeaders = yield* EnvConfig.otlpHeaders;\n const headers =\n config.headers && Object.keys(config.headers).length > 0\n ? config.headers\n : Object.keys(envHeaders).length > 0\n ? envHeaders\n : undefined;\n\n const envServiceVersion = yield* EnvConfig.serviceVersion;\n const serviceVersion =\n config.serviceVersion ?? Option.getOrUndefined(envServiceVersion);\n\n const envEnvironment = yield* EnvConfig.environment;\n const environment = config.environment ?? envEnvironment;\n\n const envOtelServiceName = yield* EnvConfig.otelServiceName;\n const serviceName =\n config.serviceName ??\n Option.getOrUndefined(envOtelServiceName) ??\n \"unknown\";\n\n const envResourceAttributes = yield* EnvConfig.otelResourceAttributes;\n\n const attributes: Record<string, string> = {};\n Object.assign(attributes, getAutoPlatformAttributes());\n attributes[\"mxl.sdk.type\"] = config.sdkType ?? \"server\";\n attributes[\"service.instance.id\"] = getServiceInstanceId();\n if (environment) {\n attributes[\"deployment.environment\"] = environment;\n attributes[\"deployment.environment.name\"] = environment;\n }\n if (serviceVersion) {\n attributes[\"service.version\"] = serviceVersion;\n }\n const commitRevision = resolveCommitRevision();\n if (commitRevision) {\n attributes[\"deployment.commit_sha\"] = commitRevision;\n attributes[\"vcs.ref.head.revision\"] = commitRevision;\n }\n attributes[\"vcs.repository.url.full\"] =\n stringOrUndefined(process.env.MXL_VCS_REPOSITORY_URL) ??\n DEFAULT_VCS_REPOSITORY_URL;\n Object.assign(attributes, envResourceAttributes);\n if (config.attributes) Object.assign(attributes, config.attributes);\n\n return {\n endpoint,\n environment,\n headers,\n resource: { serviceName, serviceVersion, attributes },\n } satisfies ResolvedResource;\n }).pipe(Effect.orDie);\n","import type { Duration } from \"effect\";\nimport { Effect, Layer } from \"effect\";\nimport { FetchHttpClient } from \"effect/unstable/http\";\nimport { Otlp } from \"effect/unstable/observability\";\n\nimport { otelGlobalContextBridgeLayer } from \"./otel-context-bridge.js\";\nimport { normalizeOtlpBaseUrl } from \"./otlp.js\";\nimport { resolveResource } from \"./resource.js\";\n\nexport interface MxlConfig {\n readonly serviceName?: string | undefined;\n readonly serviceVersion?: string | undefined;\n readonly environment?: string | undefined;\n readonly endpoint?: string | undefined;\n readonly headers?: Record<string, string> | undefined;\n readonly attributes?: Record<string, string> | undefined;\n readonly maxBatchSize?: number | undefined;\n readonly loggerExportInterval?: Duration.Input | undefined;\n readonly metricsExportInterval?: Duration.Input | undefined;\n readonly tracerExportInterval?: Duration.Input | undefined;\n readonly shutdownTimeout?: Duration.Input | undefined;\n}\n\n/**\n * Create an Effect Layer that provides OpenTelemetry traces, logs, and metrics\n * configured for MXL's OTLP collector.\n *\n * Returns a no-op layer when `OTEL_SDK_DISABLED=true`.\n *\n * Wraps the OTLP tracer with `otelGlobalContextBridgeLayer` via `provideMerge`.\n * `Otlp.layerJson({ tracerContext })` cannot evaluate without a `fiber`, and\n * `Layer.updateService` cannot wrap a Tracer the OTLP layer already provides.\n */\nexport const layer = (config: MxlConfig = {}) =>\n Layer.unwrap(\n Effect.gen(function* () {\n const resolved = yield* resolveResource({ ...config, sdkType: \"server\" });\n if (!resolved.endpoint) return Layer.empty;\n\n const otlp = Otlp.layerJson({\n baseUrl: normalizeOtlpBaseUrl(resolved.endpoint),\n headers: resolved.headers,\n resource: resolved.resource,\n maxBatchSize: config.maxBatchSize,\n loggerExportInterval: config.loggerExportInterval,\n metricsExportInterval: config.metricsExportInterval,\n tracerExportInterval: config.tracerExportInterval,\n shutdownTimeout: config.shutdownTimeout,\n }).pipe(Layer.provide(FetchHttpClient.layer));\n\n return otelGlobalContextBridgeLayer.pipe(Layer.provideMerge(otlp));\n })\n );\n","export type ProductEventSource = \"server\" | \"browser\";\n\nexport const MAX_EVENT_NAME_LENGTH = 80;\nexport const RESERVED_EVENT_NAMES = [\"session_start\", \"session_end\"] as const;\n\nexport interface ProductEventLine {\n readonly attributes: Record<string, string>;\n readonly group_id: string;\n readonly name: string;\n readonly page_path: string;\n readonly service_name: string;\n readonly session_id: string;\n readonly source: ProductEventSource;\n readonly timestamp: string;\n readonly traceparent?: string | undefined;\n readonly url: string;\n readonly user_id: string;\n readonly visitor_id: string;\n}\n\nexport interface TrackProps {\n readonly [key: string]: unknown;\n}\n\nexport interface TrackOptions {\n readonly attributes?: TrackProps | undefined;\n readonly groupId?: string | undefined;\n readonly pagePath?: string | undefined;\n readonly sessionId?: string | undefined;\n readonly timestamp?: Date | number | undefined;\n readonly traceparent?: string | undefined;\n readonly url?: string | undefined;\n readonly userId?: string | undefined;\n readonly visitorId?: string | undefined;\n}\n\nconst isReservedEventName = (name: string): boolean =>\n RESERVED_EVENT_NAMES.some((reserved) => reserved === name);\n\nexport const coerceTrackProps = (\n props: TrackProps | undefined\n): Record<string, string> => {\n if (props === undefined) {\n return {};\n }\n const attributes: Record<string, string> = {};\n for (const [key, value] of Object.entries(props)) {\n if (value === undefined) {\n continue;\n }\n attributes[key] = typeof value === \"string\" ? value : String(value);\n }\n return attributes;\n};\n\nexport const toEventTimestamp = (value: Date | number | undefined): string =>\n (value instanceof Date ? value : new Date(value ?? Date.now())).toISOString();\n\nexport const encodeProductEventLine = (input: {\n readonly name: string;\n readonly options?: TrackOptions | undefined;\n readonly serviceName: string;\n readonly source: ProductEventSource;\n}): ProductEventLine | undefined => {\n const trimmed = typeof input.name === \"string\" ? input.name.trim() : \"\";\n if (trimmed.length === 0 || isReservedEventName(trimmed)) {\n return undefined;\n }\n const options = input.options ?? {};\n return {\n attributes: coerceTrackProps(options.attributes),\n group_id: options.groupId ?? \"\",\n name: trimmed.slice(0, MAX_EVENT_NAME_LENGTH),\n page_path: options.pagePath ?? \"\",\n service_name: input.serviceName,\n session_id: options.sessionId ?? \"\",\n source: input.source,\n timestamp: toEventTimestamp(options.timestamp),\n traceparent: options.traceparent,\n url: options.url ?? \"\",\n user_id: options.userId ?? \"\",\n visitor_id: options.visitorId ?? \"\",\n };\n};\n\nexport const encodeNdjson = (lines: ReadonlyArray<ProductEventLine>): string =>\n `${lines.map((line) => JSON.stringify(line)).join(\"\\n\")}\\n`;\n","export const SDK_NAME = \"mxl-effect-sdk\";\nexport const SDK_VERSION = \"0.0.15\";\n","import {\n Cause,\n Context,\n Duration,\n Effect,\n Layer,\n ManagedRuntime,\n Option,\n Schedule,\n Schema,\n Semaphore,\n} from \"effect\";\nimport { FetchHttpClient, HttpClient, HttpClientRequest } from \"effect/unstable/http\";\nimport { SchemaJITCompiler } from \"effect/unstable/schema\";\n\nimport {\n encodeNdjson,\n encodeProductEventLine,\n type ProductEventLine,\n type TrackOptions,\n} from \"../shared/product-event.js\";\nimport { SDK_NAME, SDK_VERSION } from \"../version.js\";\n\nexport type { TrackOptions } from \"../shared/product-event.js\";\n\nconst DEFAULT_FLUSH_INTERVAL = Duration.seconds(5);\nconst DEFAULT_MAX_BATCH_SIZE = 100;\nconst MAX_BUFFERED_EVENTS = 1_000;\nconst WARN_INTERVAL_MS = 30_000;\nconst DEFAULT_BASKET_URL = \"http://127.0.0.1:8000\";\n\nexport interface MxlEventsConfig {\n readonly apiKey?: string | undefined;\n readonly clientId?: string | undefined;\n readonly endpoint?: string | undefined;\n readonly eventsPath?: string | undefined;\n readonly flushInterval?: Duration.Input | undefined;\n readonly maxBatchSize?: number | undefined;\n readonly serviceName?: string | undefined;\n}\n\nexport interface MxlEventsApi {\n readonly flush: Effect.Effect<void>;\n readonly track: (name: string, options?: TrackOptions) => Effect.Effect<void>;\n}\n\nexport class MxlEvents extends Context.Service<MxlEvents, MxlEventsApi>()(\n \"@safaricom-mxl/effect-sdk/MxlEvents\"\n) {}\n\nexport class ProductEventsPostError extends Schema.TaggedError<ProductEventsPostError>()(\n \"@safaricom-mxl/effect-sdk/ProductEventsPostError\",\n {\n cause: Schema.optionalKey(Schema.Defect()),\n message: Schema.String,\n status: Schema.optionalKey(Schema.Number),\n }\n) {}\n\nSchemaJITCompiler.enable(ProductEventsPostError.ast);\nconst stringOrUndefined = (value: string | undefined): string | undefined =>\n value && value.length > 0 ? value : undefined;\n\nconst resolveEventsConfig = (config: MxlEventsConfig) => {\n const endpoint = (\n config.endpoint ??\n process.env.MXL_BASKET_URL ??\n DEFAULT_BASKET_URL\n ).replace(/\\/$/, \"\");\n return {\n apiKey: stringOrUndefined(config.apiKey ?? process.env.MXL_API_KEY),\n clientId: stringOrUndefined(config.clientId ?? process.env.MXL_CLIENT_ID),\n serviceName:\n config.serviceName ?? process.env.OTEL_SERVICE_NAME ?? \"unknown\",\n url: `${endpoint}${config.eventsPath ?? \"/events\"}`,\n };\n};\n\nexport const make = Effect.fn(\"MxlEvents.make\")(function* (\n config: MxlEventsConfig = {}\n) {\n const resolved = resolveEventsConfig(config);\n const maxBatchSize = Math.max(1, config.maxBatchSize ?? DEFAULT_MAX_BATCH_SIZE);\n const client = (yield* HttpClient.HttpClient).pipe(HttpClient.filterStatusOk);\n const flushing = yield* Semaphore.make(1);\n\n let buffer: Array<ProductEventLine> = [];\n let warnedAboutName = false;\n let warnedAboutClient = false;\n let lastPostWarnAt = 0;\n\n const warnPost = (error: ProductEventsPostError): void => {\n const now = Date.now();\n if (now - lastPostWarnAt < WARN_INTERVAL_MS) return;\n lastPostWarnAt = now;\n console.warn(`[MxlEvents] ${error.message} (dropping batch)`, error.cause ?? \"\");\n };\n const warnMissingClient = (): void => {\n if (warnedAboutClient) return;\n warnedAboutClient = true;\n console.warn(\n \"[MxlEvents] no client id — set MXL_CLIENT_ID or pass `clientId`; dropping events\"\n );\n };\n const warnEmptyName = (): void => {\n if (warnedAboutName) return;\n warnedAboutName = true;\n console.warn(\"[MxlEvents] track() needs a non-empty event name; the call was ignored.\");\n };\n\n const post = (lines: ReadonlyArray<ProductEventLine>) => {\n const headers: Record<string, string> = {\n \"mxl-client-id\": resolved.clientId ?? \"\",\n \"mxl-sdk-name\": SDK_NAME,\n \"mxl-sdk-version\": SDK_VERSION,\n \"user-agent\": `${SDK_NAME}-server/${SDK_VERSION}`,\n };\n if (resolved.apiKey) {\n headers[\"mxl-api-key\"] = resolved.apiKey;\n }\n return HttpClientRequest.post(resolved.url).pipe(\n HttpClientRequest.setHeaders(headers),\n HttpClientRequest.bodyText(encodeNdjson(lines), \"application/x-ndjson\"),\n client.execute,\n Effect.asVoid,\n Effect.mapError((error) =>\n error.response !== undefined\n ? new ProductEventsPostError({\n message: `POST ${resolved.url} → ${error.response.status}`,\n status: error.response.status,\n })\n : new ProductEventsPostError({\n cause: error,\n message: `POST ${resolved.url} failed: ${error.message}`,\n })\n )\n );\n };\n\n const flush: Effect.Effect<void> = flushing.withPermits(1)(\n Effect.suspend(() => {\n if (buffer.length === 0) return Effect.void;\n const batch = buffer;\n buffer = [];\n if (resolved.clientId === undefined) {\n warnMissingClient();\n return Effect.void;\n }\n return post(batch).pipe(\n Effect.catchCause((cause) =>\n Effect.sync(() => {\n warnPost(\n Option.getOrElse(Cause.findErrorOption(cause), () =>\n new ProductEventsPostError({\n cause: Cause.squash(cause),\n message: `POST ${resolved.url} failed`,\n })\n )\n );\n })\n )\n );\n })\n );\n\n const track = (name: string, options: TrackOptions = {}): Effect.Effect<void> =>\n Effect.sync(() => {\n const line = encodeProductEventLine({\n name,\n options,\n serviceName: resolved.serviceName,\n source: \"server\",\n });\n if (line === undefined) {\n warnEmptyName();\n return false;\n }\n buffer.push(line);\n if (buffer.length > MAX_BUFFERED_EVENTS) {\n buffer.splice(0, buffer.length - MAX_BUFFERED_EVENTS);\n }\n return buffer.length >= maxBatchSize;\n }).pipe(\n Effect.flatMap((full) => (full ? Effect.forkDetach(flush) : Effect.void)),\n Effect.asVoid\n );\n\n const interval = config.flushInterval ?? DEFAULT_FLUSH_INTERVAL;\n if (Duration.toMillis(interval) > 0) {\n yield* Effect.forkScoped(flush.pipe(Effect.schedule(Schedule.spaced(interval))));\n }\n yield* Effect.addFinalizer(() => flush);\n\n return { flush, track } satisfies MxlEventsApi;\n});\n\nexport const layer = (config: MxlEventsConfig = {}): Layer.Layer<MxlEvents> =>\n Layer.effect(MxlEvents, make(config)).pipe(Layer.provide(FetchHttpClient.layer));\n\nexport interface MxlEventsHandle {\n readonly dispose: () => Promise<void>;\n readonly flush: () => Promise<void>;\n readonly track: (name: string, options?: TrackOptions) => void;\n}\n\nexport const makeHandle = (config: MxlEventsConfig = {}): MxlEventsHandle => {\n const runtime = ManagedRuntime.make(layer(config));\n const swallow = (promise: Promise<unknown>): Promise<void> =>\n promise.then(\n () => undefined,\n () => undefined\n );\n return {\n dispose: () => swallow(runtime.dispose()),\n flush: () =>\n swallow(\n runtime.runPromise(\n Effect.gen(function* () {\n const events = yield* MxlEvents;\n yield* events.flush;\n })\n )\n ),\n track: (name, options) => {\n void swallow(\n runtime.runPromise(\n Effect.gen(function* () {\n const events = yield* MxlEvents;\n yield* events.track(name, options);\n })\n )\n );\n },\n };\n};\n","import { Layer } from \"effect\";\n\nimport {\n type MxlEventsConfig,\n type MxlEventsHandle,\n layer as eventsLayer,\n makeHandle,\n} from \"./events.js\";\nimport type { MxlConfig } from \"./layer.js\";\nimport { layer as otelLayer } from \"./layer.js\";\n\nexport interface MxlFlushableConfig extends MxlConfig {\n readonly apiKey?: string | undefined;\n readonly autoFlushInterval?: number | false | undefined;\n readonly clientId?: string | undefined;\n readonly ingestUrl?: string | undefined;\n}\n\nexport interface FlushableTelemetry extends MxlEventsHandle {\n readonly layer: Layer.Layer<never, never, never>;\n}\n\nexport const make = (config: MxlFlushableConfig = {}): FlushableTelemetry => {\n const eventsConfig: MxlEventsConfig = {\n apiKey: config.apiKey,\n clientId: config.clientId,\n endpoint: config.ingestUrl,\n flushInterval:\n config.autoFlushInterval === false ? 0 : config.autoFlushInterval,\n serviceName: config.serviceName,\n };\n const handle = makeHandle(eventsConfig);\n return {\n dispose: handle.dispose,\n flush: handle.flush,\n layer: Layer.mergeAll(\n otelLayer(config),\n eventsLayer(eventsConfig)\n ) as Layer.Layer<never, never, never>,\n track: handle.track,\n };\n};\n","import { Layer } from \"effect\";\nimport { HttpMiddleware } from \"effect/unstable/http\";\n\nexport function shouldDisableHttpTrace(request: {\n url: string;\n method: string;\n}): boolean {\n return (\n request.method === \"OPTIONS\" ||\n request.url === \"/health\" ||\n request.url === \"/healthcheck\" ||\n request.url.startsWith(\"/healthz\") ||\n request.url === \"/metrics\" ||\n /\\.(png|ico|jpg|jpeg|gif|css|js|svg|webp|woff2?)(\\?.*)?$/i.test(request.url)\n );\n}\n\nexport function tracerDisabledWhenLayer(\n filter: (request: {\n url: string;\n method: string;\n }) => boolean = shouldDisableHttpTrace\n) {\n return Layer.succeed(HttpMiddleware.TracerDisabledWhen, filter);\n}\n","import { context as otelContext, trace as traceApi } from \"@opentelemetry/api\";\nimport { Effect } from \"effect\";\nimport * as Option from \"effect/Option\";\n\nexport interface TraceCorrelation {\n spanId?: string;\n traceId?: string;\n}\n\nexport interface TraceLogAnnotations extends Record<string, string> {}\n\nconst ZERO_TRACE_ID = \"00000000000000000000000000000000\";\nconst ZERO_SPAN_ID = \"0000000000000000\";\n\n/** Parse W3C `traceparent` (`00-{traceId}-{spanId}-{flags}`). */\nexport function parseTraceparent(\n traceparent: string | undefined\n): TraceCorrelation {\n if (!traceparent) return {};\n const parts = traceparent.trim().split(\"-\");\n if (parts.length < 4) return {};\n const traceId = parts[1];\n const spanId = parts[2];\n if (!traceId || !spanId) return {};\n if (traceId.length !== 32 || spanId.length !== 16) return {};\n if (traceId === ZERO_TRACE_ID || spanId === ZERO_SPAN_ID) return {};\n return { spanId, traceId };\n}\n\n/**\n * Resolve trace/span IDs for log correlation.\n *\n * Prefers the active OpenTelemetry span (when a host bridge or queue propagation\n * is active), then falls back to a W3C `traceparent` carrier.\n */\nexport function getEffectTraceCorrelation(options?: {\n traceparent?: string | undefined;\n}): TraceCorrelation {\n const activeSpan = traceApi.getSpan(otelContext.active());\n if (activeSpan) {\n const spanContext = activeSpan.spanContext();\n if (\n spanContext.traceId &&\n spanContext.traceId !== ZERO_TRACE_ID &&\n spanContext.spanId &&\n spanContext.spanId !== ZERO_SPAN_ID\n ) {\n return {\n spanId: spanContext.spanId,\n traceId: spanContext.traceId,\n };\n }\n }\n\n return parseTraceparent(options?.traceparent);\n}\n\n/** Build log annotation fields from active span correlation. */\nexport function traceCorrelationLogAnnotations(\n options?: {\n traceparent?: string | undefined;\n } & Record<string, string>\n): TraceLogAnnotations {\n const { traceparent, ...extra } = options ?? {};\n const correlation = getEffectTraceCorrelation({ traceparent });\n const annotations: TraceLogAnnotations = { ...extra };\n\n if (correlation.traceId) {\n annotations[\"trace.trace_id\"] = correlation.traceId;\n annotations.trace_id = correlation.traceId;\n }\n if (correlation.spanId) {\n annotations[\"trace.span_id\"] = correlation.spanId;\n annotations.span_id = correlation.spanId;\n }\n\n return annotations;\n}\n\n/** Annotate Effect logs with the active span's trace/span IDs. */\nexport function annotateLogsWithActiveSpanCorrelation<A, E, R>(\n program: Effect.Effect<A, E, R>,\n fields?: Record<string, string>\n): Effect.Effect<A, E, R> {\n return Effect.gen(function* () {\n const { traceparent, ...extra } = fields ?? {};\n const annotations: TraceLogAnnotations = { ...extra };\n\n const currentSpan = yield* Effect.currentSpan.pipe(Effect.option);\n if (Option.isSome(currentSpan)) {\n annotations[\"trace.trace_id\"] = currentSpan.value.traceId;\n annotations.trace_id = currentSpan.value.traceId;\n annotations[\"trace.span_id\"] = currentSpan.value.spanId;\n annotations.span_id = currentSpan.value.spanId;\n } else {\n Object.assign(\n annotations,\n traceCorrelationLogAnnotations({\n ...(traceparent !== undefined ? { traceparent } : {}),\n ...extra,\n })\n );\n }\n\n if (Object.keys(annotations).length === 0) {\n return yield* program;\n }\n\n return yield* program.pipe(Effect.annotateLogs(annotations));\n });\n}\n","import { Effect, Layer, References } from \"effect\";\n\nexport type EffectLogLevel = \"Debug\" | \"Info\" | \"Warn\" | \"Error\" | \"Fatal\";\n\nexport interface SerializedLogError {\n readonly message: string;\n readonly name: string;\n readonly stack?: string;\n readonly cause?: SerializedLogError;\n}\n\nconst LOG_LEVEL_BY_ENV: Record<string, EffectLogLevel> = {\n trace: \"Debug\",\n debug: \"Debug\",\n info: \"Info\",\n warn: \"Warn\",\n warning: \"Warn\",\n error: \"Error\",\n fatal: \"Fatal\",\n};\n\nexport function resolveLogLevelFromEnv(\n env: NodeJS.ProcessEnv = process.env\n): EffectLogLevel {\n const raw = env.OTEL_LOG_LEVEL ?? env.LOG_LEVEL ?? \"info\";\n return LOG_LEVEL_BY_ENV[raw.trim().toLowerCase()] ?? \"Info\";\n}\n\nfunction isFiniteHttpStatus(status: number | undefined): status is number {\n return typeof status === \"number\" && Number.isFinite(status) && status >= 0;\n}\n\n/** Map HTTP status to Effect log level for response/failure logs. */\nexport function resolveEffectLogLevelFromHttpStatus(\n status: number | undefined\n): EffectLogLevel {\n if (!isFiniteHttpStatus(status) || status < 400) {\n return \"Info\";\n }\n\n if (status >= 500) {\n return \"Error\";\n }\n\n return \"Warn\";\n}\n\nexport type HttpLogOutcome = \"error\" | \"success\";\n\nexport interface HttpStatusLogFields {\n readonly \"http.response.status_code\": string;\n readonly \"http.status\": string;\n readonly \"log.level\": \"error\" | \"info\" | \"warn\";\n readonly outcome: HttpLogOutcome;\n}\n\n/** Standard log fields for HTTP response correlation in OTEL drains. */\nexport function buildHttpStatusLogFields(\n status: number | undefined\n): Partial<HttpStatusLogFields> {\n const level = resolveEffectLogLevelFromHttpStatus(status);\n const outcome: HttpLogOutcome =\n isFiniteHttpStatus(status) && status >= 400 ? \"error\" : \"success\";\n const logLevel =\n level === \"Error\" ? \"error\" : level === \"Warn\" ? \"warn\" : \"info\";\n\n if (!isFiniteHttpStatus(status)) {\n return {\n \"log.level\": logLevel,\n outcome,\n };\n }\n\n const statusText = String(status);\n return {\n \"http.response.status_code\": statusText,\n \"http.status\": statusText,\n \"log.level\": logLevel,\n outcome,\n };\n}\n\n/** Filter Effect logs below the configured minimum level. */\nexport function minimumLogLevelLayer(\n level: EffectLogLevel = resolveLogLevelFromEnv()\n): Layer.Layer<never> {\n return Layer.succeed(References.MinimumLogLevel, level);\n}\n\nfunction resolveErrorMessage(error: Error): string {\n if (error.message.trim().length > 0) {\n return error.message;\n }\n\n if (error.cause !== undefined) {\n if (error.cause instanceof Error && error.cause.message.trim().length > 0) {\n return error.cause.message;\n }\n\n if (typeof error.cause === \"string\" && error.cause.trim().length > 0) {\n return error.cause;\n }\n }\n\n if (\n \"reason\" in error &&\n typeof error.reason === \"string\" &&\n error.reason.trim().length > 0\n ) {\n return error.reason;\n }\n\n return error.name;\n}\n\nexport function serializeLogError(error: unknown): SerializedLogError {\n if (error instanceof Error) {\n return {\n message: resolveErrorMessage(error),\n name: error.name,\n ...(error.stack ? { stack: error.stack } : {}),\n ...(error.message.trim().length === 0 && error.cause !== undefined\n ? { cause: serializeLogError(error.cause) }\n : {}),\n };\n }\n\n return {\n message: String(error),\n name: \"UnknownError\",\n };\n}\n\nfunction annotateFields(\n fields: Record<string, unknown> | undefined\n): <A, E, R>(effect: Effect.Effect<A, E, R>) => Effect.Effect<A, E, R> {\n if (!fields || Object.keys(fields).length === 0) {\n return (effect) => effect;\n }\n\n const serialized = Object.fromEntries(\n Object.entries(fields).map(([key, value]) => [\n key,\n value instanceof Error ? serializeLogError(value) : value,\n ])\n );\n\n return (effect) => effect.pipe(Effect.annotateLogs(serialized));\n}\n\nexport function logDebug(\n message: string,\n fields?: Record<string, unknown>\n): Effect.Effect<void> {\n return annotateFields(fields)(Effect.logDebug(message));\n}\n\nexport function logInfo(\n message: string,\n fields?: Record<string, unknown>\n): Effect.Effect<void> {\n return annotateFields(fields)(Effect.logInfo(message));\n}\n\nexport function logWarning(\n message: string,\n fields?: Record<string, unknown>\n): Effect.Effect<void> {\n return annotateFields(fields)(Effect.logWarning(message));\n}\n\nexport function logError(\n message: string,\n fields?: Record<string, unknown>\n): Effect.Effect<void> {\n return annotateFields(fields)(Effect.logError(message));\n}\n\nexport function logAtLevel(\n level: EffectLogLevel,\n message: string,\n fields?: Record<string, unknown>\n): Effect.Effect<void> {\n switch (level) {\n case \"Debug\":\n return logDebug(message, fields);\n case \"Info\":\n return logInfo(message, fields);\n case \"Warn\":\n return logWarning(message, fields);\n case \"Error\":\n case \"Fatal\":\n return logError(message, fields);\n }\n}\n","import * as OtelTracer from \"@effect/opentelemetry/OtelTracer\";\nimport {\n context as otelContext,\n propagation,\n SpanStatusCode,\n trace as traceApi,\n TraceFlags,\n type SpanContext,\n} from \"@opentelemetry/api\";\nimport { Effect } from \"effect\";\nimport * as Option from \"effect/Option\";\n\nimport {\n buildHttpStatusLogFields,\n logAtLevel,\n logError,\n resolveEffectLogLevelFromHttpStatus,\n serializeLogError,\n} from \"./logging.js\";\nimport { buildTraceCarrierFromSpan } from \"./otel-context-bridge.js\";\nimport { annotateLogsWithActiveSpanCorrelation } from \"./trace-correlation.js\";\nimport { parseTraceparent } from \"./trace-correlation.js\";\n\nfunction headerValue(\n value: string | ReadonlyArray<string> | undefined\n): string | undefined {\n if (value === undefined) return undefined;\n return typeof value === \"string\" ? value : value[0];\n}\n\nexport function spanContextFromTraceparent(\n traceparent: string | undefined\n): SpanContext | undefined {\n const { traceId, spanId } = parseTraceparent(traceparent);\n if (!traceId || !spanId) return undefined;\n\n return {\n isRemote: true,\n spanId,\n traceFlags: TraceFlags.SAMPLED,\n traceId,\n };\n}\n\nexport function resolveTraceparentFromHeaders(\n headers: Record<string, string | ReadonlyArray<string> | undefined>\n): string | undefined {\n return headerValue(headers.traceparent ?? headers[\"traceparent\"]);\n}\n\nexport function withParentFromTraceparent<A, E, R>(\n headers: Record<string, string | ReadonlyArray<string> | undefined>,\n program: Effect.Effect<A, E, R>\n): Effect.Effect<A, E, R> {\n const parentSpanContext = spanContextFromTraceparent(\n resolveTraceparentFromHeaders(headers)\n );\n\n if (parentSpanContext === undefined) {\n return program;\n }\n\n return OtelTracer.withSpanContext(program, parentSpanContext);\n}\n\nexport interface HttpSpanAttributes {\n readonly method: string;\n readonly route: string;\n readonly requestId?: string | undefined;\n readonly url?: string | undefined;\n}\n\nexport interface QueueTraceContextCarrier {\n readonly baggage?: string;\n readonly traceparent?: string;\n readonly tracestate?: string;\n}\n\nfunction toSpanAttributes(\n attributes: HttpSpanAttributes\n): Record<string, string> {\n const result: Record<string, string> = {\n \"http.request.method\": attributes.method,\n \"http.route\": attributes.route,\n \"url.path\": attributes.route,\n };\n\n if (attributes.requestId !== undefined) {\n result[\"http.request_id\"] = attributes.requestId;\n result[\"request.id\"] = attributes.requestId;\n }\n\n if (attributes.url !== undefined) {\n result[\"url.full\"] = attributes.url;\n }\n\n return result;\n}\n\nexport function withHttpServerSpan<A, E, R>(\n name: string,\n attributes: HttpSpanAttributes,\n program: Effect.Effect<A, E, R>\n): Effect.Effect<A, E, R> {\n return program.pipe(\n Effect.withSpan(name, {\n attributes: toSpanAttributes(attributes),\n kind: \"server\",\n }),\n Effect.withLogSpan(name)\n );\n}\n\nexport function finalizeHttpSpan(\n status: number,\n route?: string\n): Effect.Effect<void> {\n const annotations: Record<string, string | number> = {\n \"http.response.status_code\": status,\n };\n\n if (route !== undefined) {\n annotations[\"http.route\"] = route;\n annotations[\"url.path\"] = route;\n }\n\n return Effect.sync(() => {\n if (status >= 500) {\n const activeSpan = traceApi.getActiveSpan();\n activeSpan?.setStatus({\n code: SpanStatusCode.ERROR,\n message: String(status),\n });\n }\n }).pipe(Effect.andThen(() => Effect.annotateCurrentSpan(annotations)));\n}\n\nexport interface LogHttpResponseOptions {\n readonly status: number;\n readonly durationMs?: number | undefined;\n readonly method?: string | undefined;\n readonly url?: string | undefined;\n readonly route?: string | undefined;\n readonly error?: unknown;\n readonly traceparent?: string | undefined;\n}\n\nfunction stringifyLogFieldValue(value: unknown): string {\n if (value === undefined) {\n return \"\";\n }\n return String(value);\n}\n\nfunction buildHttpResponseLogFields(\n options: LogHttpResponseOptions\n): Record<string, unknown> {\n const fields: Record<string, unknown> = {\n ...buildHttpStatusLogFields(options.status),\n ...(options.durationMs === undefined\n ? {}\n : { durationMs: options.durationMs }),\n ...(options.method === undefined\n ? {}\n : { \"http.request.method\": options.method }),\n ...(options.url === undefined ? {} : { \"url.full\": options.url }),\n ...(options.route === undefined ? {} : { \"http.route\": options.route }),\n ...(options.route === undefined ? {} : { \"url.path\": options.route }),\n ...(options.traceparent === undefined\n ? {}\n : { traceparent: options.traceparent }),\n };\n\n if (options.error !== undefined) {\n fields.error = serializeLogError(options.error);\n }\n\n return fields;\n}\n\n/** Log an HTTP response at info/warn/error severity based on status code. */\nexport function logHttpResponse(\n message: string,\n options: LogHttpResponseOptions\n): Effect.Effect<void> {\n const level = resolveEffectLogLevelFromHttpStatus(options.status);\n const fields = buildHttpResponseLogFields(options);\n const correlationFields = Object.fromEntries(\n Object.entries(fields)\n .filter(([, value]) => value !== undefined)\n .map(([key, value]) => [key, stringifyLogFieldValue(value)])\n );\n\n return annotateLogsWithActiveSpanCorrelation(\n logAtLevel(level, message, fields),\n correlationFields\n );\n}\n\nexport function logHttpRequestFailure(\n message: string,\n error: unknown,\n fields?: Record<string, unknown>\n): Effect.Effect<void> {\n const logFields: Record<string, string> = {};\n if (fields) {\n for (const [key, value] of Object.entries(fields)) {\n if (value !== undefined) {\n logFields[key] = String(value);\n }\n }\n }\n\n return annotateLogsWithActiveSpanCorrelation(\n logError(message, {\n error: serializeLogError(error),\n ...fields,\n }),\n logFields\n );\n}\n\nfunction normalizeHeaderRecord(\n headers: Record<string, string | ReadonlyArray<string> | undefined>\n): Record<string, string> {\n const normalized: Record<string, string> = {};\n for (const [key, value] of Object.entries(headers)) {\n if (value === undefined) continue;\n normalized[key.toLowerCase()] =\n typeof value === \"string\" ? value : (value[0] ?? \"\");\n }\n return normalized;\n}\n\nfunction normalizeCarrierRecord(\n carrier: QueueTraceContextCarrier | Record<string, string> | undefined\n): Record<string, string> | undefined {\n if (!carrier) return undefined;\n const normalized: Record<string, string> = {};\n for (const [key, value] of Object.entries(carrier)) {\n if (value === undefined || value === \"\") continue;\n normalized[key.toLowerCase()] = value;\n }\n return Object.keys(normalized).length > 0 ? normalized : undefined;\n}\n\n/** Resolve parent span context from a W3C trace carrier. */\nexport function spanContextFromCarrier(\n carrier: QueueTraceContextCarrier | Record<string, string> | undefined\n): SpanContext | undefined {\n const normalized = normalizeCarrierRecord(carrier);\n if (!normalized) return undefined;\n\n const extracted = propagation.extract(otelContext.active(), normalized);\n const spanContext = traceApi.getSpan(extracted)?.spanContext();\n if (\n spanContext?.traceId &&\n spanContext.traceId !== \"00000000000000000000000000000000\" &&\n spanContext.spanId &&\n spanContext.spanId !== \"0000000000000000\"\n ) {\n return spanContext;\n }\n\n return spanContextFromTraceparent(normalized.traceparent);\n}\n\nexport function withParentFromTraceCarrier<A, E, R>(\n carrier: QueueTraceContextCarrier | Record<string, string> | undefined,\n program: Effect.Effect<A, E, R>\n): Effect.Effect<A, E, R> {\n const parentSpanContext = spanContextFromCarrier(carrier);\n if (parentSpanContext === undefined) {\n return program;\n }\n return OtelTracer.withSpanContext(program, parentSpanContext);\n}\n\n/** Build W3C trace carrier for queue/job propagation from request headers + active OTel context. */\nexport function buildQueueTraceCarrier(\n headers?: Record<string, string | ReadonlyArray<string> | undefined>\n): Record<string, string> | undefined {\n const normalized = headers ? normalizeHeaderRecord(headers) : {};\n const parentContext = propagation.extract(otelContext.active(), normalized);\n const carrier: Record<string, string> = {};\n propagation.inject(parentContext, carrier);\n return Object.keys(carrier).length > 0 ? carrier : undefined;\n}\n\n/** Build W3C trace carrier using the active Effect span when available. */\nexport function buildQueueTraceCarrierEffect(\n headers?: Record<string, string | ReadonlyArray<string> | undefined>\n): Effect.Effect<Record<string, string> | undefined> {\n return Effect.gen(function* () {\n const normalized = headers ? normalizeHeaderRecord(headers) : {};\n const currentSpan = yield* Effect.currentSpan.pipe(Effect.option);\n\n if (Option.isSome(currentSpan)) {\n return buildTraceCarrierFromSpan(currentSpan.value, normalized);\n }\n\n return buildQueueTraceCarrier(headers);\n });\n}\n","import * as OtelTracer from \"@effect/opentelemetry/OtelTracer\";\nimport type { SpanContext } from \"@opentelemetry/api\";\nimport { Effect, type ManagedRuntime } from \"effect\";\n\nimport {\n type QueueTraceContextCarrier,\n spanContextFromCarrier,\n} from \"./http-tracing.js\";\nimport { logError, logInfo, serializeLogError } from \"./logging.js\";\nimport { annotateLogsWithActiveSpanCorrelation } from \"./trace-correlation.js\";\n\nexport interface RunJobWithSpanOptions {\n readonly name: string;\n readonly attributes?: Record<string, string> | undefined;\n readonly parentSpanContext?: SpanContext | undefined;\n readonly parentTraceCarrier?:\n | QueueTraceContextCarrier\n | Record<string, string>\n | undefined;\n readonly logAttributes?: Record<string, string> | undefined;\n}\n\nfunction resolveParentSpanContext(\n options: RunJobWithSpanOptions\n): SpanContext | undefined {\n if (options.parentSpanContext !== undefined) {\n return options.parentSpanContext;\n }\n return spanContextFromCarrier(options.parentTraceCarrier);\n}\n\nexport function jobWithSpanEffect<A, E, R>(\n options: RunJobWithSpanOptions,\n program: Effect.Effect<A, E, R>\n): Effect.Effect<A, E, R> {\n const parentSpanContext = resolveParentSpanContext(options);\n const startedAt = Date.now();\n\n let wrapped = program.pipe(\n Effect.tap(() =>\n logInfo(\"Job completed\", {\n durationMs: Date.now() - startedAt,\n \"job.name\": options.name,\n outcome: \"success\",\n ...options.logAttributes,\n })\n ),\n Effect.tapError((error) =>\n logError(\"Job failed\", {\n durationMs: Date.now() - startedAt,\n error: serializeLogError(error),\n \"job.name\": options.name,\n outcome: \"error\",\n ...options.logAttributes,\n })\n ),\n (effect) =>\n annotateLogsWithActiveSpanCorrelation(effect, {\n \"job.name\": options.name,\n ...options.logAttributes,\n }),\n Effect.withLogSpan(options.name),\n Effect.withSpan(options.name, {\n attributes: options.attributes,\n kind: \"consumer\",\n })\n );\n\n if (parentSpanContext !== undefined) {\n wrapped = OtelTracer.withSpanContext(wrapped, parentSpanContext);\n }\n\n return wrapped;\n}\n\nexport function runJobWithSpan<A, E, R>(\n runtime: ManagedRuntime.ManagedRuntime<R, unknown>,\n options: RunJobWithSpanOptions,\n program: Effect.Effect<A, E>\n): Promise<A> {\n return runtime.runPromise(jobWithSpanEffect(options, program));\n}\n","import {\n getEffectTraceCorrelation,\n parseTraceparent,\n} from \"./trace-correlation.js\";\n\n/** Minimal evlog enricher context (compatible with `evlog` EnrichContext). */\nexport interface EffectTraceEnrichContext {\n readonly event: Record<string, unknown>;\n readonly headers?: Record<string, string> | undefined;\n}\n\nexport interface EffectTraceEnricherOptions {\n readonly overwrite?: boolean | undefined;\n}\n\nfunction headerValue(\n headers: Record<string, string> | undefined,\n name: string\n): string | undefined {\n if (!headers) return undefined;\n const direct = headers[name];\n if (direct !== undefined) return direct;\n const lower = headers[name.toLowerCase()];\n if (lower !== undefined) return lower;\n return undefined;\n}\n\nfunction assignTraceFields(\n event: Record<string, unknown>,\n traceId: string,\n spanId: string,\n overwrite: boolean\n): void {\n if (overwrite || event.trace_id === undefined) {\n event.trace_id = traceId;\n }\n if (overwrite || event.span_id === undefined) {\n event.span_id = spanId;\n }\n if (overwrite || event.traceId === undefined) {\n event.traceId = traceId;\n }\n if (overwrite || event.spanId === undefined) {\n event.spanId = spanId;\n }\n\n const trace =\n typeof event.trace === \"object\" && event.trace !== null\n ? (event.trace as Record<string, unknown>)\n : {};\n\n if (overwrite || trace.trace_id === undefined) {\n trace.trace_id = traceId;\n }\n if (overwrite || trace.span_id === undefined) {\n trace.span_id = spanId;\n }\n\n if (Object.keys(trace).length > 0) {\n event.trace = trace;\n }\n}\n\n/**\n * Enrich evlog wide events with trace/span IDs from OTel global context or W3C headers.\n *\n * Use `createEffectTraceEnricher` in the MXL evlog enricher chain.\n */\nexport function createEffectTraceEnricher(\n options: EffectTraceEnricherOptions = {}\n): (ctx: EffectTraceEnrichContext) => void {\n const overwrite = options.overwrite ?? false;\n\n return (ctx) => {\n const traceparent = headerValue(ctx.headers, \"traceparent\");\n const correlation = getEffectTraceCorrelation({ traceparent });\n\n if (correlation.traceId && correlation.spanId) {\n assignTraceFields(\n ctx.event,\n correlation.traceId,\n correlation.spanId,\n overwrite\n );\n return;\n }\n\n const parsed = parseTraceparent(traceparent);\n if (parsed.traceId && parsed.spanId) {\n assignTraceFields(ctx.event, parsed.traceId, parsed.spanId, overwrite);\n }\n };\n}\n","import {\n context as otelContext,\n propagation,\n SpanKind,\n SpanStatusCode,\n trace as traceApi,\n} from \"@opentelemetry/api\";\nimport { Effect } from \"effect\";\n\nexport type DbSystem = \"clickhouse\" | \"postgresql\" | \"redis\";\n\nexport type DependencySpanKind = \"client\" | \"producer\" | \"consumer\";\n\nconst MAX_FLUSH_SPAN_LINKS = 32;\n\nexport interface QueueTraceContextCarrier {\n readonly traceparent?: string | undefined;\n readonly tracestate?: string | undefined;\n readonly baggage?: string | undefined;\n}\n\nexport function dbClientSpanAttributes(\n dbSystem: DbSystem,\n operation?: string\n): Record<string, string> {\n return {\n \"db.system\": dbSystem,\n \"db.system.name\": dbSystem,\n \"peer.service\": dbSystem,\n ...(operation ? { \"db.operation.name\": operation } : {}),\n };\n}\n\nexport function queueProducerSpanAttributes(\n destinationName: string,\n peerService = \"mxl-worker\"\n): Record<string, string> {\n return {\n \"messaging.destination.name\": destinationName,\n \"messaging.system\": \"bullmq\",\n \"peer.service\": peerService,\n };\n}\n\nexport function queueConsumerSpanAttributes(\n destinationName: string\n): Record<string, string> {\n return {\n \"messaging.destination.name\": destinationName,\n \"messaging.system\": \"bullmq\",\n };\n}\n\nexport function kafkaProducerSpanAttributes(\n topic: string,\n peerService = \"kafka\"\n): Record<string, string> {\n return {\n \"messaging.destination.name\": topic,\n \"messaging.system\": \"kafka\",\n \"peer.service\": peerService,\n };\n}\n\nexport function bufferSpanAttributes(\n bufferName: string,\n operation: string\n): Record<string, string> {\n return {\n \"buffer.name\": bufferName,\n \"db.operation.name\": operation,\n \"db.system\": \"redis\",\n \"db.system.name\": \"redis\",\n \"peer.service\": \"redis\",\n };\n}\n\nexport function geoSpanAttributes(): Record<string, string> {\n return {\n \"db.operation.name\": \"resolve\",\n \"db.system\": \"maxmind\",\n \"db.system.name\": \"maxmind\",\n \"peer.service\": \"maxmind\",\n };\n}\n\nexport function addSpanLinksFromTraceCarriers(\n carriers: readonly QueueTraceContextCarrier[]\n): number {\n const span = traceApi.getActiveSpan();\n if (!span) {\n return 0;\n }\n\n const seen = new Set<string>();\n let linked = 0;\n\n for (const carrier of carriers) {\n if (!carrier.traceparent || seen.has(carrier.traceparent)) {\n continue;\n }\n seen.add(carrier.traceparent);\n\n const extracted = propagation.extract(otelContext.active(), carrier);\n const linkedContext = traceApi.getSpanContext(extracted);\n if (!linkedContext) {\n continue;\n }\n\n span.addLink({ context: linkedContext });\n linked += 1;\n\n if (linked >= MAX_FLUSH_SPAN_LINKS) {\n break;\n }\n }\n\n return linked;\n}\n\nexport interface WithDependencySpanOptions {\n readonly attributes?: Record<string, string> | undefined;\n readonly kind?: DependencySpanKind | undefined;\n}\n\nexport function withDependencySpan<A, E, R>(\n name: string,\n attributes: Record<string, string>,\n program: Effect.Effect<A, E, R>\n): Effect.Effect<A, E, R>;\nexport function withDependencySpan<A, E, R>(\n name: string,\n options: WithDependencySpanOptions,\n program: Effect.Effect<A, E, R>\n): Effect.Effect<A, E, R>;\nexport function withDependencySpan<A, E, R>(\n name: string,\n attributesOrOptions: Record<string, string> | WithDependencySpanOptions,\n program: Effect.Effect<A, E, R>\n): Effect.Effect<A, E, R> {\n const options = isWithDependencySpanOptions(attributesOrOptions)\n ? attributesOrOptions\n : { attributes: attributesOrOptions };\n\n const attributes = options.attributes ?? {};\n const kind: DependencySpanKind = options.kind ?? \"client\";\n\n return program.pipe(Effect.withSpan(name, { attributes, kind }));\n}\n\nfunction isWithDependencySpanOptions(\n value: Record<string, string> | WithDependencySpanOptions\n): value is WithDependencySpanOptions {\n return (\n typeof value === \"object\" &&\n (\"kind\" in value ||\n (\"attributes\" in value && typeof value.attributes === \"object\"))\n );\n}\n\n/** Promise-based dependency span for non-Effect code paths. */\nexport async function withPromiseDependencySpan<T>(\n name: string,\n attributes: Record<string, string>,\n operation: () => Promise<T>,\n kind: DependencySpanKind = \"client\"\n): Promise<T> {\n const tracer = traceApi.getTracer(\"mxl-effect-sdk\");\n const spanKind =\n kind === \"producer\"\n ? SpanKind.PRODUCER\n : kind === \"consumer\"\n ? SpanKind.CONSUMER\n : SpanKind.CLIENT;\n return tracer.startActiveSpan(\n name,\n { attributes, kind: spanKind },\n async (span) => {\n try {\n const result = await operation();\n span.end();\n return result;\n } catch (error) {\n if (error instanceof Error) {\n span.recordException(error);\n span.setStatus({\n code: SpanStatusCode.ERROR,\n message: error.message,\n });\n } else {\n span.setStatus({\n code: SpanStatusCode.ERROR,\n message: String(error),\n });\n }\n span.end();\n throw error;\n }\n }\n );\n}\n"],"mappings":";;;;;;;;;;;;;;AAKA,MAAM,WAAW;AAEjB,IAAI,0BAA0B;;;;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AAS;EACd,IAAI;GACF,MAAM,SAAS,MAAM,UAAU;GAC/B,KAAK,IAAI;GACT,OAAO;EACT,SAAS,OAAO;GACd,IAAI,iBAAiB,OAAO;IAC1B,KAAK,gBAAgB,KAAK;IAC1B,KAAK,UAAU;KACb,MAAM,eAAe;KACrB,SAAS,MAAM;IACjB,CAAC;GACH,OACE,KAAK,UAAU;IACb,MAAM,eAAe;IACrB,SAAS,OAAO,KAAK;GACvB,CAAC;GAEH,KAAK,IAAI;GACT,MAAM;EACR;CACF,CACF;AACF"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@safaricom-mxl/effect-sdk",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.17",
|
|
4
4
|
"description": "MXL OpenTelemetry and product-analytics SDK for Effect applications",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"type": "module",
|
|
@@ -66,24 +66,31 @@
|
|
|
66
66
|
]
|
|
67
67
|
}
|
|
68
68
|
},
|
|
69
|
+
"scripts": {
|
|
70
|
+
"build": "tsdown",
|
|
71
|
+
"check": "tsc --noEmit",
|
|
72
|
+
"clean": "rimraf dist",
|
|
73
|
+
"test": "vitest run"
|
|
74
|
+
},
|
|
69
75
|
"dependencies": {
|
|
70
76
|
"@opentelemetry/api": "^1.9.1",
|
|
77
|
+
"@opentelemetry/context-async-hooks": "^2.11.0",
|
|
71
78
|
"@opentelemetry/exporter-trace-otlp-http": "^0.222.0",
|
|
72
79
|
"@opentelemetry/sdk-trace-base": "^2.11.0",
|
|
73
80
|
"std-env": "^4.2.0",
|
|
74
81
|
"uuid": "^14.0.2"
|
|
75
82
|
},
|
|
76
83
|
"devDependencies": {
|
|
77
|
-
"@effect/opentelemetry": "^4.0.0-rc.
|
|
78
|
-
"@types/node": "^26.6.
|
|
79
|
-
"effect": "^4.0.0-rc.
|
|
84
|
+
"@effect/opentelemetry": "^4.0.0-rc.116",
|
|
85
|
+
"@types/node": "^26.6.2",
|
|
86
|
+
"effect": "^4.0.0-rc.116",
|
|
80
87
|
"tsdown": "^0.23.0",
|
|
81
88
|
"typescript": "^7.0.2",
|
|
82
89
|
"vitest": "^5.0.1"
|
|
83
90
|
},
|
|
84
91
|
"peerDependencies": {
|
|
85
|
-
"@effect/opentelemetry": "^4.0.0-rc.
|
|
86
|
-
"effect": "^4.0.0-rc.
|
|
92
|
+
"@effect/opentelemetry": "^4.0.0-rc.116",
|
|
93
|
+
"effect": "^4.0.0-rc.116"
|
|
87
94
|
},
|
|
88
95
|
"author": "MXL <ServiceAvailability@Safaricom.co.ke>",
|
|
89
96
|
"repository": {
|
|
@@ -100,11 +107,5 @@
|
|
|
100
107
|
"opentelemetry",
|
|
101
108
|
"observability",
|
|
102
109
|
"telemetry"
|
|
103
|
-
]
|
|
104
|
-
|
|
105
|
-
"build": "tsdown",
|
|
106
|
-
"check": "tsc --noEmit",
|
|
107
|
-
"clean": "rimraf dist",
|
|
108
|
-
"test": "vitest run"
|
|
109
|
-
}
|
|
110
|
-
}
|
|
110
|
+
]
|
|
111
|
+
}
|
package/LICENSE
DELETED
|
@@ -1,201 +0,0 @@
|
|
|
1
|
-
Apache License
|
|
2
|
-
Version 2.0, January 2004
|
|
3
|
-
http://www.apache.org/licenses/
|
|
4
|
-
|
|
5
|
-
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
-
|
|
7
|
-
1. Definitions.
|
|
8
|
-
|
|
9
|
-
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
-
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
-
|
|
12
|
-
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
-
the copyright owner that is granting the License.
|
|
14
|
-
|
|
15
|
-
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
-
other entities that control, are controlled by, or are under common
|
|
17
|
-
control with that entity. For the purposes of this definition,
|
|
18
|
-
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
-
direction or management of such entity, whether by contract or
|
|
20
|
-
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
-
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
-
|
|
23
|
-
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
-
exercising permissions granted by this License.
|
|
25
|
-
|
|
26
|
-
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
-
including but not limited to software source code, documentation
|
|
28
|
-
source, and configuration files.
|
|
29
|
-
|
|
30
|
-
"Object" form shall mean any form resulting from mechanical
|
|
31
|
-
transformation or translation of a Source form, including but
|
|
32
|
-
not limited to compiled object code, generated documentation,
|
|
33
|
-
and conversions to other media types.
|
|
34
|
-
|
|
35
|
-
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
-
Object form, made available under the License, as indicated by a
|
|
37
|
-
copyright notice that is included in or attached to the work
|
|
38
|
-
(an example is provided in the Appendix below).
|
|
39
|
-
|
|
40
|
-
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
-
form, that is based on (or derived from) the Work and for which the
|
|
42
|
-
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
-
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
-
of this License, Derivative Works shall not include works that remain
|
|
45
|
-
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
-
the Work and Derivative Works thereof.
|
|
47
|
-
|
|
48
|
-
"Contribution" shall mean any work of authorship, including
|
|
49
|
-
the original version of the Work and any modifications or additions
|
|
50
|
-
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
-
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
-
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
-
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
-
means any form of electronic, verbal, or written communication sent
|
|
55
|
-
to the Licensor or its representatives, including but not limited to
|
|
56
|
-
communication on electronic mailing lists, source code control systems,
|
|
57
|
-
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
-
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
-
excluding communication that is conspicuously marked or otherwise
|
|
60
|
-
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
-
|
|
62
|
-
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
-
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
-
subsequently incorporated within the Work.
|
|
65
|
-
|
|
66
|
-
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
-
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
-
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
-
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
-
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
-
Work and such Derivative Works in Source or Object form.
|
|
72
|
-
|
|
73
|
-
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
-
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
-
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
-
(except as stated in this section) patent license to make, have made,
|
|
77
|
-
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
-
where such license applies only to those patent claims licensable
|
|
79
|
-
by such Contributor that are necessarily infringed by their
|
|
80
|
-
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
-
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
-
institute patent litigation against any entity (including a
|
|
83
|
-
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
-
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
-
or contributory patent infringement, then any patent licenses
|
|
86
|
-
granted to You under this License for that Work shall terminate
|
|
87
|
-
as of the date such litigation is filed.
|
|
88
|
-
|
|
89
|
-
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
-
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
-
modifications, and in Source or Object form, provided that You
|
|
92
|
-
meet the following conditions:
|
|
93
|
-
|
|
94
|
-
(a) You must give any other recipients of the Work or
|
|
95
|
-
Derivative Works a copy of this License; and
|
|
96
|
-
|
|
97
|
-
(b) You must cause any modified files to carry prominent notices
|
|
98
|
-
stating that You changed the files; and
|
|
99
|
-
|
|
100
|
-
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
-
that You distribute, all copyright, patent, trademark, and
|
|
102
|
-
attribution notices from the Source form of the Work,
|
|
103
|
-
excluding those notices that do not pertain to any part of
|
|
104
|
-
the Derivative Works; and
|
|
105
|
-
|
|
106
|
-
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
-
distribution, then any Derivative Works that You distribute must
|
|
108
|
-
include a readable copy of the attribution notices contained
|
|
109
|
-
within such NOTICE file, excluding those notices that do not
|
|
110
|
-
pertain to any part of the Derivative Works, in at least one
|
|
111
|
-
of the following places: within a NOTICE text file distributed
|
|
112
|
-
as part of the Derivative Works; within the Source form or
|
|
113
|
-
documentation, if provided along with the Derivative Works; or,
|
|
114
|
-
within a display generated by the Derivative Works, if and
|
|
115
|
-
wherever such third-party notices normally appear. The contents
|
|
116
|
-
of the NOTICE file are for informational purposes only and
|
|
117
|
-
do not modify the License. You may add Your own attribution
|
|
118
|
-
notices within Derivative Works that You distribute, alongside
|
|
119
|
-
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
-
that such additional attribution notices cannot be construed
|
|
121
|
-
as modifying the License.
|
|
122
|
-
|
|
123
|
-
You may add Your own copyright statement to Your modifications and
|
|
124
|
-
may provide additional or different license terms and conditions
|
|
125
|
-
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
-
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
-
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
-
the conditions stated in this License.
|
|
129
|
-
|
|
130
|
-
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
-
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
-
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
-
this License, without any additional terms or conditions.
|
|
134
|
-
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
-
the terms of any separate license agreement you may have executed
|
|
136
|
-
with Licensor regarding such Contributions.
|
|
137
|
-
|
|
138
|
-
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
-
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
-
except as required for reasonable and customary use in describing the
|
|
141
|
-
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
-
|
|
143
|
-
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
-
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
-
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
-
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
-
implied, including, without limitation, any warranties or conditions
|
|
148
|
-
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
-
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
-
appropriateness of using or redistributing the Work and assume any
|
|
151
|
-
risks associated with Your exercise of permissions under this License.
|
|
152
|
-
|
|
153
|
-
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
-
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
-
unless required by applicable law (such as deliberate and grossly
|
|
156
|
-
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
-
liable to You for damages, including any direct, indirect, special,
|
|
158
|
-
incidental, or consequential damages of any character arising as a
|
|
159
|
-
result of this License or out of the use or inability to use the
|
|
160
|
-
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
-
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
-
other commercial damages or losses), even if such Contributor
|
|
163
|
-
has been advised of the possibility of such damages.
|
|
164
|
-
|
|
165
|
-
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
-
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
-
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
-
or other liability obligations and/or rights consistent with this
|
|
169
|
-
License. However, in accepting such obligations, You may act only
|
|
170
|
-
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
-
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
-
defend, and hold each Contributor harmless for any liability
|
|
173
|
-
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
-
of your accepting any such warranty or additional liability.
|
|
175
|
-
|
|
176
|
-
END OF TERMS AND CONDITIONS
|
|
177
|
-
|
|
178
|
-
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
-
|
|
180
|
-
To apply the Apache License to your work, attach the following
|
|
181
|
-
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
-
replaced with your own identifying information. (Don't include
|
|
183
|
-
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
-
comment syntax for the file format. We also recommend that a
|
|
185
|
-
file or class name and description of purpose be included on the
|
|
186
|
-
same "printed page" as the copyright notice for easier
|
|
187
|
-
identification within third-party archives.
|
|
188
|
-
|
|
189
|
-
Copyright [yyyy] [name of copyright owner]
|
|
190
|
-
|
|
191
|
-
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
-
you may not use this file except in compliance with the License.
|
|
193
|
-
You may obtain a copy of the License at
|
|
194
|
-
|
|
195
|
-
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
-
|
|
197
|
-
Unless required by applicable law or agreed to in writing, software
|
|
198
|
-
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
-
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
-
See the License for the specific language governing permissions and
|
|
201
|
-
limitations under the License.
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index-BF4-zL-9.d.mts","names":[],"sources":["../src/server/layer.ts","../src/shared/product-event.ts","../src/server/events.ts","../src/server/flushable.ts","../src/server/platform.ts","../src/server/config.ts","../src/server/otlp.ts","../src/server/http-middleware.ts","../src/server/trace-correlation.ts","../src/server/http-tracing.ts","../src/server/jobs.ts","../src/server/logging.ts","../src/server/otel-context-bridge.ts","../src/server/evlog-bridge.ts","../src/shared/dependency-spans.ts"],"mappings":";;;;;;;UAUiB;WACN;WACA;WACA;WACA;WACA,UAAU;WACV,aAAa;WACb;WACA,uBAAuB,SAAS;WAChC,wBAAwB,SAAS;WACjC,uBAAuB,SAAS;WAChC,kBAAkB,SAAS;;;;;;;;cASzB,UAAK,SAAY,cAAS,MAAA;;;UCVtB;YACL;;UAGK;WACN,aAAa;WACb;WACA;WACA;WACA,YAAY;WACZ;WACA;WACA;WACA;;;;;UCHM;WACN;WACA;WACA;WACA;WACA,gBAAgB,SAAS;WACzB;WACA;;UAGM;WACN,OAAO,OAAO;WACd,QAAQ,cAAc,UAAU,iBAAiB,OAAO;;;cAGtD,kBAAkB;;;;;;cAIlB,+BAA+B;cA2B/B,SAAI,SAAA,oBAAA,OAAA;;EAuFM,QAAA,cAAM,UAAW,iBAAoB,OAAO;UA6BjE,WAAA,oCAAA;cAEW,QAAK,SAAY,oBAAuB,MAAM,MAAM;UAGhD;WACN,eAAe;WACf,aAAa;WACb,QAAQ,cAAc,UAAU;;cAG9B,aAAU,SAAY,oBAAuB;;;;UChMzC,2BAA2B;WACjC;WACA;WACA;WACA;;UAGM,2BAA2B;WACjC,OAAO,MAAM;;cAGX,OAAI,SAAY,uBAA0B;;;UCnBtC;WACN;WACA;WACA;WACA;WACA,KAAK,SAAS;;KAGpB,QAAQ;cAoIA,2BAAwB,QAC3B,mBACP;KAoBS,qBAAqB;cAoBpB,iCAAgC;;;;;;;;;cCjIhC,8BAA2B,kBAErC;;;;cA+BU,mBAAgB,kBAAoB;;;iBCzFjC,qBAAqB;;;iBCGrB,uBAAuB;EACrC;EACA;;iBAYc,wBACd,UAAS;EACP;EACA;gBACoC,MAAA;;;UCjBvB;EACf;EACA;;UAGe,4BAA4B;;iBAM7B,iBACd,kCACC;;;;;;;iBAkBa,0BAA0B;EACxC;IACE;;iBAqBY,+BACd;EACE;IACE,yBACH;;iBAkB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