@atrim/instrument-node 0.7.1-dev.14fdea7.20260108231415 → 0.7.1-dev.14fdea7.20260108232436

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.
@@ -80,6 +80,53 @@ declare const createEffectTracingLayer: () => Layer.Layer<never>;
80
80
  * ```
81
81
  */
82
82
  declare const EffectTracingLive: Layer.Layer<never>;
83
+ /**
84
+ * Create a combined layer that provides both:
85
+ * 1. Effect-native HTTP tracing (via NodeSdk.layer)
86
+ * 2. Fiber-level auto-tracing (via Supervisor)
87
+ *
88
+ * This gives you automatic spans for:
89
+ * - Every HTTP request (from Effect's platform middleware)
90
+ * - Every forked fiber (from our Supervisor)
91
+ *
92
+ * No manual Effect.withSpan() calls needed.
93
+ */
94
+ declare const createCombinedTracingLayer: () => Layer.Layer<never>;
95
+ /**
96
+ * Combined tracing layer providing both HTTP and fiber-level auto-tracing
97
+ *
98
+ * This is the **most comprehensive** tracing option. You get automatic spans for:
99
+ * - Every HTTP request (from Effect's @effect/platform middleware)
100
+ * - Every forked fiber (from our Supervisor)
101
+ *
102
+ * No manual Effect.withSpan() calls needed - everything is traced automatically.
103
+ *
104
+ * @example
105
+ * ```yaml
106
+ * # instrumentation.yaml
107
+ * effect:
108
+ * auto_instrumentation:
109
+ * enabled: true
110
+ * granularity: fiber
111
+ * exporter_config:
112
+ * type: otlp
113
+ * endpoint: http://localhost:4318
114
+ * ```
115
+ *
116
+ * @example
117
+ * ```typescript
118
+ * import { CombinedTracingLive } from '@atrim/instrument-node/effect/auto'
119
+ *
120
+ * const HttpLive = router.pipe(
121
+ * HttpServer.serve(),
122
+ * Layer.provide(ServerLive),
123
+ * Layer.provide(CombinedTracingLive),
124
+ * )
125
+ *
126
+ * // Both HTTP requests AND forked fibers are auto-traced!
127
+ * ```
128
+ */
129
+ declare const CombinedTracingLive: Layer.Layer<never>;
83
130
 
84
131
  /**
85
132
  * Auto-Tracing Supervisor for Effect-TS
@@ -434,4 +481,4 @@ declare function inferSpanName(fiberId: number, sourceInfo: SourceInfo | undefin
434
481
  */
435
482
  declare function sanitizeSpanName(name: string): string;
436
483
 
437
- export { AutoTracingConfig, AutoTracingConfigLayer, AutoTracingConfigLive, AutoTracingEnabled, AutoTracingLive, AutoTracingSpanName, AutoTracingSupervisor, EffectTracingLive, FullAutoTracingLive, type SourceInfo, type TemplateVariables, createAutoTracingLayer, createAutoTracingSupervisor, createEffectTracingLayer, createFullAutoTracingLayer, defaultAutoTracingConfig, inferSpanName, loadAutoTracingConfig, loadAutoTracingConfigSync, sanitizeSpanName, setSpanName, withAutoTracing, withoutAutoTracing };
484
+ export { AutoTracingConfig, AutoTracingConfigLayer, AutoTracingConfigLive, AutoTracingEnabled, AutoTracingLive, AutoTracingSpanName, AutoTracingSupervisor, CombinedTracingLive, EffectTracingLive, FullAutoTracingLive, type SourceInfo, type TemplateVariables, createAutoTracingLayer, createAutoTracingSupervisor, createCombinedTracingLayer, createEffectTracingLayer, createFullAutoTracingLayer, defaultAutoTracingConfig, inferSpanName, loadAutoTracingConfig, loadAutoTracingConfigSync, sanitizeSpanName, setSpanName, withAutoTracing, withoutAutoTracing };
@@ -80,6 +80,53 @@ declare const createEffectTracingLayer: () => Layer.Layer<never>;
80
80
  * ```
81
81
  */
82
82
  declare const EffectTracingLive: Layer.Layer<never>;
