@atrim/instrument-node 0.5.0-14fdea7-20260109020503 → 0.5.0-14fdea7-20260109021638
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/package.json +1 -1
- package/target/dist/integrations/effect/auto/index.cjs +38 -11
- package/target/dist/integrations/effect/auto/index.cjs.map +1 -1
- package/target/dist/integrations/effect/auto/index.d.cts +4 -3
- package/target/dist/integrations/effect/auto/index.d.ts +4 -3
- package/target/dist/integrations/effect/auto/index.js +39 -12
- package/target/dist/integrations/effect/auto/index.js.map +1 -1
|
@@ -166,17 +166,18 @@ declare class AutoTracingSupervisor extends Supervisor.AbstractSupervisor<void>
|
|
|
166
166
|
private readonly fiberSpans;
|
|
167
167
|
private readonly fiberStartTimes;
|
|
168
168
|
private _tracer;
|
|
169
|
+
private readonly tracerProvider;
|
|
169
170
|
private readonly includePatterns;
|
|
170
171
|
private readonly excludePatterns;
|
|
171
172
|
private activeFiberCount;
|
|
172
173
|
private _rootSpan;
|
|
173
|
-
constructor(config: AutoInstrumentationConfig);
|
|
174
|
+
constructor(config: AutoInstrumentationConfig, tracerProvider?: OtelApi.TracerProvider);
|
|
174
175
|
/**
|
|
175
176
|
* Set the root span for parent context propagation
|
|
176
177
|
*/
|
|
177
178
|
setRootSpan(span: OtelApi.Span): void;
|
|
178
179
|
/**
|
|
179
|
-
* Get the tracer lazily -
|
|
180
|
+
* Get the tracer lazily - uses provided TracerProvider if available, otherwise uses global
|
|
180
181
|
*/
|
|
181
182
|
private get tracer();
|
|
182
183
|
/**
|
|
@@ -211,7 +212,7 @@ declare class AutoTracingSupervisor extends Supervisor.AbstractSupervisor<void>
|
|
|
211
212
|
/**
|
|
212
213
|
* Create a custom AutoTracingSupervisor with the given config
|
|
213
214
|
*/
|
|
214
|
-
declare const createAutoTracingSupervisor: (config: AutoInstrumentationConfig) => AutoTracingSupervisor;
|
|
215
|
+
declare const createAutoTracingSupervisor: (config: AutoInstrumentationConfig, tracerProvider?: OtelApi.TracerProvider) => AutoTracingSupervisor;
|
|
215
216
|
/**
|
|
216
217
|
* Layer that provides auto-tracing with custom configuration
|
|
217
218
|
*
|
|
@@ -166,17 +166,18 @@ declare class AutoTracingSupervisor extends Supervisor.AbstractSupervisor<void>
|
|
|
166
166
|
private readonly fiberSpans;
|
|
167
167
|
private readonly fiberStartTimes;
|
|
168
168
|
private _tracer;
|
|
169
|
+
private readonly tracerProvider;
|
|
169
170
|
private readonly includePatterns;
|
|
170
171
|
private readonly excludePatterns;
|
|
171
172
|
private activeFiberCount;
|
|
172
173
|
private _rootSpan;
|
|
173
|
-
constructor(config: AutoInstrumentationConfig);
|
|
174
|
+
constructor(config: AutoInstrumentationConfig, tracerProvider?: OtelApi.TracerProvider);
|
|
174
175
|
/**
|
|
175
176
|
* Set the root span for parent context propagation
|
|
176
177
|
*/
|
|
177
178
|
setRootSpan(span: OtelApi.Span): void;
|
|
178
179
|
/**
|
|
179
|
-
* Get the tracer lazily -
|
|
180
|
+
* Get the tracer lazily - uses provided TracerProvider if available, otherwise uses global
|
|
180
181
|
*/
|
|
181
182
|
private get tracer();
|
|
182
183
|
/**
|
|
@@ -211,7 +212,7 @@ declare class AutoTracingSupervisor extends Supervisor.AbstractSupervisor<void>
|
|
|
211
212
|
/**
|
|
212
213
|
* Create a custom AutoTracingSupervisor with the given config
|
|
213
214
|
*/
|
|
214
|
-
declare const createAutoTracingSupervisor: (config: AutoInstrumentationConfig) => AutoTracingSupervisor;
|
|
215
|
+
declare const createAutoTracingSupervisor: (config: AutoInstrumentationConfig, tracerProvider?: OtelApi.TracerProvider) => AutoTracingSupervisor;
|
|
215
216
|
/**
|
|
216
217
|
* Layer that provides auto-tracing with custom configuration
|
|
217
218
|
*
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Data, Context, Effect, Layer, FiberRef, Option, Supervisor, FiberRefs, Tracer, Exit } from 'effect';
|
|
2
|
-
import { NodeSdk } from '@effect/opentelemetry';
|
|
2
|
+
import { NodeSdk, Tracer as Tracer$1 } from '@effect/opentelemetry';
|
|
3
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';
|
|
@@ -706,7 +706,7 @@ function sanitizeSpanName(name) {
|
|
|
706
706
|
var AutoTracingEnabled = FiberRef.unsafeMake(true);
|
|
707
707
|
var AutoTracingSpanName = FiberRef.unsafeMake(Option.none());
|
|
708
708
|
var AutoTracingSupervisor = class extends Supervisor.AbstractSupervisor {
|
|
709
|
-
constructor(config) {
|
|
709
|
+
constructor(config, tracerProvider) {
|
|
710
710
|
super();
|
|
711
711
|
this.config = config;
|
|
712
712
|
// WeakMap to associate fibers with their OTel spans
|
|
@@ -715,6 +715,8 @@ var AutoTracingSupervisor = class extends Supervisor.AbstractSupervisor {
|
|
|
715
715
|
__publicField(this, "fiberStartTimes", /* @__PURE__ */ new WeakMap());
|
|
716
716
|
// OpenTelemetry tracer - lazily initialized
|
|
717
717
|
__publicField(this, "_tracer", null);
|
|
718
|
+
// Optional TracerProvider (if provided, use this instead of global)
|
|
719
|
+
__publicField(this, "tracerProvider", null);
|
|
718
720
|
// Compiled filter patterns
|
|
719
721
|
__publicField(this, "includePatterns");
|
|
720
722
|
__publicField(this, "excludePatterns");
|
|
@@ -722,6 +724,10 @@ var AutoTracingSupervisor = class extends Supervisor.AbstractSupervisor {
|
|
|
722
724
|
__publicField(this, "activeFiberCount", 0);
|
|
723
725
|
// Root span for parent context (set by withAutoTracing)
|
|
724
726
|
__publicField(this, "_rootSpan", null);
|
|
727
|
+
if (tracerProvider) {
|
|
728
|
+
this.tracerProvider = tracerProvider;
|
|
729
|
+
logger.log("@atrim/auto-trace: Using provided TracerProvider");
|
|
730
|
+
}
|
|
725
731
|
this.includePatterns = (config.filter?.include || []).map((p) => new RegExp(p));
|
|
726
732
|
this.excludePatterns = (config.filter?.exclude || []).map((p) => new RegExp(p));
|
|
727
733
|
logger.log("@atrim/auto-trace: Supervisor initialized");
|
|
@@ -736,11 +742,17 @@ var AutoTracingSupervisor = class extends Supervisor.AbstractSupervisor {
|
|
|
736
742
|
this._rootSpan = span;
|
|
737
743
|
}
|
|
738
744
|
/**
|
|
739
|
-
* Get the tracer lazily -
|
|
745
|
+
* Get the tracer lazily - uses provided TracerProvider if available, otherwise uses global
|
|
740
746
|
*/
|
|
741
747
|
get tracer() {
|
|
742
748
|
if (!this._tracer) {
|
|
743
|
-
|
|
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
|
+
}
|
|
744
756
|
}
|
|
745
757
|
return this._tracer;
|
|
746
758
|
}
|
|
@@ -944,8 +956,8 @@ var AutoTracingSupervisor = class extends Supervisor.AbstractSupervisor {
|
|
|
944
956
|
}
|
|
945
957
|
}
|
|
946
958
|
};
|
|
947
|
-
var createAutoTracingSupervisor = (config) => {
|
|
948
|
-
return new AutoTracingSupervisor(config);
|
|
959
|
+
var createAutoTracingSupervisor = (config, tracerProvider) => {
|
|
960
|
+
return new AutoTracingSupervisor(config, tracerProvider);
|
|
949
961
|
};
|
|
950
962
|
var createAutoTracingLayer = (options) => {
|
|
951
963
|
return Layer.unwrapEffect(
|
|
@@ -1213,12 +1225,27 @@ var createCombinedTracingLayer = () => {
|
|
|
1213
1225
|
},
|
|
1214
1226
|
spanProcessor: createSpanProcessor()
|
|
1215
1227
|
}));
|
|
1216
|
-
const
|
|
1217
|
-
|
|
1218
|
-
|
|
1219
|
-
|
|
1220
|
-
|
|
1221
|
-
|
|
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)));
|
|
1222
1249
|
})
|
|
1223
1250
|
);
|
|
1224
1251
|
};
|