@atrim/instrument-node 0.5.1-dev.14fdea7.20260108231120 → 0.5.1-dev.14fdea7.20260109021657

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
@@ -119,17 +166,18 @@ declare class AutoTracingSupervisor extends Supervisor.AbstractSupervisor<void>
119
166
  private readonly fiberSpans;
120
167
  private readonly fiberStartTimes;
121
168
  private _tracer;
169
+ private readonly tracerProvider;
122
170
  private readonly includePatterns;
123
171
  private readonly excludePatterns;
124
172
  private activeFiberCount;
125
173
  private _rootSpan;
126
- constructor(config: AutoInstrumentationConfig);
174
+ constructor(config: AutoInstrumentationConfig, tracerProvider?: OtelApi.TracerProvider);
127
175
  /**
128
176
  * Set the root span for parent context propagation
129
177
  */
130
178
  setRootSpan(span: OtelApi.Span): void;
131
179
  /**
132
- * Get the tracer lazily - this allows time for the NodeSdk layer to register the global provider
180
+ * Get the tracer lazily - uses provided TracerProvider if available, otherwise uses global
133
181
  */
134
182
  private get tracer();
135
183
  /**
@@ -164,7 +212,7 @@ declare class AutoTracingSupervisor extends Supervisor.AbstractSupervisor<void>
164
212
  /**
165
213
  * Create a custom AutoTracingSupervisor with the given config
166
214
  */
167
- declare const createAutoTracingSupervisor: (config: AutoInstrumentationConfig) => AutoTracingSupervisor;
215
+ declare const createAutoTracingSupervisor: (config: AutoInstrumentationConfig, tracerProvider?: OtelApi.TracerProvider) => AutoTracingSupervisor;
168
216
  /**
169
217
  * Layer that provides auto-tracing with custom configuration
170
218
  *
@@ -434,4 +482,4 @@ declare function inferSpanName(fiberId: number, sourceInfo: SourceInfo | undefin
434
482
  */
435
483
  declare function sanitizeSpanName(name: string): string;
436
484
 
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 };
485
+ 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
@@ -119,17 +166,18 @@ declare class AutoTracingSupervisor extends Supervisor.AbstractSupervisor<void>
119
166
  private readonly fiberSpans;
120
167
  private readonly fiberStartTimes;
121
168
  private _tracer;
169
+ private readonly tracerProvider;
122
170
  private readonly includePatterns;
123
171
  private readonly excludePatterns;
124
172
  private activeFiberCount;
125
173
  private _rootSpan;
126
- constructor(config: AutoInstrumentationConfig);
174
+ constructor(config: AutoInstrumentationConfig, tracerProvider?: OtelApi.TracerProvider);
127
175
  /**
128
176
  * Set the root span for parent context propagation
129
177
  */
130
178
  setRootSpan(span: OtelApi.Span): void;
131
179
  /**
132
- * Get the tracer lazily - this allows time for the NodeSdk layer to register the global provider
180
+ * Get the tracer lazily - uses provided TracerProvider if available, otherwise uses global
133
181
  */
134
182
  private get tracer();
135
183
  /**
@@ -164,7 +212,7 @@ declare class AutoTracingSupervisor extends Supervisor.AbstractSupervisor<void>
164
212
  /**
165
213
  * Create a custom AutoTracingSupervisor with the given config
166
214
  */
167
- declare const createAutoTracingSupervisor: (config: AutoInstrumentationConfig) => AutoTracingSupervisor;
215
+ declare const createAutoTracingSupervisor: (config: AutoInstrumentationConfig, tracerProvider?: OtelApi.TracerProvider) => AutoTracingSupervisor;
168
216
  /**
169
217
  * Layer that provides auto-tracing with custom configuration
170
218
  *
@@ -434,4 +482,4 @@ declare function inferSpanName(fiberId: number, sourceInfo: SourceInfo | undefin
434
482
  */
435
483
  declare function sanitizeSpanName(name: string): string;
