@lunora/runtime 1.0.0-alpha.24 → 1.0.0-alpha.25

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/index.d.mts CHANGED
@@ -2778,6 +2778,60 @@ interface AnalyticsEngineSinkOptions extends OnlyErrorsOption {
2778
2778
  * only error events (defaults to all events).
2779
2779
  */
2780
2780
  declare const analyticsEngineSink: (options: AnalyticsEngineSinkOptions) => ObservabilitySink;
2781
+ /** Options for {@link otlpSink}. */
2782
+ interface OtlpSinkOptions extends OnlyErrorsOption {
2783
+ /**
2784
+ * The OTLP-over-HTTP collector base endpoint (e.g.
2785
+ * `https://collector.example.com`). Following the OTel base-endpoint
2786
+ * convention, the sink POSTs spans to `${endpoint}/v1/traces` and log
2787
+ * records to `${endpoint}/v1/logs`; a trailing slash is tolerated.
2788
+ */
2789
+ endpoint: string;
2790
+ /**
2791
+ * Extra headers merged onto every OTLP POST — typically an `Authorization`
2792
+ * bearer plus the `x-lunora-deployment` / `x-lunora-org` correlation headers
2793
+ * the platform injects at deploy. `Content-Type: application/json` is set by
2794
+ * default and may be overridden here.
2795
+ */
2796
+ headers?: Record<string, string>;
2797
+ /**
2798
+ * Value of the `service.name` resource attribute on every exported span and
2799
+ * log — the logical service the telemetry belongs to. Defaults to `lunora`.
2800
+ */
2801
+ serviceName?: string;
2802
+ /**
2803
+ * Convenience bearer token: when set, an `Authorization: Bearer` header
2804
+ * carrying it is added to every POST (overriding any authorization in
2805
+ * `headers`). Mirrors the container exporter so the platform can inject the
2806
+ * same `LUNORA_OTLP_TOKEN` into both. Leave unset for an unauthenticated collector.
2807
+ */
2808
+ token?: string;
2809
+ }
2810
+ /**
2811
+ * A fire-and-forget sink that exports telemetry over OTLP-over-HTTP (JSON).
2812
+ *
2813
+ * This is the single, standard wire contract both the worker and (via the
2814
+ * container exporter helper) container processes use, so telemetry from either
2815
+ * side lands in the same collector. Each RPC dispatch becomes one OTLP **span**
2816
+ * (`${endpoint}/v1/traces`) named after its `functionPath`, with start/end
2817
+ * derived from `durationMs` and status OK/ERROR; each `ctx.log.*` line becomes
2818
+ * one OTLP **log record** (`${endpoint}/v1/logs`). Trace/span ids are random
2819
+ * per span — real trace correlation (worker→container `traceparent`) is a later
2820
+ * phase.
2821
+ *
2822
+ * Like {@link webhookSink}, each export is its own `fetch`, registered with the
2823
+ * request's `context.waitUntil` when present so it survives isolate teardown,
2824
+ * and every rejection is swallowed so a flaky collector never surfaces to the
2825
+ * caller.
2826
+ *
2827
+ * Privacy: spans carry `error.type`/`error.message` and logs carry the rendered
2828
+ * `message`, which may include user input. Point `endpoint` only at a collector
2829
+ * you trust, and gate PII upstream if that is a concern.
2830
+ * @param options Sink options: `endpoint` is the collector base URL, `headers`
2831
+ * are merged onto every POST (auth + correlation), `serviceName` sets the
2832
+ * resource `service.name`, and `onlyErrors` exports error spans only.
2833
+ */
2834
+ declare const otlpSink: (options: OtlpSinkOptions) => ObservabilitySink;
2781
2835
  /**
2782
2836
  * Combine several sinks into one that fans each event out to all of them.
2783
2837
  *
@@ -2787,4 +2841,4 @@ declare const analyticsEngineSink: (options: AnalyticsEngineSinkOptions) => Obse
2787
2841
  */
2788
2842
  declare const combineSinks: (...sinks: ObservabilitySink[]) => ObservabilitySink;
2789
2843
  declare const VERSION: string;
2790
- export { type AdminTableResolver, type AirbyteMessage, type AnalyticsEngineDataPointLike, type AnalyticsEngineDatasetLike, type AnalyticsEngineSinkOptions, type AuthAdmin, type AuthCapabilities, type AuthConfigInfo, type AuthImpersonation, type AuthIntrospector, type AuthPage, type AuthSession, type AuthUser, type AuthUserFieldSpec, type BackupManifest, type BackupStore, type ComposeIdentityResolversErrorMode, type ComposeIdentityResolversOptions, type ConnectorChange, type ConnectorSyncPage, type CorsOptions, type CronHandler, type CronJobDispatch, type CronJobInfo, type CrossShardCounter, type CrossShardReader, type CrossShardRelationCapabilities, type CrossShardRelationOptions, type CsrfOptions, DEFAULT_REGISTRY_CACHE_TTL_MS, type DurableObjectJurisdiction, type DynamicShardRegistry, type DynamicShardRegistryOptions, type ExecutionContextLike, type ExportFanOutRequest, type ExportFanOutResult, type FanOutRequest, type FanOutResult, type FanOutSpec, type FivetranResponse, type FrameworkHostHandler, type FrameworkWorkerOptions, type FrameworkWorkerOptionsInput, type FunctionDescriptor, type FunctionRegistryEntry, type FunctionRegistryLike, type GlobalExportFunction as GlobalExportFn, type GlobalImportFunction as GlobalImportFn, type GlobalIntrospector, type GlobalTableInfo as GlobalTableInfoMeta, type GlobalTablePage as GlobalTablePageMeta, type HttpActionContext, type HttpActionLike, type HttpRouterLike, type IdentityContractLike, type IdentityResolver, type IdentityValidation, type ImportFanOutRequest, type ImportFanOutResult, type KvIntrospector, type KvKeyEntry, type KvKeyListResult, type KvNamespaceSummary, type KvValueResult, type ListAuthUsersOptions, type LogEvent, type LogLevel, LunoraError, type LunoraErrorBody, type LunoraHandlerOptions, type LunoraWorker, type MergeStrategy, type MigrationFanOutRequest, type MigrationFanOutResult, NOOP_EXECUTION_CONTEXT, type ObservabilityEvent, type ObservabilitySink, type ObservabilitySinkContext, type QueryCoordinator, type QueryCoordinatorOptions, type RankFanOutRequest, type RankFanOutResult, type RankPageFanOutRequest, type RankPageFanOutResult, type ResolvedSecurity, type ResolvedShard, type Route, type RpcContext, type RpcEnvelope, SHARD_REGISTRY_DO_NAME, type ScheduledControllerLike, type SecurityHeadersOptions, type SecurityOptions, type SentrySinkOptions, type ShardError, type ShardExportOutcome, type ShardImportOutcome, type ShardMigrationOutcome, type ShardNamespaceLike, type ShardRankOutcome, type ShardRankPageOutcome, type ShardRegistry, type ShardTrafficEntry, type ShardTrafficFanOutRequest, type ShardTrafficFanOutResult, type ShardingInfo, type StorageListFunction as StorageListFn, type StorageObject, VERSION, type VectorIndexSummary, type VectorIntrospector, type VectorQueryMatch, type WebhookSinkOptions, type WorkerOptions, analyticsEngineSink, applyJurisdiction, combineSinks, composeIdentityResolvers, composeWorker, consoleSink, createCrossShardRelationCapabilities, createDynamicShardRegistry, createLunoraHandler, createQueryCoordinator, createStaticShardRegistry, createWorker, decorateResponse, defineRpcEnvelope, emitLogEvent, emitRpcEvent, enforceOrigin, handleCorsPreflight, mergeStrategyForAggregate, resolveLunoraOptions, resolveSecurity, resolveShard, routeIdentityResolvers, sentrySink, toAirbyteMessages, toErrorResponse, toFivetranResponse, webhookSink, withFrameworkWorker };
2844
+ export { type AdminTableResolver, type AirbyteMessage, type AnalyticsEngineDataPointLike, type AnalyticsEngineDatasetLike, type AnalyticsEngineSinkOptions, type AuthAdmin, type AuthCapabilities, type AuthConfigInfo, type AuthImpersonation, type AuthIntrospector, type AuthPage, type AuthSession, type AuthUser, type AuthUserFieldSpec, type BackupManifest, type BackupStore, type ComposeIdentityResolversErrorMode, type ComposeIdentityResolversOptions, type ConnectorChange, type ConnectorSyncPage, type CorsOptions, type CronHandler, type CronJobDispatch, type CronJobInfo, type CrossShardCounter, type CrossShardReader, type CrossShardRelationCapabilities, type CrossShardRelationOptions, type CsrfOptions, DEFAULT_REGISTRY_CACHE_TTL_MS, type DurableObjectJurisdiction, type DynamicShardRegistry, type DynamicShardRegistryOptions, type ExecutionContextLike, type ExportFanOutRequest, type ExportFanOutResult, type FanOutRequest, type FanOutResult, type FanOutSpec, type FivetranResponse, type FrameworkHostHandler, type FrameworkWorkerOptions, type FrameworkWorkerOptionsInput, type FunctionDescriptor, type FunctionRegistryEntry, type FunctionRegistryLike, type GlobalExportFunction as GlobalExportFn, type GlobalImportFunction as GlobalImportFn, type GlobalIntrospector, type GlobalTableInfo as GlobalTableInfoMeta, type GlobalTablePage as GlobalTablePageMeta, type HttpActionContext, type HttpActionLike, type HttpRouterLike, type IdentityContractLike, type IdentityResolver, type IdentityValidation, type ImportFanOutRequest, type ImportFanOutResult, type KvIntrospector, type KvKeyEntry, type KvKeyListResult, type KvNamespaceSummary, type KvValueResult, type ListAuthUsersOptions, type LogEvent, type LogLevel, LunoraError, type LunoraErrorBody, type LunoraHandlerOptions, type LunoraWorker, type MergeStrategy, type MigrationFanOutRequest, type MigrationFanOutResult, NOOP_EXECUTION_CONTEXT, type ObservabilityEvent, type ObservabilitySink, type ObservabilitySinkContext, type OtlpSinkOptions, type QueryCoordinator, type QueryCoordinatorOptions, type RankFanOutRequest, type RankFanOutResult, type RankPageFanOutRequest, type RankPageFanOutResult, type ResolvedSecurity, type ResolvedShard, type Route, type RpcContext, type RpcEnvelope, SHARD_REGISTRY_DO_NAME, type ScheduledControllerLike, type SecurityHeadersOptions, type SecurityOptions, type SentrySinkOptions, type ShardError, type ShardExportOutcome, type ShardImportOutcome, type ShardMigrationOutcome, type ShardNamespaceLike, type ShardRankOutcome, type ShardRankPageOutcome, type ShardRegistry, type ShardTrafficEntry, type ShardTrafficFanOutRequest, type ShardTrafficFanOutResult, type ShardingInfo, type StorageListFunction as StorageListFn, type StorageObject, VERSION, type VectorIndexSummary, type VectorIntrospector, type VectorQueryMatch, type WebhookSinkOptions, type WorkerOptions, analyticsEngineSink, applyJurisdiction, combineSinks, composeIdentityResolvers, composeWorker, consoleSink, createCrossShardRelationCapabilities, createDynamicShardRegistry, createLunoraHandler, createQueryCoordinator, createStaticShardRegistry, createWorker, decorateResponse, defineRpcEnvelope, emitLogEvent, emitRpcEvent, enforceOrigin, handleCorsPreflight, mergeStrategyForAggregate, otlpSink, resolveLunoraOptions, resolveSecurity, resolveShard, routeIdentityResolvers, sentrySink, toAirbyteMessages, toErrorResponse, toFivetranResponse, webhookSink, withFrameworkWorker };
package/dist/index.d.ts CHANGED
@@ -2778,6 +2778,60 @@ interface AnalyticsEngineSinkOptions extends OnlyErrorsOption {
2778
2778
  * only error events (defaults to all events).
2779
2779
  */
2780
2780
  declare const analyticsEngineSink: (options: AnalyticsEngineSinkOptions) => ObservabilitySink;
2781
+ /** Options for {@link otlpSink}. */
2782
+ interface OtlpSinkOptions extends OnlyErrorsOption {
2783
+ /**
2784
+ * The OTLP-over-HTTP collector base endpoint (e.g.
2785
+ * `https://collector.example.com`). Following the OTel base-endpoint
2786
+ * convention, the sink POSTs spans to `${endpoint}/v1/traces` and log
2787
+ * records to `${endpoint}/v1/logs`; a trailing slash is tolerated.
2788
+ */
2789
+ endpoint: string;
2790
+ /**
2791
+ * Extra headers merged onto every OTLP POST — typically an `Authorization`
2792
+ * bearer plus the `x-lunora-deployment` / `x-lunora-org` correlation headers
2793
+ * the platform injects at deploy. `Content-Type: application/json` is set by
2794
+ * default and may be overridden here.
2795
+ */
2796
+ headers?: Record<string, string>;
2797
+ /**
2798
+ * Value of the `service.name` resource attribute on every exported span and
2799
+ * log — the logical service the telemetry belongs to. Defaults to `lunora`.
2800
+ */
2801
+ serviceName?: string;
2802
+ /**
2803
+ * Convenience bearer token: when set, an `Authorization: Bearer` header
2804
+ * carrying it is added to every POST (overriding any authorization in
2805
+ * `headers`). Mirrors the container exporter so the platform can inject the
2806
+ * same `LUNORA_OTLP_TOKEN` into both. Leave unset for an unauthenticated collector.
2807
+ */
2808
+ token?: string;
2809
+ }
2810
+ /**
2811
+ * A fire-and-forget sink that exports telemetry over OTLP-over-HTTP (JSON).
2812
+ *
2813
+ * This is the single, standard wire contract both the worker and (via the
2814
+ * container exporter helper) container processes use, so telemetry from either
2815
+ * side lands in the same collector. Each RPC dispatch becomes one OTLP **span**
2816
+ * (`${endpoint}/v1/traces`) named after its `functionPath`, with start/end
2817
+ * derived from `durationMs` and status OK/ERROR; each `ctx.log.*` line becomes
2818
+ * one OTLP **log record** (`${endpoint}/v1/logs`). Trace/span ids are random
2819
+ * per span — real trace correlation (worker→container `traceparent`) is a later
2820
+ * phase.
2821
+ *
2822
+ * Like {@link webhookSink}, each export is its own `fetch`, registered with the
2823
+ * request's `context.waitUntil` when present so it survives isolate teardown,
2824
+ * and every rejection is swallowed so a flaky collector never surfaces to the
2825
+ * caller.
2826
+ *
2827
+ * Privacy: spans carry `error.type`/`error.message` and logs carry the rendered
2828
+ * `message`, which may include user input. Point `endpoint` only at a collector
2829
+ * you trust, and gate PII upstream if that is a concern.
2830
+ * @param options Sink options: `endpoint` is the collector base URL, `headers`
2831
+ * are merged onto every POST (auth + correlation), `serviceName` sets the
2832
+ * resource `service.name`, and `onlyErrors` exports error spans only.
2833
+ */
2834
+ declare const otlpSink: (options: OtlpSinkOptions) => ObservabilitySink;
2781
2835
  /**
2782
2836
  * Combine several sinks into one that fans each event out to all of them.
2783
2837
  *
@@ -2787,4 +2841,4 @@ declare const analyticsEngineSink: (options: AnalyticsEngineSinkOptions) => Obse
2787
2841
  */
2788
2842
  declare const combineSinks: (...sinks: ObservabilitySink[]) => ObservabilitySink;
2789
2843
  declare const VERSION: string;
2790
- export { type AdminTableResolver, type AirbyteMessage, type AnalyticsEngineDataPointLike, type AnalyticsEngineDatasetLike, type AnalyticsEngineSinkOptions, type AuthAdmin, type AuthCapabilities, type AuthConfigInfo, type AuthImpersonation, type AuthIntrospector, type AuthPage, type AuthSession, type AuthUser, type AuthUserFieldSpec, type BackupManifest, type BackupStore, type ComposeIdentityResolversErrorMode, type ComposeIdentityResolversOptions, type ConnectorChange, type ConnectorSyncPage, type CorsOptions, type CronHandler, type CronJobDispatch, type CronJobInfo, type CrossShardCounter, type CrossShardReader, type CrossShardRelationCapabilities, type CrossShardRelationOptions, type CsrfOptions, DEFAULT_REGISTRY_CACHE_TTL_MS, type DurableObjectJurisdiction, type DynamicShardRegistry, type DynamicShardRegistryOptions, type ExecutionContextLike, type ExportFanOutRequest, type ExportFanOutResult, type FanOutRequest, type FanOutResult, type FanOutSpec, type FivetranResponse, type FrameworkHostHandler, type FrameworkWorkerOptions, type FrameworkWorkerOptionsInput, type FunctionDescriptor, type FunctionRegistryEntry, type FunctionRegistryLike, type GlobalExportFunction as GlobalExportFn, type GlobalImportFunction as GlobalImportFn, type GlobalIntrospector, type GlobalTableInfo as GlobalTableInfoMeta, type GlobalTablePage as GlobalTablePageMeta, type HttpActionContext, type HttpActionLike, type HttpRouterLike, type IdentityContractLike, type IdentityResolver, type IdentityValidation, type ImportFanOutRequest, type ImportFanOutResult, type KvIntrospector, type KvKeyEntry, type KvKeyListResult, type KvNamespaceSummary, type KvValueResult, type ListAuthUsersOptions, type LogEvent, type LogLevel, LunoraError, type LunoraErrorBody, type LunoraHandlerOptions, type LunoraWorker, type MergeStrategy, type MigrationFanOutRequest, type MigrationFanOutResult, NOOP_EXECUTION_CONTEXT, type ObservabilityEvent, type ObservabilitySink, type ObservabilitySinkContext, type QueryCoordinator, type QueryCoordinatorOptions, type RankFanOutRequest, type RankFanOutResult, type RankPageFanOutRequest, type RankPageFanOutResult, type ResolvedSecurity, type ResolvedShard, type Route, type RpcContext, type RpcEnvelope, SHARD_REGISTRY_DO_NAME, type ScheduledControllerLike, type SecurityHeadersOptions, type SecurityOptions, type SentrySinkOptions, type ShardError, type ShardExportOutcome, type ShardImportOutcome, type ShardMigrationOutcome, type ShardNamespaceLike, type ShardRankOutcome, type ShardRankPageOutcome, type ShardRegistry, type ShardTrafficEntry, type ShardTrafficFanOutRequest, type ShardTrafficFanOutResult, type ShardingInfo, type StorageListFunction as StorageListFn, type StorageObject, VERSION, type VectorIndexSummary, type VectorIntrospector, type VectorQueryMatch, type WebhookSinkOptions, type WorkerOptions, analyticsEngineSink, applyJurisdiction, combineSinks, composeIdentityResolvers, composeWorker, consoleSink, createCrossShardRelationCapabilities, createDynamicShardRegistry, createLunoraHandler, createQueryCoordinator, createStaticShardRegistry, createWorker, decorateResponse, defineRpcEnvelope, emitLogEvent, emitRpcEvent, enforceOrigin, handleCorsPreflight, mergeStrategyForAggregate, resolveLunoraOptions, resolveSecurity, resolveShard, routeIdentityResolvers, sentrySink, toAirbyteMessages, toErrorResponse, toFivetranResponse, webhookSink, withFrameworkWorker };
2844
+ export { type AdminTableResolver, type AirbyteMessage, type AnalyticsEngineDataPointLike, type AnalyticsEngineDatasetLike, type AnalyticsEngineSinkOptions, type AuthAdmin, type AuthCapabilities, type AuthConfigInfo, type AuthImpersonation, type AuthIntrospector, type AuthPage, type AuthSession, type AuthUser, type AuthUserFieldSpec, type BackupManifest, type BackupStore, type ComposeIdentityResolversErrorMode, type ComposeIdentityResolversOptions, type ConnectorChange, type ConnectorSyncPage, type CorsOptions, type CronHandler, type CronJobDispatch, type CronJobInfo, type CrossShardCounter, type CrossShardReader, type CrossShardRelationCapabilities, type CrossShardRelationOptions, type CsrfOptions, DEFAULT_REGISTRY_CACHE_TTL_MS, type DurableObjectJurisdiction, type DynamicShardRegistry, type DynamicShardRegistryOptions, type ExecutionContextLike, type ExportFanOutRequest, type ExportFanOutResult, type FanOutRequest, type FanOutResult, type FanOutSpec, type FivetranResponse, type FrameworkHostHandler, type FrameworkWorkerOptions, type FrameworkWorkerOptionsInput, type FunctionDescriptor, type FunctionRegistryEntry, type FunctionRegistryLike, type GlobalExportFunction as GlobalExportFn, type GlobalImportFunction as GlobalImportFn, type GlobalIntrospector, type GlobalTableInfo as GlobalTableInfoMeta, type GlobalTablePage as GlobalTablePageMeta, type HttpActionContext, type HttpActionLike, type HttpRouterLike, type IdentityContractLike, type IdentityResolver, type IdentityValidation, type ImportFanOutRequest, type ImportFanOutResult, type KvIntrospector, type KvKeyEntry, type KvKeyListResult, type KvNamespaceSummary, type KvValueResult, type ListAuthUsersOptions, type LogEvent, type LogLevel, LunoraError, type LunoraErrorBody, type LunoraHandlerOptions, type LunoraWorker, type MergeStrategy, type MigrationFanOutRequest, type MigrationFanOutResult, NOOP_EXECUTION_CONTEXT, type ObservabilityEvent, type ObservabilitySink, type ObservabilitySinkContext, type OtlpSinkOptions, type QueryCoordinator, type QueryCoordinatorOptions, type RankFanOutRequest, type RankFanOutResult, type RankPageFanOutRequest, type RankPageFanOutResult, type ResolvedSecurity, type ResolvedShard, type Route, type RpcContext, type RpcEnvelope, SHARD_REGISTRY_DO_NAME, type ScheduledControllerLike, type SecurityHeadersOptions, type SecurityOptions, type SentrySinkOptions, type ShardError, type ShardExportOutcome, type ShardImportOutcome, type ShardMigrationOutcome, type ShardNamespaceLike, type ShardRankOutcome, type ShardRankPageOutcome, type ShardRegistry, type ShardTrafficEntry, type ShardTrafficFanOutRequest, type ShardTrafficFanOutResult, type ShardingInfo, type StorageListFunction as StorageListFn, type StorageObject, VERSION, type VectorIndexSummary, type VectorIntrospector, type VectorQueryMatch, type WebhookSinkOptions, type WorkerOptions, analyticsEngineSink, applyJurisdiction, combineSinks, composeIdentityResolvers, composeWorker, consoleSink, createCrossShardRelationCapabilities, createDynamicShardRegistry, createLunoraHandler, createQueryCoordinator, createStaticShardRegistry, createWorker, decorateResponse, defineRpcEnvelope, emitLogEvent, emitRpcEvent, enforceOrigin, handleCorsPreflight, mergeStrategyForAggregate, otlpSink, resolveLunoraOptions, resolveSecurity, resolveShard, routeIdentityResolvers, sentrySink, toAirbyteMessages, toErrorResponse, toFivetranResponse, webhookSink, withFrameworkWorker };
package/dist/index.mjs CHANGED
@@ -4,7 +4,7 @@ export { createCrossShardRelationCapabilities } from './packem_shared/createCros
4
4
  export { DEFAULT_REGISTRY_CACHE_TTL_MS, SHARD_REGISTRY_DO_NAME, createDynamicShardRegistry } from './packem_shared/DEFAULT_REGISTRY_CACHE_TTL_MS-B3pA7aXp.mjs';
5
5
  export { LunoraError, toErrorResponse } from './packem_shared/LunoraError-Bpb9EFJ3.mjs';
6
6
  export { emitLogEvent, emitRpcEvent } from './packem_shared/emitLogEvent-pEdtqAK8.mjs';
7
- export { analyticsEngineSink, combineSinks, consoleSink, sentrySink, webhookSink } from './packem_shared/analyticsEngineSink-DqEvrQs0.mjs';
7
+ export { analyticsEngineSink, combineSinks, consoleSink, otlpSink, sentrySink, webhookSink } from './packem_shared/analyticsEngineSink-BpJlA7e9.mjs';
8
8
  export { createQueryCoordinator, createStaticShardRegistry, mergeStrategyForAggregate } from './packem_shared/createQueryCoordinator-DNCJzOZE.mjs';
9
9
  export { applyJurisdiction, resolveShard } from './packem_shared/applyJurisdiction-BkZtTkct.mjs';
10
10
  export { decorateResponse, enforceOrigin, handleCorsPreflight, resolveSecurity } from './packem_shared/decorateResponse-DRWQFNhF.mjs';
@@ -0,0 +1,275 @@
1
+ const OTLP_SEVERITY = {
2
+ debug: 5,
3
+ // DEBUG
4
+ error: 17,
5
+ // ERROR
6
+ info: 9,
7
+ // INFO
8
+ log: 9,
9
+ // INFO
10
+ warn: 13
11
+ // WARN
12
+ };
13
+ const otlpUnixNano = (ms) => `${String(Math.round(ms))}000000`;
14
+ const otlpRandomHex = (bytes) => {
15
+ const buffer = new Uint8Array(bytes);
16
+ crypto.getRandomValues(buffer);
17
+ let hex = "";
18
+ for (const byte of buffer) {
19
+ hex += byte.toString(16).padStart(2, "0");
20
+ }
21
+ return hex;
22
+ };
23
+ const encodeAttribute = (key, value) => {
24
+ if (typeof value === "boolean") {
25
+ return { key, value: { boolValue: value } };
26
+ }
27
+ if (typeof value === "number") {
28
+ if (!Number.isFinite(value)) {
29
+ return { key, value: { stringValue: String(value) } };
30
+ }
31
+ return Number.isSafeInteger(value) ? { key, value: { intValue: String(value) } } : { key, value: { doubleValue: value } };
32
+ }
33
+ return { key, value: { stringValue: value } };
34
+ };
35
+ const mergeHeaders = (defaults, overrides, token) => {
36
+ const merged = {};
37
+ const seen = /* @__PURE__ */ new Map();
38
+ const put = (name, value) => {
39
+ const lower = name.toLowerCase();
40
+ const existing = seen.get(lower);
41
+ if (existing === void 0) {
42
+ seen.set(lower, name);
43
+ merged[name] = value;
44
+ } else {
45
+ merged[existing] = value;
46
+ }
47
+ };
48
+ for (const [name, value] of Object.entries(defaults)) {
49
+ put(name, value);
50
+ }
51
+ for (const [name, value] of Object.entries(overrides ?? {})) {
52
+ put(name, value);
53
+ }
54
+ if (token !== void 0 && token.length > 0) {
55
+ put("authorization", `Bearer ${token}`);
56
+ }
57
+ return merged;
58
+ };
59
+ const wrapResourceSpans = (span, scopeName, serviceName) => {
60
+ return {
61
+ resourceSpans: [
62
+ {
63
+ resource: { attributes: [encodeAttribute("service.name", serviceName)] },
64
+ scopeSpans: [{ scope: { name: scopeName }, spans: [span] }]
65
+ }
66
+ ]
67
+ };
68
+ };
69
+ const wrapResourceLogs = (logRecord, scopeName, serviceName) => {
70
+ return {
71
+ resourceLogs: [
72
+ {
73
+ resource: { attributes: [encodeAttribute("service.name", serviceName)] },
74
+ scopeLogs: [{ logRecords: [logRecord], scope: { name: scopeName } }]
75
+ }
76
+ ]
77
+ };
78
+ };
79
+
80
+ const shouldSkip = (event, onlyErrors) => onlyErrors === true && event.ok;
81
+ const otlpTraceBody = (event, serviceName, endMs) => {
82
+ const attributes = [encodeAttribute("lunora.function_path", event.functionPath), encodeAttribute("lunora.ok", event.ok)];
83
+ if (event.shardKey !== void 0) {
84
+ attributes.push(encodeAttribute("lunora.shard_key", event.shardKey));
85
+ }
86
+ if (event.error) {
87
+ attributes.push(encodeAttribute("error.type", event.error.code), encodeAttribute("lunora.error_status", event.error.status));
88
+ }
89
+ if (event.fanOut) {
90
+ attributes.push(
91
+ encodeAttribute("lunora.fanout.table", event.fanOut.table),
92
+ encodeAttribute("lunora.fanout.shards", event.fanOut.shards),
93
+ encodeAttribute("lunora.fanout.failed", event.fanOut.failed)
94
+ );
95
+ }
96
+ const span = {
97
+ attributes,
98
+ endTimeUnixNano: otlpUnixNano(endMs),
99
+ // SPAN_KIND_SERVER — a dispatched RPC is server-side request handling.
100
+ kind: 2,
101
+ name: event.functionPath,
102
+ spanId: otlpRandomHex(8),
103
+ startTimeUnixNano: otlpUnixNano(endMs - event.durationMs),
104
+ // STATUS_CODE_OK (1) / STATUS_CODE_ERROR (2).
105
+ status: event.ok ? { code: 1 } : { code: 2, message: event.error?.message ?? "" },
106
+ traceId: otlpRandomHex(16)
107
+ };
108
+ return wrapResourceSpans(span, "@lunora/runtime", serviceName);
109
+ };
110
+ const otlpLogBody = (event, serviceName) => {
111
+ const attributes = [encodeAttribute("lunora.function_path", event.functionPath)];
112
+ if (event.shardKey !== void 0) {
113
+ attributes.push(encodeAttribute("lunora.shard_key", event.shardKey));
114
+ }
115
+ if (event.userId !== void 0) {
116
+ attributes.push(encodeAttribute("lunora.user_id", event.userId));
117
+ }
118
+ const logRecord = {
119
+ attributes,
120
+ body: { stringValue: event.message },
121
+ severityNumber: OTLP_SEVERITY[event.level],
122
+ severityText: event.level.toUpperCase(),
123
+ timeUnixNano: otlpUnixNano(event.ts)
124
+ };
125
+ return wrapResourceLogs(logRecord, "@lunora/runtime", serviceName);
126
+ };
127
+ const otlpPost = (url, body, headers, context) => {
128
+ try {
129
+ const sent = fetch(url, { body: JSON.stringify(body), headers, method: "POST" }).catch(() => {
130
+ });
131
+ if (context?.waitUntil) {
132
+ context.waitUntil(sent);
133
+ }
134
+ } catch {
135
+ }
136
+ };
137
+ const consoleSink = (options = {}) => {
138
+ const { onlyErrors } = options;
139
+ return {
140
+ onLog: (event) => {
141
+ if (event.level === "error") {
142
+ console.error("[lunora:log]", event.functionPath, event.message);
143
+ } else {
144
+ console.log("[lunora:log]", event.functionPath, event.message);
145
+ }
146
+ },
147
+ onRpc: (event) => {
148
+ if (shouldSkip(event, onlyErrors)) {
149
+ return;
150
+ }
151
+ if (event.ok) {
152
+ console.log("[lunora:rpc]", event);
153
+ } else {
154
+ console.error("[lunora:rpc]", event);
155
+ }
156
+ }
157
+ };
158
+ };
159
+ const webhookSink = (options) => {
160
+ const { headers, onlyErrors, transform, url } = options;
161
+ const mergedHeaders = mergeHeaders({ "content-type": "application/json" }, headers);
162
+ return {
163
+ onRpc: (event, context) => {
164
+ if (shouldSkip(event, onlyErrors)) {
165
+ return;
166
+ }
167
+ try {
168
+ let payload = event;
169
+ if (transform) {
170
+ try {
171
+ payload = transform(event);
172
+ } catch {
173
+ return;
174
+ }
175
+ }
176
+ if (payload === null || payload === void 0) {
177
+ return;
178
+ }
179
+ const sent = fetch(url, {
180
+ body: JSON.stringify(payload),
181
+ headers: mergedHeaders,
182
+ method: "POST"
183
+ }).catch(() => {
184
+ });
185
+ if (context?.waitUntil) {
186
+ context.waitUntil(sent);
187
+ }
188
+ } catch {
189
+ }
190
+ }
191
+ };
192
+ };
193
+ const sentrySink = (options) => {
194
+ const { capture } = options;
195
+ const onlyErrors = options.onlyErrors ?? true;
196
+ return {
197
+ onRpc: (event) => {
198
+ if (shouldSkip(event, onlyErrors)) {
199
+ return;
200
+ }
201
+ try {
202
+ capture(event);
203
+ } catch {
204
+ }
205
+ }
206
+ };
207
+ };
208
+ const analyticsEngineSink = (options) => {
209
+ const { dataset, onlyErrors } = options;
210
+ return {
211
+ onRpc: (event) => {
212
+ if (shouldSkip(event, onlyErrors)) {
213
+ return;
214
+ }
215
+ try {
216
+ dataset.writeDataPoint({
217
+ blobs: [event.functionPath, event.ok ? "ok" : "error", event.shardKey ?? "", event.error?.code ?? "", event.fanOut?.table ?? ""],
218
+ doubles: [event.durationMs, event.ok ? 0 : 1, event.fanOut?.shards ?? 0, event.fanOut?.failed ?? 0],
219
+ indexes: [event.functionPath]
220
+ });
221
+ } catch {
222
+ }
223
+ }
224
+ };
225
+ };
226
+ const otlpSink = (options) => {
227
+ const { endpoint, headers, onlyErrors, token } = options;
228
+ const serviceName = options.serviceName ?? "lunora";
229
+ let base = endpoint;
230
+ while (base.endsWith("/")) {
231
+ base = base.slice(0, -1);
232
+ }
233
+ const tracesUrl = `${base}/v1/traces`;
234
+ const logsUrl = `${base}/v1/logs`;
235
+ const mergedHeaders = mergeHeaders({ "content-type": "application/json" }, headers, token);
236
+ return {
237
+ onLog: (event, context) => {
238
+ otlpPost(logsUrl, otlpLogBody(event, serviceName), mergedHeaders, context);
239
+ },
240
+ onRpc: (event, context) => {
241
+ if (shouldSkip(event, onlyErrors)) {
242
+ return;
243
+ }
244
+ otlpPost(tracesUrl, otlpTraceBody(event, serviceName, Date.now()), mergedHeaders, context);
245
+ }
246
+ };
247
+ };
248
+ const combineSinks = (...sinks) => {
249
+ return {
250
+ onLog: (event, context) => {
251
+ for (const sink of sinks) {
252
+ if (!sink.onLog) {
253
+ continue;
254
+ }
255
+ try {
256
+ sink.onLog(event, context);
257
+ } catch {
258
+ }
259
+ }
260
+ },
261
+ onRpc: (event, context) => {
262
+ for (const sink of sinks) {
263
+ if (!sink.onRpc) {
264
+ continue;
265
+ }
266
+ try {
267
+ sink.onRpc(event, context);
268
+ } catch {
269
+ }
270
+ }
271
+ }
272
+ };
273
+ };
274
+
275
+ export { analyticsEngineSink, combineSinks, consoleSink, otlpSink, sentrySink, webhookSink };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lunora/runtime",
3
- "version": "1.0.0-alpha.24",
3
+ "version": "1.0.0-alpha.25",
4
4
  "description": "Lunora Worker runtime: the RPC router, shard resolver, and query coordinator",
5
5
  "keywords": [
6
6
  "cloudflare",
@@ -1,141 +0,0 @@
1
- const shouldSkip = (event, onlyErrors) => onlyErrors === true && event.ok;
2
- const mergeHeaders = (defaults, overrides) => {
3
- if (!overrides) {
4
- return { ...defaults };
5
- }
6
- const merged = {};
7
- const seen = /* @__PURE__ */ new Map();
8
- for (const [name, value] of Object.entries(defaults)) {
9
- const lower = name.toLowerCase();
10
- seen.set(lower, name);
11
- merged[name] = value;
12
- }
13
- for (const [name, value] of Object.entries(overrides)) {
14
- const lower = name.toLowerCase();
15
- const existing = seen.get(lower);
16
- if (existing === void 0) {
17
- seen.set(lower, name);
18
- merged[name] = value;
19
- } else {
20
- merged[existing] = value;
21
- }
22
- }
23
- return merged;
24
- };
25
- const consoleSink = (options = {}) => {
26
- const { onlyErrors } = options;
27
- return {
28
- onLog: (event) => {
29
- if (event.level === "error") {
30
- console.error("[lunora:log]", event.functionPath, event.message);
31
- } else {
32
- console.log("[lunora:log]", event.functionPath, event.message);
33
- }
34
- },
35
- onRpc: (event) => {
36
- if (shouldSkip(event, onlyErrors)) {
37
- return;
38
- }
39
- if (event.ok) {
40
- console.log("[lunora:rpc]", event);
41
- } else {
42
- console.error("[lunora:rpc]", event);
43
- }
44
- }
45
- };
46
- };
47
- const webhookSink = (options) => {
48
- const { headers, onlyErrors, transform, url } = options;
49
- const mergedHeaders = mergeHeaders({ "content-type": "application/json" }, headers);
50
- return {
51
- onRpc: (event, context) => {
52
- if (shouldSkip(event, onlyErrors)) {
53
- return;
54
- }
55
- try {
56
- let payload = event;
57
- if (transform) {
58
- try {
59
- payload = transform(event);
60
- } catch {
61
- return;
62
- }
63
- }
64
- if (payload === null || payload === void 0) {
65
- return;
66
- }
67
- const sent = fetch(url, {
68
- body: JSON.stringify(payload),
69
- headers: mergedHeaders,
70
- method: "POST"
71
- }).catch(() => {
72
- });
73
- if (context?.waitUntil) {
74
- context.waitUntil(sent);
75
- }
76
- } catch {
77
- }
78
- }
79
- };
80
- };
81
- const sentrySink = (options) => {
82
- const { capture } = options;
83
- const onlyErrors = options.onlyErrors ?? true;
84
- return {
85
- onRpc: (event) => {
86
- if (shouldSkip(event, onlyErrors)) {
87
- return;
88
- }
89
- try {
90
- capture(event);
91
- } catch {
92
- }
93
- }
94
- };
95
- };
96
- const analyticsEngineSink = (options) => {
97
- const { dataset, onlyErrors } = options;
98
- return {
99
- onRpc: (event) => {
100
- if (shouldSkip(event, onlyErrors)) {
101
- return;
102
- }
103
- try {
104
- dataset.writeDataPoint({
105
- blobs: [event.functionPath, event.ok ? "ok" : "error", event.shardKey ?? "", event.error?.code ?? "", event.fanOut?.table ?? ""],
106
- doubles: [event.durationMs, event.ok ? 0 : 1, event.fanOut?.shards ?? 0, event.fanOut?.failed ?? 0],
107
- indexes: [event.functionPath]
108
- });
109
- } catch {
110
- }
111
- }
112
- };
113
- };
114
- const combineSinks = (...sinks) => {
115
- return {
116
- onLog: (event, context) => {
117
- for (const sink of sinks) {
118
- if (!sink.onLog) {
119
- continue;
120
- }
121
- try {
122
- sink.onLog(event, context);
123
- } catch {
124
- }
125
- }
126
- },
127
- onRpc: (event, context) => {
128
- for (const sink of sinks) {
129
- if (!sink.onRpc) {
130
- continue;
131
- }
132
- try {
133
- sink.onRpc(event, context);
134
- } catch {
135
- }
136
- }
137
- }
138
- };
139
- };
140
-
141
- export { analyticsEngineSink, combineSinks, consoleSink, sentrySink, webhookSink };