@atrim/instrument-node 0.5.1 → 0.5.2-dev.95aa52a.20251221232442

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.
@@ -1,6 +1,8 @@
1
1
  'use strict';
2
2
 
3
3
  var effect = require('effect');
4
+ var Tracer = require('@effect/opentelemetry/Tracer');
5
+ var Resource = require('@effect/opentelemetry/Resource');
4
6
  var Otlp = require('@effect/opentelemetry/Otlp');
5
7
  var platform = require('@effect/platform');
6
8
  var api = require('@opentelemetry/api');
@@ -29,6 +31,8 @@ function _interopNamespace(e) {
29
31
  return Object.freeze(n);
30
32
  }
31
33
 
34
+ var Tracer__namespace = /*#__PURE__*/_interopNamespace(Tracer);
35
+ var Resource__namespace = /*#__PURE__*/_interopNamespace(Resource);
32
36
  var Otlp__namespace = /*#__PURE__*/_interopNamespace(Otlp);
33
37
  var HttpClient__namespace = /*#__PURE__*/_interopNamespace(HttpClient);
34
38
  var HttpClientRequest__namespace = /*#__PURE__*/_interopNamespace(HttpClientRequest);
@@ -100,6 +104,13 @@ var InstrumentationConfigSchema = zod.z.object({
100
104
  ignore_patterns: zod.z.array(PatternConfigSchema)
101
105
  }),
102
106
  effect: zod.z.object({
107
+ // Enable/disable Effect tracing entirely
108
+ // When false, EffectInstrumentationLive returns Layer.empty
109
+ enabled: zod.z.boolean().default(true),
110
+ // Exporter mode:
111
+ // - "unified": Use global TracerProvider from Node SDK (recommended, enables filtering)
112
+ // - "standalone": Use Effect's own OTLP exporter (bypasses Node SDK filtering)
113
+ exporter: zod.z.enum(["unified", "standalone"]).default("unified"),
103
114
  auto_extract_metadata: zod.z.boolean(),
104
115
  auto_isolation: AutoIsolationConfigSchema.optional()
105
116
  }).optional(),
@@ -478,6 +489,8 @@ function getDefaultConfig() {
478
489
  ]
479
490
  },
480
491
  effect: {
492
+ enabled: true,
493
+ exporter: "unified",
481
494
  auto_extract_metadata: true
482
495
  }
483
496
  };
@@ -507,7 +520,8 @@ async function loadConfigWithOptions(options = {}) {
507
520
  }
508
521
 
509
522
  // src/integrations/effect/effect-tracer.ts