83
+ /**
84
+ * Create a combined layer that provides both:
85
+ * 1. Effect-native HTTP tracing (via NodeSdk.layer)
86
+ * 2. Fiber-level auto-tracing (via Supervisor)
87
+ *
88
+ * This gives you automatic spans for:
89
+ * - Every HTTP request (from Effect's platform middleware)
90
+ * - Every forked fiber (from our Supervisor)
91
+ *
92
+ * No manual Effect.withSpan() calls needed.
93
+ */
94
+ declare const createCombinedTracingLayer: () => Layer.Layer<never>;
95
+ /**
96
+ * Combined tracing layer providing both HTTP and fiber-level auto-tracing
97
+ *
98
+ * This is the **most comprehensive** tracing option. You get automatic spans for:
99
+ * - Every HTTP request (from Effect's @effect/platform middleware)
100
+ * - Every forked fiber (from our Supervisor)
101
+ *
102
+ * No manual Effect.withSpan() calls needed - everything is traced automatically.
103
+ *
104
+ * @example
105
+ * ```yaml
106
+ * # instrumentation.yaml
107
+ * effect:
108
+ * auto_instrumentation:
109
+ * enabled: true
110
+ * granularity: fiber
111
+ * exporter_config:
112
+ * type: otlp
113
+ * endpoint: http://localhost:4318
114
+ * ```
115
+ *
116
+ * @example
117
+ * ```typescript
118
+ * import { CombinedTracingLive } from '@atrim/instrument-node/effect/auto'
119
+ *
120
+ * const HttpLive = router.pipe(
121
+ * HttpServer.serve(),
122
+ * Layer.provide(ServerLive),
123
+ * Layer.provide(CombinedTracingLive),
124
+ * )
125
+ *
126
+ * // Both HTTP requests AND forked fibers are auto-traced!
127
+ * ```
128
+ */
129
+ declare const CombinedTracingLive: Layer.Layer<never>;
83
130
 
84
131
  /**
85
132
  * Auto-Tracing Supervisor for Effect-TS
@@ -434,4 +481,4 @@ declare function inferSpanName(fiberId: number, sourceInfo: SourceInfo | undefin
434
481
  */
435
482
  declare function sanitizeSpanName(name: string): string;
436
483
 
437
- export { AutoTracingConfig, AutoTracingConfigLayer, AutoTracingConfigLive, AutoTracingEnabled, AutoTracingLive, AutoTracingSpanName, AutoTracingSupervisor, EffectTracingLive, FullAutoTracingLive, type SourceInfo, type TemplateVariables, createAutoTracingLayer, createAutoTracingSupervisor, createEffectTracingLayer, createFullAutoTracingLayer, defaultAutoTracingConfig, inferSpanName, loadAutoTracingConfig, loadAutoTracingConfigSync, sanitizeSpanName, setSpanName, withAutoTracing, withoutAutoTracing };
484
+ export { AutoTracingConfig, AutoTracingConfigLayer, AutoTracingConfigLive, AutoTracingEnabled, AutoTracingLive, AutoTracingSpanName, AutoTracingSupervisor, CombinedTracingLive, EffectTracingLive, FullAutoTracingLive, type SourceInfo, type TemplateVariables, createAutoTracingLayer, createAutoTracingSupervisor, createCombinedTracingLayer, createEffectTracingLayer, createFullAutoTracingLayer, defaultAutoTracingConfig, inferSpanName, loadAutoTracingConfig, loadAutoTracingConfigSync, sanitizeSpanName, setSpanName, withAutoTracing, withoutAutoTracing };
@@ -1,6 +1,6 @@
1
1
  import { Data, Context, Effect, Layer, FiberRef, Option, Supervisor, FiberRefs, Exit } from 'effect';
2
2
  import { NodeSdk } from '@effect/opentelemetry';
3
- import { SimpleSpanProcessor, ConsoleSpanExporter, BatchSpanProcessor, BasicTracerProvider } from '@opentelemetry/sdk-trace-base';
3
+ import { BasicTracerProvider, SimpleSpanProcessor, ConsoleSpanExporter, BatchSpanProcessor } from '@opentelemetry/sdk-trace-base';
4
4
  import { OTLPTraceExporter } from '@opentelemetry/exporter-trace-otlp-http';
5
5
  import { FileSystem } from '@effect/platform/FileSystem';
6
6
  import * as HttpClient from '@effect/platform/HttpClient';
@@ -586,67 +586,6 @@ var loadFullConfig = (options) => Effect.gen(function* () {
586
586
  }
587
587
  return config;
588
588
  });
