@atrim/instrument-node 0.7.1-dev.14fdea7.20260108232436 → 0.7.1-dev.14fdea7.20260109021705
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 +59 -24
- 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 +61 -26
- package/target/dist/integrations/effect/auto/index.js.map +1 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@atrim/instrument-node",
|
|
3
|
-
"version": "0.7.1-dev.14fdea7.
|
|
3
|
+
"version": "0.7.1-dev.14fdea7.20260109021705",
|
|
4
4
|
"description": "OpenTelemetry instrumentation for Node.js with centralized YAML configuration",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
@@ -731,7 +731,7 @@ function sanitizeSpanName(name) {
|
|
|
731
731
|
var AutoTracingEnabled = effect.FiberRef.unsafeMake(true);
|
|
732
732
|
var AutoTracingSpanName = effect.FiberRef.unsafeMake(effect.Option.none());
|
|
733
733
|
var AutoTracingSupervisor = class extends effect.Supervisor.AbstractSupervisor {
|
|
734
|
-
constructor(config) {
|
|
734
|
+
constructor(config, tracerProvider) {
|
|
735
735
|
super();
|
|
736
736
|
this.config = config;
|
|
737
737
|
// WeakMap to associate fibers with their OTel spans
|
|
@@ -740,6 +740,8 @@ var AutoTracingSupervisor = class extends effect.Supervisor.AbstractSupervisor {
|
|
|
740
740
|
__publicField(this, "fiberStartTimes", /* @__PURE__ */ new WeakMap());
|
|
741
741
|
// OpenTelemetry tracer - lazily initialized
|
|
742
742
|
__publicField(this, "_tracer", null);
|
|
743
|
+
// Optional TracerProvider (if provided, use this instead of global)
|
|
744
|
+
__publicField(this, "tracerProvider", null);
|
|
743
745
|
// Compiled filter patterns
|
|
744
746
|
__publicField(this, "includePatterns");
|
|
745
747
|
__publicField(this, "excludePatterns");
|
|
@@ -747,6 +749,10 @@ var AutoTracingSupervisor = class extends effect.Supervisor.AbstractSupervisor {
|
|
|
747
749
|
__publicField(this, "activeFiberCount", 0);
|
|
748
750
|
// Root span for parent context (set by withAutoTracing)
|
|
749
751
|
__publicField(this, "_rootSpan", null);
|
|
752
|
+
if (tracerProvider) {
|
|
753
|
+
this.tracerProvider = tracerProvider;
|
|
754
|
+
logger.log("@atrim/auto-trace: Using provided TracerProvider");
|
|
755
|
+
}
|
|
750
756
|
this.includePatterns = (config.filter?.include || []).map((p) => new RegExp(p));
|
|
751
757
|
this.excludePatterns = (config.filter?.exclude || []).map((p) => new RegExp(p));
|
|
752
758
|
logger.log("@atrim/auto-trace: Supervisor initialized");
|
|
@@ -761,11 +767,17 @@ var AutoTracingSupervisor = class extends effect.Supervisor.AbstractSupervisor {
|
|
|
761
767
|
this._rootSpan = span;
|
|
762
768
|
}
|
|
763
769
|
/**
|
|
764
|
-
* Get the tracer lazily -
|
|
770
|
+
* Get the tracer lazily - uses provided TracerProvider if available, otherwise uses global
|
|
765
771
|
*/
|
|
766
772
|
get tracer() {
|
|
767
773
|
if (!this._tracer) {
|
|
768
|
-
|
|
774
|
+
if (this.tracerProvider) {
|
|
775
|
+
logger.log("@atrim/auto-trace: Getting tracer from provided TracerProvider");
|
|
776
|
+
this._tracer = this.tracerProvider.getTracer("@atrim/auto-trace", "1.0.0");
|
|
777
|
+
} else {
|
|
778
|
+
logger.log("@atrim/auto-trace: Getting tracer from global API");
|
|
779
|
+
this._tracer = OtelApi__namespace.trace.getTracer("@atrim/auto-trace", "1.0.0");
|
|
780
|
+
}
|
|
769
781
|
}
|
|
770
782
|
return this._tracer;
|
|
771
783
|
}
|
|
@@ -779,9 +791,11 @@ var AutoTracingSupervisor = class extends effect.Supervisor.AbstractSupervisor {
|
|
|
779
791
|
* Called when a fiber starts executing
|
|
780
792
|
*/
|
|
781
793
|
onStart(_context, _effect, parent, fiber) {
|
|
794
|
+
logger.log(`@atrim/auto-trace: onStart called for fiber ${fiber.id().id}`);
|
|
782
795
|
const fiberRefsValue = fiber.getFiberRefs();
|
|
783
796
|
const enabled = effect.FiberRefs.getOrDefault(fiberRefsValue, AutoTracingEnabled);
|
|
784
797
|
if (!enabled) {
|
|
798
|
+
logger.log(`@atrim/auto-trace: Auto-tracing disabled for fiber ${fiber.id().id}`);
|
|
785
799
|
return;
|
|
786
800
|
}
|
|
787
801
|
const samplingRate = this.config.performance?.sampling_rate ?? 1;
|
|
@@ -805,26 +819,31 @@ var AutoTracingSupervisor = class extends effect.Supervisor.AbstractSupervisor {
|
|
|
805
819
|
}
|
|
806
820
|
let parentContext = OtelApi__namespace.ROOT_CONTEXT;
|
|
807
821
|
let parentFiberId;
|
|
808
|
-
|
|
822
|
+
const maybeEffectParentSpan = effect.Context.getOption(_context, effect.Tracer.ParentSpan);
|
|
823
|
+
if (effect.Option.isSome(maybeEffectParentSpan)) {
|
|
824
|
+
const effectSpan = maybeEffectParentSpan.value;
|
|
825
|
+
logger.log(`@atrim/auto-trace: Found ParentSpan - traceId=${effectSpan.traceId.slice(0, 8)}..., spanId=${effectSpan.spanId.slice(0, 8)}...`);
|
|
826
|
+
const otelSpanContext = {
|
|
827
|
+
traceId: effectSpan.traceId,
|
|
828
|
+
spanId: effectSpan.spanId,
|
|
829
|
+
traceFlags: effectSpan.sampled ? OtelApi__namespace.TraceFlags.SAMPLED : OtelApi__namespace.TraceFlags.NONE,
|
|
830
|
+
isRemote: false
|
|
831
|
+
};
|
|
832
|
+
const wrappedSpan = OtelApi__namespace.trace.wrapSpanContext(otelSpanContext);
|
|
833
|
+
parentContext = OtelApi__namespace.trace.setSpan(OtelApi__namespace.ROOT_CONTEXT, wrappedSpan);
|
|
834
|
+
} else if (effect.Option.isSome(parent)) {
|
|
809
835
|
parentFiberId = parent.value.id().id;
|
|
810
836
|
const parentSpan = this.fiberSpans.get(parent.value);
|
|
811
837
|
if (parentSpan) {
|
|
812
838
|
parentContext = OtelApi__namespace.trace.setSpan(OtelApi__namespace.ROOT_CONTEXT, parentSpan);
|
|
813
|
-
} else {
|
|
814
|
-
const activeSpan = OtelApi__namespace.trace.getSpan(OtelApi__namespace.context.active());
|
|
815
|
-
if (activeSpan) {
|
|
816
|
-
parentContext = OtelApi__namespace.context.active();
|
|
817
|
-
} else if (this._rootSpan) {
|
|
818
|
-
parentContext = OtelApi__namespace.trace.setSpan(OtelApi__namespace.ROOT_CONTEXT, this._rootSpan);
|
|
819
|
-
}
|
|
820
|
-
}
|
|
821
|
-
} else {
|
|
822
|
-
const activeSpan = OtelApi__namespace.trace.getSpan(OtelApi__namespace.context.active());
|
|
823
|
-
if (activeSpan) {
|
|
824
|
-
parentContext = OtelApi__namespace.context.active();
|
|
825
839
|
} else if (this._rootSpan) {
|
|
826
840
|
parentContext = OtelApi__namespace.trace.setSpan(OtelApi__namespace.ROOT_CONTEXT, this._rootSpan);
|
|
827
841
|
}
|
|
842
|
+
} else if (this._rootSpan) {
|
|
843
|
+
parentContext = OtelApi__namespace.trace.setSpan(OtelApi__namespace.ROOT_CONTEXT, this._rootSpan);
|
|
844
|
+
}
|
|
845
|
+
if (effect.Option.isSome(parent)) {
|
|
846
|
+
parentFiberId = parent.value.id().id;
|
|
828
847
|
}
|
|
829
848
|
const span = this.tracer.startSpan(
|
|
830
849
|
spanName,
|
|
@@ -834,6 +853,7 @@ var AutoTracingSupervisor = class extends effect.Supervisor.AbstractSupervisor {
|
|
|
834
853
|
},
|
|
835
854
|
parentContext
|
|
836
855
|
);
|
|
856
|
+
logger.log(`@atrim/auto-trace: Created span "${spanName}" for fiber ${fiber.id().id}`);
|
|
837
857
|
this.fiberSpans.set(fiber, span);
|
|
838
858
|
this.fiberStartTimes.set(fiber, process.hrtime.bigint());
|
|
839
859
|
this.activeFiberCount++;
|
|
@@ -961,8 +981,8 @@ var AutoTracingSupervisor = class extends effect.Supervisor.AbstractSupervisor {
|
|
|
961
981
|
}
|
|
962
982
|
}
|
|
963
983
|
};
|
|
964
|
-
var createAutoTracingSupervisor = (config) => {
|
|
965
|
-
return new AutoTracingSupervisor(config);
|
|
984
|
+
var createAutoTracingSupervisor = (config, tracerProvider) => {
|
|
985
|
+
return new AutoTracingSupervisor(config, tracerProvider);
|
|
966
986
|
};
|
|
967
987
|
var createAutoTracingLayer = (options) => {
|
|
968
988
|
return effect.Layer.unwrapEffect(
|
|
@@ -1230,12 +1250,27 @@ var createCombinedTracingLayer = () => {
|
|
|
1230
1250
|
},
|
|
1231
1251
|
spanProcessor: createSpanProcessor()
|
|
1232
1252
|
}));
|
|
1233
|
-
const
|
|
1234
|
-
|
|
1235
|
-
|
|
1236
|
-
|
|
1237
|
-
|
|
1238
|
-
|
|
1253
|
+
const supervisorLayer = effect.Layer.unwrapScoped(
|
|
1254
|
+
effect.Effect.gen(function* () {
|
|
1255
|
+
const tracerProvider = yield* effect.Effect.serviceOption(opentelemetry.Tracer.OtelTracerProvider);
|
|
1256
|
+
if (effect.Option.isSome(tracerProvider)) {
|
|
1257
|
+
logger.log("@atrim/auto-trace: Got TracerProvider from NodeSdk layer");
|
|
1258
|
+
const supervisor = createAutoTracingSupervisor(autoConfig, tracerProvider.value);
|
|
1259
|
+
logger.log("@atrim/auto-trace: Combined layer created");
|
|
1260
|
+
logger.log(" - HTTP requests: auto-traced via Effect platform");
|
|
1261
|
+
logger.log(" - Forked fibers: auto-traced via Supervisor");
|
|
1262
|
+
return effect.Supervisor.addSupervisor(supervisor);
|
|
1263
|
+
} else {
|
|
1264
|
+
logger.log("@atrim/auto-trace: WARNING: No TracerProvider found, creating supervisor without it");
|
|
1265
|
+
const supervisor = createAutoTracingSupervisor(autoConfig);
|
|
1266
|
+
logger.log("@atrim/auto-trace: Combined layer created (fallback)");
|
|
1267
|
+
logger.log(" - HTTP requests: auto-traced via Effect platform");
|
|
1268
|
+
logger.log(" - Forked fibers: auto-traced via Supervisor");
|
|
1269
|
+
return effect.Supervisor.addSupervisor(supervisor);
|
|
1270
|
+
}
|
|
1271
|
+
})
|
|
1272
|
+
);
|
|
1273
|
+
return supervisorLayer.pipe(effect.Layer.provide(effect.Layer.discard(sdkLayer)));
|
|
1239
1274
|
})
|
|
1240
1275
|
);
|
|
1241
1276
|
};
|