510
- var SDK_NAME = "@effect/opentelemetry-otlp";
523
+ var SDK_NAME = "@effect/opentelemetry";
524
+ var ATTR_TELEMETRY_EXPORTER_MODE = "telemetry.exporter.mode";
511
525
  function createEffectInstrumentation(options = {}) {
512
526
  return effect.Layer.unwrapEffect(
513
527
  effect.Effect.gen(function* () {
@@ -518,90 +532,89 @@ function createEffectInstrumentation(options = {}) {
518
532
  message: error instanceof Error ? error.message : String(error)
519
533
  })
520
534
  });
535
+ const effectEnabled = process.env.OTEL_EFFECT_ENABLED !== "false" && (config.effect?.enabled ?? true);
536
+ if (!effectEnabled) {
537
+ logger.log("@atrim/instrumentation/effect: Effect tracing disabled via config");
538
+ return effect.Layer.empty;
539
+ }
521
540
  yield* effect.Effect.sync(() => {
522
541
  const loggingLevel = config.instrumentation.logging || "on";
523
542
  logger.setLevel(loggingLevel);
524
543
  });
525
544
  yield* effect.Effect.sync(() => initializePatternMatcher(config));
526
- const otlpEndpoint = options.otlpEndpoint || process.env.OTEL_EXPORTER_OTLP_ENDPOINT || "http://localhost:4318";
527
545
  const serviceName = options.serviceName || process.env.OTEL_SERVICE_NAME || "effect-service";
528
546
  const serviceVersion = options.serviceVersion || process.env.npm_package_version || "1.0.0";
529
- const autoExtractMetadata = options.autoExtractMetadata ?? config.effect?.auto_extract_metadata ?? true;
530
- const continueExistingTraces = options.continueExistingTraces ?? true;
531
- logger.log("\u{1F50D} Effect OpenTelemetry instrumentation");
532
- logger.log(` \u{1F4E1} Endpoint: ${otlpEndpoint}`);
533
- logger.log(` \u{1F3F7}\uFE0F Service: ${serviceName}`);
534
- logger.log(` \u2705 Auto metadata extraction: ${autoExtractMetadata}`);
535
- logger.log(` \u2705 Continue existing traces: ${continueExistingTraces}`);
536
- const otlpLayer = Otlp__namespace.layer({
537
- baseUrl: otlpEndpoint,
538
- resource: {
539
- serviceName,
540
- serviceVersion,
541
- attributes: {
542
- "platform.component": "effect",
543
- "effect.auto_metadata": autoExtractMetadata,
544
- "effect.context_propagation": continueExistingTraces,
545
- [ATTR_TELEMETRY_SDK_LANGUAGE]: TELEMETRY_SDK_LANGUAGE_VALUE_NODEJS,
546
- [ATTR_TELEMETRY_SDK_NAME]: SDK_NAME
547
- }
548
- },
549
- // Bridge Effect context to OpenTelemetry global context
550
- // This is essential for context propagation to work properly
551
- tracerContext: (f, span) => {
552
- if (span._tag !== "Span") {
553
- return f();
547
+ const exporterMode = options.exporterMode ?? config.effect?.exporter ?? "unified";
548
+ const resourceAttributes = {
549
+ "platform.component": "effect",
550
+ [ATTR_TELEMETRY_SDK_LANGUAGE]: TELEMETRY_SDK_LANGUAGE_VALUE_NODEJS,
551
+ [ATTR_TELEMETRY_SDK_NAME]: SDK_NAME,
552
+ [ATTR_TELEMETRY_EXPORTER_MODE]: exporterMode
553
+ };
554
+ if (exporterMode === "standalone") {
555
+ const otlpEndpoint = options.otlpEndpoint || process.env.OTEL_EXPORTER_OTLP_ENDPOINT || "http://localhost:4318";
556
+ logger.log("Effect OpenTelemetry instrumentation (standalone)");
557
+ logger.log(` Service: ${serviceName}`);
558
+ logger.log(` Endpoint: ${otlpEndpoint}`);
559
+ logger.log(" WARNING: Standalone mode bypasses Node SDK filtering");
560
+ return Otlp__namespace.layer({
561
+ baseUrl: otlpEndpoint,
562
+ resource: {
563
+ serviceName,
564
+ serviceVersion,
565
+ attributes: resourceAttributes
566
+ },
567
+ // Bridge Effect context to OpenTelemetry global context
568
+ tracerContext: (f, span) => {
569
+ if (span._tag !== "Span") {
570
+ return f();
571
+ }
572
+ const spanContext = {
573
+ traceId: span.traceId,
574
+ spanId: span.spanId,
575
+ traceFlags: span.sampled ? api.TraceFlags.SAMPLED : api.TraceFlags.NONE
576
+ };
577
+ const otelSpan = api.trace.wrapSpanContext(spanContext);
578
+ return api.context.with(api.trace.setSpan(api.context.active(), otelSpan), f);
554
579
  }
555
- const spanContext = {
556
- traceId: span.traceId,
557
- spanId: span.spanId,
558
- traceFlags: span.sampled ? api.TraceFlags.SAMPLED : api.TraceFlags.NONE
559
- };
560
- const otelSpan = api.trace.wrapSpanContext(spanContext);
561
- return api.context.with(api.trace.setSpan(api.context.active(), otelSpan), f);
562
- }
563
- }).pipe(effect.Layer.provide(platform.FetchHttpClient.layer));
564
- if (autoExtractMetadata) {
565
- return otlpLayer;
580
+ }).pipe(effect.Layer.provide(platform.FetchHttpClient.layer));
581
+ } else {
582
+ logger.log("Effect OpenTelemetry instrumentation (unified)");
583
+ logger.log(` Service: ${serviceName}`);
584
+ logger.log(" Using global TracerProvider for span export");
585
+ return Tracer__namespace.layerGlobal.pipe(
586
+ effect.Layer.provide(
587
+ Resource__namespace.layer({
588
+ serviceName,
589
+ serviceVersion,
590
+ attributes: resourceAttributes
591
+ })
592
+ )
593
+ );
566
594
  }
567
- return otlpLayer;
568
595
  })
569
596
  ).pipe(effect.Layer.orDie);