589
-
590
- // src/integrations/effect/auto/effect-tracing.ts
591
- var createEffectTracingLayer = () => {
592
- return Layer.unwrapEffect(
593
- Effect.gen(function* () {
594
- const config = yield* loadFullConfig();
595
- const serviceName = process.env.OTEL_SERVICE_NAME || "effect-service";
596
- const serviceVersion = process.env.npm_package_version || "1.0.0";
597
- const exporterConfig = config.effect?.exporter_config ?? {
598
- type: "otlp",
599
- processor: "batch"
600
- };
601
- logger.log("@atrim/auto-trace: Effect-native tracing enabled");
602
- logger.log(` Service: ${serviceName}`);
603
- logger.log(` Exporter: ${exporterConfig.type}`);
604
- if (exporterConfig.type === "none") {
605
- logger.log('@atrim/auto-trace: Exporter type is "none", using empty layer');
606
- return Layer.empty;
607
- }
608
- const createSpanProcessor = () => {
609
- if (exporterConfig.type === "console") {
610
- logger.log("@atrim/auto-trace: Using ConsoleSpanExporter with SimpleSpanProcessor");
611
- return new SimpleSpanProcessor(new ConsoleSpanExporter());
612
- }
613
- const endpoint = exporterConfig.endpoint || process.env.OTEL_EXPORTER_OTLP_ENDPOINT || "http://localhost:4318";
614
- logger.log(`@atrim/auto-trace: Using OTLPTraceExporter (${endpoint})`);
615
- const otlpConfig = {
616
- url: `${endpoint}/v1/traces`
617
- };
618
- if (exporterConfig.headers) {
619
- otlpConfig.headers = exporterConfig.headers;
620
- logger.log(`@atrim/auto-trace: Using custom headers: ${Object.keys(exporterConfig.headers).join(", ")}`);
621
- }
622
- const exporter = new OTLPTraceExporter(otlpConfig);
623
- if (exporterConfig.processor === "simple") {
624
- logger.log("@atrim/auto-trace: Using SimpleSpanProcessor");
625
- return new SimpleSpanProcessor(exporter);
626
- }
627
- const batchConfig = exporterConfig.batch ?? {
628
- scheduled_delay_millis: 1e3,
629
- max_export_batch_size: 100
630
- };
631
- logger.log("@atrim/auto-trace: Using BatchSpanProcessor");
632
- return new BatchSpanProcessor(exporter, {
633
- scheduledDelayMillis: batchConfig.scheduled_delay_millis,
634
- maxExportBatchSize: batchConfig.max_export_batch_size
635
- });
636
- };
637
- const sdkLayer = NodeSdk.layer(() => ({
638
- resource: {
639
- serviceName,
640
- serviceVersion
641
- },
642
- spanProcessor: createSpanProcessor()
643
- }));
644
- logger.log("@atrim/auto-trace: NodeSdk layer created - HTTP requests will be auto-traced");
645
- return Layer.discard(sdkLayer);
646
- })
647
- );
648
- };
649
- var EffectTracingLive = createEffectTracingLayer();
650
589
  var compiledRulesCache = /* @__PURE__ */ new WeakMap();