436
484
 
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 };
485
+ 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
- import { Data, Context, Effect, Layer, FiberRef, Option, Supervisor, FiberRefs, Exit } from 'effect';
2
- import { NodeSdk } from '@effect/opentelemetry';
3
- import { SimpleSpanProcessor, ConsoleSpanExporter, BatchSpanProcessor, BasicTracerProvider } from '@opentelemetry/sdk-trace-base';
1
+ import { Data, Context, Effect, Layer, FiberRef, Option, Supervisor, FiberRefs, Tracer, Exit } from 'effect';
2
+ import { NodeSdk, Tracer as Tracer$1 } from '@effect/opentelemetry';
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);
@@ -767,7 +706,7 @@ function sanitizeSpanName(name) {
767
706
  var AutoTracingEnabled = FiberRef.unsafeMake(true);
768
707
  var AutoTracingSpanName = FiberRef.unsafeMake(Option.none());
769
708
  var AutoTracingSupervisor = class extends Supervisor.AbstractSupervisor {
770
- constructor(config) {
709
+ constructor(config, tracerProvider) {
771
710
  super();
772
711
  this.config = config;
773
712
  // WeakMap to associate fibers with their OTel spans
@@ -776,6 +715,8 @@ var AutoTracingSupervisor = class extends Supervisor.AbstractSupervisor {
776
715
  __publicField(this, "fiberStartTimes", /* @__PURE__ */ new WeakMap());
777
716
  // OpenTelemetry tracer - lazily initialized
778
717
  __publicField(this, "_tracer", null);
718
+ // Optional TracerProvider (if provided, use this instead of global)
719
+ __publicField(this, "tracerProvider", null);
779
720
  // Compiled filter patterns
780
721
  __publicField(this, "includePatterns");
781
722
  __publicField(this, "excludePatterns");
@@ -783,6 +724,10 @@ var AutoTracingSupervisor = class extends Supervisor.AbstractSupervisor {
783
724
  __publicField(this, "activeFiberCount", 0);
784
725
  // Root span for parent context (set by withAutoTracing)
785
726
  __publicField(this, "_rootSpan", null);
727
+ if (tracerProvider) {
728
+ this.tracerProvider = tracerProvider;
729
+ logger.log("@atrim/auto-trace: Using provided TracerProvider");
730
+ }
786
731
  this.includePatterns = (config.filter?.include || []).map((p) => new RegExp(p));
787
732
  this.excludePatterns = (config.filter?.exclude || []).map((p) => new RegExp(p));
788
733
  logger.log("@atrim/auto-trace: Supervisor initialized");
@@ -797,11 +742,17 @@ var AutoTracingSupervisor = class extends Supervisor.AbstractSupervisor {
797
742
  this._rootSpan = span;
798
743
  }
799
744
  /**
800
- * Get the tracer lazily - this allows time for the NodeSdk layer to register the global provider
745
+ * Get the tracer lazily - uses provided TracerProvider if available, otherwise uses global
801
746
  */
802
747
  get tracer() {
803
748
  if (!this._tracer) {
804
- this._tracer = OtelApi.trace.getTracer("@atrim/auto-trace", "1.0.0");
749
+ if (this.tracerProvider) {
750
+ logger.log("@atrim/auto-trace: Getting tracer from provided TracerProvider");
751
+ this._tracer = this.tracerProvider.getTracer("@atrim/auto-trace", "1.0.0");
752
+ } else {
753
+ logger.log("@atrim/auto-trace: Getting tracer from global API");
754
+ this._tracer = OtelApi.trace.getTracer("@atrim/auto-trace", "1.0.0");
755
+ }
805
756
  }
806
757
  return this._tracer;
807
758
  }
@@ -815,9 +766,11 @@ var AutoTracingSupervisor = class extends Supervisor.AbstractSupervisor {
815
766
  * Called when a fiber starts executing
816
767
  */
817
768
  onStart(_context, _effect, parent, fiber) {
769
+ logger.log(`@atrim/auto-trace: onStart called for fiber ${fiber.id().id}`);
818
770
  const fiberRefsValue = fiber.getFiberRefs();
819
771
  const enabled = FiberRefs.getOrDefault(fiberRefsValue, AutoTracingEnabled);
820
772
  if (!enabled) {
773
+ logger.log(`@atrim/auto-trace: Auto-tracing disabled for fiber ${fiber.id().id}`);
821
774
  return;
822
775
  }
823
776
  const samplingRate = this.config.performance?.sampling_rate ?? 1;
@@ -841,7 +794,19 @@ var AutoTracingSupervisor = class extends Supervisor.AbstractSupervisor {
841
794
  }
842
795
  let parentContext = OtelApi.ROOT_CONTEXT;
843
796
  let parentFiberId;
844
- if (Option.isSome(parent)) {
797
+ const maybeEffectParentSpan = Context.getOption(_context, Tracer.ParentSpan);
798
+ if (Option.isSome(maybeEffectParentSpan)) {
799
+ const effectSpan = maybeEffectParentSpan.value;
800
+ logger.log(`@atrim/auto-trace: Found ParentSpan - traceId=${effectSpan.traceId.slice(0, 8)}..., spanId=${effectSpan.spanId.slice(0, 8)}...`);
801
+ const otelSpanContext = {
802
+ traceId: effectSpan.traceId,
803
+ spanId: effectSpan.spanId,
804
+ traceFlags: effectSpan.sampled ? OtelApi.TraceFlags.SAMPLED : OtelApi.TraceFlags.NONE,
805
+ isRemote: false
806
+ };
807
+ const wrappedSpan = OtelApi.trace.wrapSpanContext(otelSpanContext);
808
+ parentContext = OtelApi.trace.setSpan(OtelApi.ROOT_CONTEXT, wrappedSpan);
809
+ } else if (Option.isSome(parent)) {
845
810
  parentFiberId = parent.value.id().id;
846
811
  const parentSpan = this.fiberSpans.get(parent.value);
847
812
  if (parentSpan) {
@@ -852,6 +817,9 @@ var AutoTracingSupervisor = class extends Supervisor.AbstractSupervisor {
852
817
  } else if (this._rootSpan) {
853
818
  parentContext = OtelApi.trace.setSpan(OtelApi.ROOT_CONTEXT, this._rootSpan);
854
819
  }
820
+ if (Option.isSome(parent)) {
821
+ parentFiberId = parent.value.id().id;
822
+ }
855
823
  const span = this.tracer.startSpan(
856
824
  spanName,
857
825
  {
@@ -860,6 +828,7 @@ var AutoTracingSupervisor = class extends Supervisor.AbstractSupervisor {
860
828
  },
861
829
  parentContext
862
830
  );
831
+ logger.log(`@atrim/auto-trace: Created span "${spanName}" for fiber ${fiber.id().id}`);
863
832
  this.fiberSpans.set(fiber, span);
864
833
  this.fiberStartTimes.set(fiber, process.hrtime.bigint());
865
834
  this.activeFiberCount++;
@@ -987,8 +956,8 @@ var AutoTracingSupervisor = class extends Supervisor.AbstractSupervisor {
987
956
  }
988
957
  }
989
958
  };
990
- var createAutoTracingSupervisor = (config) => {
991
- return new AutoTracingSupervisor(config);
959
+ var createAutoTracingSupervisor = (config, tracerProvider) => {
960
+ return new AutoTracingSupervisor(config, tracerProvider);
992
961
  };
993
962
  var createAutoTracingLayer = (options) => {
994
963
  return Layer.unwrapEffect(
@@ -1131,6 +1100,157 @@ var createFullAutoTracingLayer = () => {
1131
1100
  };
1132
1101
  var FullAutoTracingLive = createFullAutoTracingLayer();
1133
1102
 
1134
- export { AutoTracingConfig, AutoTracingConfigLayer, AutoTracingConfigLive, AutoTracingEnabled, AutoTracingLive, AutoTracingSpanName, AutoTracingSupervisor, EffectTracingLive, FullAutoTracingLive, createAutoTracingLayer, createAutoTracingSupervisor, createEffectTracingLayer, createFullAutoTracingLayer, defaultAutoTracingConfig, inferSpanName, loadAutoTracingConfig, loadAutoTracingConfigSync, sanitizeSpanName, setSpanName, withAutoTracing, withoutAutoTracing };
1103
+ // src/integrations/effect/auto/effect-tracing.ts
1104
+ var createEffectTracingLayer = () => {
1105
+ return Layer.unwrapEffect(
1106
+ Effect.gen(function* () {
1107
+ const config = yield* loadFullConfig();
1108
+ const serviceName = process.env.OTEL_SERVICE_NAME || "effect-service";
1109
+ const serviceVersion = process.env.npm_package_version || "1.0.0";
1110
+ const exporterConfig = config.effect?.exporter_config ?? {
1111
+ type: "otlp",
1112
+ processor: "batch"
1113
+ };
1114
+ logger.log("@atrim/auto-trace: Effect-native tracing enabled");
1115
+ logger.log(` Service: ${serviceName}`);
1116
+ logger.log(` Exporter: ${exporterConfig.type}`);
1117
+ if (exporterConfig.type === "none") {
1118
+ logger.log('@atrim/auto-trace: Exporter type is "none", using empty layer');
1119
+ return Layer.empty;
1120
+ }
1121
+ const createSpanProcessor = () => {
1122
+ if (exporterConfig.type === "console") {
1123
+ logger.log("@atrim/auto-trace: Using ConsoleSpanExporter with SimpleSpanProcessor");
1124
+ return new SimpleSpanProcessor(new ConsoleSpanExporter());
1125
+ }
1126
+ const endpoint = exporterConfig.endpoint || process.env.OTEL_EXPORTER_OTLP_ENDPOINT || "http://localhost:4318";
1127
+ logger.log(`@atrim/auto-trace: Using OTLPTraceExporter (${endpoint})`);
1128
+ const otlpConfig = {
1129
+ url: `${endpoint}/v1/traces`
1130
+ };
1131
+ if (exporterConfig.headers) {
1132
+ otlpConfig.headers = exporterConfig.headers;
1133
+ logger.log(`@atrim/auto-trace: Using custom headers: ${Object.keys(exporterConfig.headers).join(", ")}`);
1134
+ }
1135
+ const exporter = new OTLPTraceExporter(otlpConfig);
1136
+ if (exporterConfig.processor === "simple") {
1137
+ logger.log("@atrim/auto-trace: Using SimpleSpanProcessor");
1138
+ return new SimpleSpanProcessor(exporter);
1139
+ }
1140
+ const batchConfig = exporterConfig.batch ?? {
1141
+ scheduled_delay_millis: 1e3,
1142
+ max_export_batch_size: 100
1143
+ };
1144
+ logger.log("@atrim/auto-trace: Using BatchSpanProcessor");
1145
+ return new BatchSpanProcessor(exporter, {
1146
+ scheduledDelayMillis: batchConfig.scheduled_delay_millis,
1147
+ maxExportBatchSize: batchConfig.max_export_batch_size
1148
+ });
1149
+ };
1150
+ const sdkLayer = NodeSdk.layer(() => ({
1151
+ resource: {
1152
+ serviceName,
1153
+ serviceVersion
1154
+ },
1155
+ spanProcessor: createSpanProcessor()
1156
+ }));
1157
+ logger.log("@atrim/auto-trace: NodeSdk layer created - HTTP requests will be auto-traced");
1158
+ return Layer.discard(sdkLayer);
1159
+ })
1160
+ );
1161
+ };
1162
+ var EffectTracingLive = createEffectTracingLayer();
1163
+ var createCombinedTracingLayer = () => {
1164
+ return Layer.unwrapEffect(
1165
+ Effect.gen(function* () {
1166
+ const config = yield* loadFullConfig();
1167
+ const serviceName = process.env.OTEL_SERVICE_NAME || "effect-service";
1168
+ const serviceVersion = process.env.npm_package_version || "1.0.0";
1169
+ const exporterConfig = config.effect?.exporter_config ?? {
1170
+ type: "otlp",
1171
+ processor: "batch"
1172
+ };
1173
+ const autoConfig = config.effect?.auto_instrumentation ?? {
1174
+ enabled: true,
1175
+ granularity: "fiber",
1176
+ span_naming: {
1177
+ default: "effect.{function}",
1178
+ infer_from_source: true,
1179
+ rules: []
1180
+ },
1181
+ filter: { include: [], exclude: [] },
1182
+ performance: { sampling_rate: 1, min_duration: "0ms", max_concurrent: 0 },
1183
+ metadata: { fiber_info: true, source_location: true, parent_fiber: true }
1184
+ };
1185
+ logger.log("@atrim/auto-trace: Combined tracing enabled (HTTP + Fiber)");
1186
+ logger.log(` Service: ${serviceName}`);
1187
+ logger.log(` Exporter: ${exporterConfig.type}`);
1188
+ if (exporterConfig.type === "none") {
1189
+ logger.log('@atrim/auto-trace: Exporter type is "none", using empty layer');
1190
+ return Layer.empty;
1191
+ }
1192
+ const createSpanProcessor = () => {
1193
+ if (exporterConfig.type === "console") {
1194
+ logger.log("@atrim/auto-trace: Using ConsoleSpanExporter with SimpleSpanProcessor");
1195
+ return new SimpleSpanProcessor(new ConsoleSpanExporter());
1196
+ }
1197
+ const endpoint = exporterConfig.endpoint || process.env.OTEL_EXPORTER_OTLP_ENDPOINT || "http://localhost:4318";
1198
+ logger.log(`@atrim/auto-trace: Using OTLPTraceExporter (${endpoint})`);
1199
+ const otlpConfig = {
1200
+ url: `${endpoint}/v1/traces`
1201
+ };
1202
+ if (exporterConfig.headers) {
1203
+ otlpConfig.headers = exporterConfig.headers;
1204
+ logger.log(`@atrim/auto-trace: Using custom headers: ${Object.keys(exporterConfig.headers).join(", ")}`);
1205
+ }
1206
+ const exporter = new OTLPTraceExporter(otlpConfig);
1207
+ if (exporterConfig.processor === "simple") {
1208
+ logger.log("@atrim/auto-trace: Using SimpleSpanProcessor");
1209
+ return new SimpleSpanProcessor(exporter);
1210
+ }
1211
+ const batchConfig = exporterConfig.batch ?? {
1212
+ scheduled_delay_millis: 1e3,
1213
+ max_export_batch_size: 100
1214
+ };
1215
+ logger.log("@atrim/auto-trace: Using BatchSpanProcessor");
1216
+ return new BatchSpanProcessor(exporter, {
1217
+ scheduledDelayMillis: batchConfig.scheduled_delay_millis,
1218
+ maxExportBatchSize: batchConfig.max_export_batch_size
1219
+ });
1220
+ };
1221
+ const sdkLayer = NodeSdk.layer(() => ({
1222
+ resource: {
1223
+ serviceName,
1224
+ serviceVersion
1225
+ },
1226
+ spanProcessor: createSpanProcessor()
1227
+ }));
1228
+ const supervisorLayer = Layer.unwrapScoped(
1229
+ Effect.gen(function* () {
1230
+ const tracerProvider = yield* Effect.serviceOption(Tracer$1.OtelTracerProvider);
1231
+ if (Option.isSome(tracerProvider)) {
1232
+ logger.log("@atrim/auto-trace: Got TracerProvider from NodeSdk layer");
1233
+ const supervisor = createAutoTracingSupervisor(autoConfig, tracerProvider.value);
1234
+ logger.log("@atrim/auto-trace: Combined layer created");
1235
+ logger.log(" - HTTP requests: auto-traced via Effect platform");
1236
+ logger.log(" - Forked fibers: auto-traced via Supervisor");
1237
+ return Supervisor.addSupervisor(supervisor);
1238
+ } else {
1239
+ logger.log("@atrim/auto-trace: WARNING: No TracerProvider found, creating supervisor without it");
1240
+ const supervisor = createAutoTracingSupervisor(autoConfig);
1241
+ logger.log("@atrim/auto-trace: Combined layer created (fallback)");
1242
+ logger.log(" - HTTP requests: auto-traced via Effect platform");
1243
+ logger.log(" - Forked fibers: auto-traced via Supervisor");
1244
+ return Supervisor.addSupervisor(supervisor);
1245
+ }
1246
+ })
1247
+ );
1248
+ return supervisorLayer.pipe(Layer.provide(Layer.discard(sdkLayer)));
1249
+ })
1250
+ );
1251
+ };
1252
+ var CombinedTracingLive = createCombinedTracingLayer();
1253
+
1254
+ 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
1255
  //# sourceMappingURL=index.js.map
1136
1256
  //# sourceMappingURL=index.js.map