570
597
  }
571
598
  var EffectInstrumentationLive = effect.Effect.sync(() => {
572
- const endpoint = process.env.OTEL_EXPORTER_OTLP_ENDPOINT || "http://localhost:4318";
573
599
  const serviceName = process.env.OTEL_SERVICE_NAME || "effect-service";
574
600
  const serviceVersion = process.env.npm_package_version || "1.0.0";
575
601
  logger.minimal(`@atrim/instrumentation/effect: Effect tracing enabled (${serviceName})`);
576
- logger.log("\u{1F50D} Effect OpenTelemetry tracer");
577
- logger.log(` \u{1F4E1} Endpoint: ${endpoint}`);
578
- logger.log(` \u{1F3F7}\uFE0F Service: ${serviceName}`);
579
- return Otlp__namespace.layer({
580
- baseUrl: endpoint,
581
- resource: {
582
- serviceName,
583
- serviceVersion,
584
- attributes: {
585
- "platform.component": "effect",
586
- [ATTR_TELEMETRY_SDK_LANGUAGE]: TELEMETRY_SDK_LANGUAGE_VALUE_NODEJS,
587
- [ATTR_TELEMETRY_SDK_NAME]: SDK_NAME
588
- }
589
- },
590
- // CRITICAL: Bridge Effect context to OpenTelemetry global context
591
- // This allows NodeSDK auto-instrumentation to see Effect spans as parent spans
592
- tracerContext: (f, span) => {
593
- if (span._tag !== "Span") {
594
- return f();
595
- }
596
- const spanContext = {
597
- traceId: span.traceId,
598
- spanId: span.spanId,
599
- traceFlags: span.sampled ? api.TraceFlags.SAMPLED : api.TraceFlags.NONE
600
- };
601
- const otelSpan = api.trace.wrapSpanContext(spanContext);
602
- return api.context.with(api.trace.setSpan(api.context.active(), otelSpan), f);
603
- }
604
- }).pipe(effect.Layer.provide(platform.FetchHttpClient.layer));
602
+ logger.log("Effect OpenTelemetry tracer (unified)");
603
+ logger.log(` Service: ${serviceName}`);
604
+ return Tracer__namespace.layerGlobal.pipe(
605
+ effect.Layer.provide(
606
+ Resource__namespace.layer({
607
+ serviceName,
608
+ serviceVersion,
609
+ attributes: {
610
+ "platform.component": "effect",
611
+ [ATTR_TELEMETRY_SDK_LANGUAGE]: TELEMETRY_SDK_LANGUAGE_VALUE_NODEJS,
612
+ [ATTR_TELEMETRY_SDK_NAME]: SDK_NAME,
613
+ [ATTR_TELEMETRY_EXPORTER_MODE]: "unified"
614
+ }
615
+ })
616
+ )
617
+ );
605
618
  }).pipe(effect.Layer.unwrapEffect);
606
619
  function annotateUser(userId, email, username) {
607
620
  const attributes = {