651
590
  function compileNamingRules(rules) {
652
591
  const cached = compiledRulesCache.get(rules);
@@ -846,11 +785,21 @@ var AutoTracingSupervisor = class extends Supervisor.AbstractSupervisor {
846
785
  const parentSpan = this.fiberSpans.get(parent.value);
847
786
  if (parentSpan) {
848
787
  parentContext = OtelApi.trace.setSpan(OtelApi.ROOT_CONTEXT, parentSpan);
788
+ } else {
789
+ const activeSpan = OtelApi.trace.getSpan(OtelApi.context.active());
790
+ if (activeSpan) {
791
+ parentContext = OtelApi.context.active();
792
+ } else if (this._rootSpan) {
793
+ parentContext = OtelApi.trace.setSpan(OtelApi.ROOT_CONTEXT, this._rootSpan);
794
+ }
795
+ }
796
+ } else {
797
+ const activeSpan = OtelApi.trace.getSpan(OtelApi.context.active());
798
+ if (activeSpan) {
799
+ parentContext = OtelApi.context.active();
849
800
  } else if (this._rootSpan) {
850
801
  parentContext = OtelApi.trace.setSpan(OtelApi.ROOT_CONTEXT, this._rootSpan);
851
802
  }
852
- } else if (this._rootSpan) {
853
- parentContext = OtelApi.trace.setSpan(OtelApi.ROOT_CONTEXT, this._rootSpan);
854
803
  }
855
804
  const span = this.tracer.startSpan(
856
805
  spanName,
@@ -1131,6 +1080,142 @@ var createFullAutoTracingLayer = () => {
1131
1080
  };
1132
1081
  var FullAutoTracingLive = createFullAutoTracingLayer();
1133
1082
 
1134
- export { AutoTracingConfig, AutoTracingConfigLayer, AutoTracingConfigLive, AutoTracingEnabled, AutoTracingLive, AutoTracingSpanName, AutoTracingSupervisor, EffectTracingLive, FullAutoTracingLive, createAutoTracingLayer, createAutoTracingSupervisor, createEffectTracingLayer, createFullAutoTracingLayer, defaultAutoTracingConfig, inferSpanName, loadAutoTracingConfig, loadAutoTracingConfigSync, sanitizeSpanName, setSpanName, withAutoTracing, withoutAutoTracing };
1083
+ // src/integrations/effect/auto/effect-tracing.ts
1084
+ var createEffectTracingLayer = () => {
1085
+ return Layer.unwrapEffect(
1086
+ Effect.gen(function* () {
1087
+ const config = yield* loadFullConfig();
1088
+ const serviceName = process.env.OTEL_SERVICE_NAME || "effect-service";
1089
+ const serviceVersion = process.env.npm_package_version || "1.0.0";
1090
+ const exporterConfig = config.effect?.exporter_config ?? {
1091
+ type: "otlp",
1092
+ processor: "batch"
1093
+ };
1094
+ logger.log("@atrim/auto-trace: Effect-native tracing enabled");
1095
+ logger.log(` Service: ${serviceName}`);
1096
+ logger.log(` Exporter: ${exporterConfig.type}`);
1097
+ if (exporterConfig.type === "none") {
1098
+ logger.log('@atrim/auto-trace: Exporter type is "none", using empty layer');
1099
+ return Layer.empty;
1100
+ }
1101
+ const createSpanProcessor = () => {
1102
+ if (exporterConfig.type === "console") {
1103
+ logger.log("@atrim/auto-trace: Using ConsoleSpanExporter with SimpleSpanProcessor");
1104
+ return new SimpleSpanProcessor(new ConsoleSpanExporter());
1105
+ }
1106
+ const endpoint = exporterConfig.endpoint || process.env.OTEL_EXPORTER_OTLP_ENDPOINT || "http://localhost:4318";
1107
+ logger.log(`@atrim/auto-trace: Using OTLPTraceExporter (${endpoint})`);
1108
+ const otlpConfig = {
1109
+ url: `${endpoint}/v1/traces`
1110
+ };
1111
+ if (exporterConfig.headers) {
1112
+ otlpConfig.headers = exporterConfig.headers;
1113
+ logger.log(`@atrim/auto-trace: Using custom headers: ${Object.keys(exporterConfig.headers).join(", ")}`);
1114
+ }
1115
+ const exporter = new OTLPTraceExporter(otlpConfig);
1116
+ if (exporterConfig.processor === "simple") {
1117
+ logger.log("@atrim/auto-trace: Using SimpleSpanProcessor");
1118
+ return new SimpleSpanProcessor(exporter);
1119
+ }
1120
+ const batchConfig = exporterConfig.batch ?? {
1121
+ scheduled_delay_millis: 1e3,
1122
+ max_export_batch_size: 100
1123
+ };
1124
+ logger.log("@atrim/auto-trace: Using BatchSpanProcessor");
1125
+ return new BatchSpanProcessor(exporter, {
1126
+ scheduledDelayMillis: batchConfig.scheduled_delay_millis,
1127
+ maxExportBatchSize: batchConfig.max_export_batch_size
1128
+ });
1129
+ };
1130
+ const sdkLayer = NodeSdk.layer(() => ({
1131
+ resource: {
1132
+ serviceName,
1133
+ serviceVersion
1134
+ },
1135
+ spanProcessor: createSpanProcessor()
1136
+ }));
1137
+ logger.log("@atrim/auto-trace: NodeSdk layer created - HTTP requests will be auto-traced");
1138
+ return Layer.discard(sdkLayer);
1139
+ })
1140
+ );
1141
+ };
1142
+ var EffectTracingLive = createEffectTracingLayer();
1143
+ var createCombinedTracingLayer = () => {
1144
+ return Layer.unwrapEffect(
1145
+ Effect.gen(function* () {
1146
+ const config = yield* loadFullConfig();
1147
+ const serviceName = process.env.OTEL_SERVICE_NAME || "effect-service";
1148
+ const serviceVersion = process.env.npm_package_version || "1.0.0";
1149
+ const exporterConfig = config.effect?.exporter_config ?? {
1150
+ type: "otlp",
1151
+ processor: "batch"
1152
+ };
1153
+ const autoConfig = config.effect?.auto_instrumentation ?? {
1154
+ enabled: true,
1155
+ granularity: "fiber",
1156
+ span_naming: {
1157
+ default: "effect.{function}",
1158
+ infer_from_source: true,
1159
+ rules: []
1160
+ },
1161
+ filter: { include: [], exclude: [] },
1162
+ performance: { sampling_rate: 1, min_duration: "0ms", max_concurrent: 0 },
1163
+ metadata: { fiber_info: true, source_location: true, parent_fiber: true }
1164
+ };
1165
+ logger.log("@atrim/auto-trace: Combined tracing enabled (HTTP + Fiber)");
1166
+ logger.log(` Service: ${serviceName}`);
1167
+ logger.log(` Exporter: ${exporterConfig.type}`);
1168
+ if (exporterConfig.type === "none") {
1169
+ logger.log('@atrim/auto-trace: Exporter type is "none", using empty layer');
1170
+ return Layer.empty;
1171
+ }
1172
+ const createSpanProcessor = () => {
1173
+ if (exporterConfig.type === "console") {
1174
+ logger.log("@atrim/auto-trace: Using ConsoleSpanExporter with SimpleSpanProcessor");
1175
+ return new SimpleSpanProcessor(new ConsoleSpanExporter());
1176
+ }
1177
+ const endpoint = exporterConfig.endpoint || process.env.OTEL_EXPORTER_OTLP_ENDPOINT || "http://localhost:4318";
1178
+ logger.log(`@atrim/auto-trace: Using OTLPTraceExporter (${endpoint})`);
1179
+ const otlpConfig = {
1180
+ url: `${endpoint}/v1/traces`
1181
+ };
1182
+ if (exporterConfig.headers) {
1183
+ otlpConfig.headers = exporterConfig.headers;
1184
+ logger.log(`@atrim/auto-trace: Using custom headers: ${Object.keys(exporterConfig.headers).join(", ")}`);
1185
+ }
1186
+ const exporter = new OTLPTraceExporter(otlpConfig);
1187
+ if (exporterConfig.processor === "simple") {
1188
+ logger.log("@atrim/auto-trace: Using SimpleSpanProcessor");
1189
+ return new SimpleSpanProcessor(exporter);
1190
+ }
1191
+ const batchConfig = exporterConfig.batch ?? {
1192
+ scheduled_delay_millis: 1e3,
1193
+ max_export_batch_size: 100
1194
+ };
1195
+ logger.log("@atrim/auto-trace: Using BatchSpanProcessor");
1196
+ return new BatchSpanProcessor(exporter, {
1197
+ scheduledDelayMillis: batchConfig.scheduled_delay_millis,
1198
+ maxExportBatchSize: batchConfig.max_export_batch_size
1199
+ });
1200
+ };
1201
+ const sdkLayer = NodeSdk.layer(() => ({
1202
+ resource: {
1203
+ serviceName,
1204
+ serviceVersion
1205
+ },
1206
+ spanProcessor: createSpanProcessor()
1207
+ }));
1208
+ const supervisor = createAutoTracingSupervisor(autoConfig);
1209
+ const supervisorLayer = Supervisor.addSupervisor(supervisor);
1210
+ logger.log("@atrim/auto-trace: Combined layer created");
1211
+ logger.log(" - HTTP requests: auto-traced via Effect platform");
1212
+ logger.log(" - Forked fibers: auto-traced via Supervisor");
1213
+ return supervisorLayer.pipe(Layer.provideMerge(Layer.discard(sdkLayer)));
1214
+ })
1215
+ );
1216
+ };
1217
+ var CombinedTracingLive = createCombinedTracingLayer();
1218
+
1219
+ export { AutoTracingConfig, AutoTracingConfigLayer, AutoTracingConfigLive, AutoTracingEnabled, AutoTracingLive, AutoTracingSpanName, AutoTracingSupervisor, CombinedTracingLive, EffectTracingLive, FullAutoTracingLive, createAutoTracingLayer, createAutoTracingSupervisor, createCombinedTracingLayer, createEffectTracingLayer, createFullAutoTracingLayer, defaultAutoTracingConfig, inferSpanName, loadAutoTracingConfig, loadAutoTracingConfigSync, sanitizeSpanName, setSpanName, withAutoTracing, withoutAutoTracing };
1135
1220
  //# sourceMappingURL=index.js.map
1136
1221
  //# sourceMappingURL=index.js.map