@atrim/instrument-node 0.5.0 → 0.5.1

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.
@@ -34,6 +34,11 @@ var HttpClient__namespace = /*#__PURE__*/_interopNamespace(HttpClient);
34
34
  var HttpClientRequest__namespace = /*#__PURE__*/_interopNamespace(HttpClientRequest);
35
35
 
36
36
  // src/integrations/effect/effect-tracer.ts
37
+
38
+ // ../../node_modules/.pnpm/@opentelemetry+semantic-conventions@1.38.0/node_modules/@opentelemetry/semantic-conventions/build/esm/stable_attributes.js
39
+ var ATTR_TELEMETRY_SDK_LANGUAGE = "telemetry.sdk.language";
40
+ var TELEMETRY_SDK_LANGUAGE_VALUE_NODEJS = "nodejs";
41
+ var ATTR_TELEMETRY_SDK_NAME = "telemetry.sdk.name";
37
42
  var __defProp = Object.defineProperty;
38
43
  var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
39
44
  var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
@@ -70,7 +75,20 @@ var HttpFilteringConfigSchema = zod.z.object({
70
75
  // Patterns to ignore for incoming HTTP requests (string patterns only in YAML)
71
76
  ignore_incoming_paths: zod.z.array(zod.z.string()).optional(),
72
77
  // Require parent span for outgoing requests (prevents root spans for HTTP calls)
73
- require_parent_for_outgoing_spans: zod.z.boolean().optional()
78
+ require_parent_for_outgoing_spans: zod.z.boolean().optional(),
79
+ // Trace context propagation configuration
80
+ // Controls which cross-origin requests receive W3C Trace Context headers (traceparent, tracestate)
81
+ propagate_trace_context: zod.z.object({
82
+ // Strategy for trace propagation
83
+ // - "all": Propagate to all cross-origin requests (may cause CORS errors)
84
+ // - "none": Never propagate trace headers
85
+ // - "same-origin": Only propagate to same-origin requests (default, safe)
86
+ // - "patterns": Propagate based on include_urls patterns
87
+ strategy: zod.z.enum(["all", "none", "same-origin", "patterns"]).default("same-origin"),
88
+ // URL patterns to include when strategy is "patterns"
89
+ // Supports regex patterns (e.g., "^https://api\\.myapp\\.com")
90
+ include_urls: zod.z.array(zod.z.string()).optional()
91
+ }).optional()
74
92
  });
75
93
  var InstrumentationConfigSchema = zod.z.object({
76
94
  version: zod.z.string(),
@@ -489,6 +507,7 @@ async function loadConfigWithOptions(options = {}) {
489
507
  }
490
508
 
491
509
  // src/integrations/effect/effect-tracer.ts
510
+ var SDK_NAME = "@effect/opentelemetry-otlp";
492
511
  function createEffectInstrumentation(options = {}) {
493
512
  return effect.Layer.unwrapEffect(
494
513
  effect.Effect.gen(function* () {
@@ -522,7 +541,9 @@ function createEffectInstrumentation(options = {}) {
522
541
  attributes: {
523
542
  "platform.component": "effect",
524
543
  "effect.auto_metadata": autoExtractMetadata,
525
- "effect.context_propagation": continueExistingTraces
544
+ "effect.context_propagation": continueExistingTraces,
545
+ [ATTR_TELEMETRY_SDK_LANGUAGE]: TELEMETRY_SDK_LANGUAGE_VALUE_NODEJS,
546
+ [ATTR_TELEMETRY_SDK_NAME]: SDK_NAME
526
547
  }
527
548
  },
528
549
  // Bridge Effect context to OpenTelemetry global context
@@ -561,7 +582,9 @@ var EffectInstrumentationLive = effect.Effect.sync(() => {
561
582
  serviceName,
562
583
  serviceVersion,
563
584
  attributes: {
564
- "platform.component": "effect"
585
+ "platform.component": "effect",
586
+ [ATTR_TELEMETRY_SDK_LANGUAGE]: TELEMETRY_SDK_LANGUAGE_VALUE_NODEJS,
587
+ [ATTR_TELEMETRY_SDK_NAME]: SDK_NAME
565
588
  }
566
589
  },
567
590
  // CRITICAL: Bridge Effect context to OpenTelemetry global context
@@ -580,25 +603,144 @@ var EffectInstrumentationLive = effect.Effect.sync(() => {
580
603
  }
581
604
  }).pipe(effect.Layer.provide(platform.FetchHttpClient.layer));
582
605
  }).pipe(effect.Layer.unwrapEffect);
583
-
584
- // src/integrations/effect/effect-helpers.ts
585
- function annotateUser(_userId, _email) {
606
+ function annotateUser(userId, email, username) {
607
+ const attributes = {
608
+ "user.id": userId
609
+ };
610
+ if (email) attributes["user.email"] = email;
611
+ if (username) attributes["user.name"] = username;
612
+ return effect.Effect.annotateCurrentSpan(attributes);
613
+ }
614
+ function annotateDataSize(bytes, items, compressionRatio) {
615
+ const attributes = {
616
+ "data.size.bytes": bytes,
617
+ "data.size.items": items
618
+ };
619
+ if (compressionRatio !== void 0) {
620
+ attributes["data.compression.ratio"] = compressionRatio;
621
+ }
622
+ return effect.Effect.annotateCurrentSpan(attributes);
586
623
  }
587
- function annotateDataSize(_bytes, _count) {
624
+ function annotateBatch(totalItems, batchSize, successCount, failureCount) {
625
+ const attributes = {
626
+ "batch.size": batchSize,
627
+ "batch.total_items": totalItems,
628
+ "batch.count": Math.ceil(totalItems / batchSize)
629
+ };
630
+ if (successCount !== void 0) {
631
+ attributes["batch.success_count"] = successCount;
632
+ }
633
+ if (failureCount !== void 0) {
634
+ attributes["batch.failure_count"] = failureCount;
635
+ }
636
+ return effect.Effect.annotateCurrentSpan(attributes);
588
637
  }
589
- function annotateBatch(_size, _batchSize) {
638
+ function annotateLLM(model, provider, tokens) {
639
+ const attributes = {
640
+ "llm.model": model,
641
+ "llm.provider": provider
642
+ };
643
+ if (tokens) {
644
+ if (tokens.prompt !== void 0) attributes["llm.tokens.prompt"] = tokens.prompt;
645
+ if (tokens.completion !== void 0) attributes["llm.tokens.completion"] = tokens.completion;
646
+ if (tokens.total !== void 0) attributes["llm.tokens.total"] = tokens.total;
647
+ }
648
+ return effect.Effect.annotateCurrentSpan(attributes);
590
649
  }
591
- function annotateLLM(_model, _operation, _inputTokens, _outputTokens) {
650
+ function annotateQuery(query, duration, rowCount, database) {
651
+ const attributes = {
652
+ "db.statement": query.length > 1e3 ? query.substring(0, 1e3) + "..." : query
653
+ };
654
+ if (duration !== void 0) attributes["db.duration.ms"] = duration;
655
+ if (rowCount !== void 0) attributes["db.row_count"] = rowCount;
656
+ if (database) attributes["db.name"] = database;
657
+ return effect.Effect.annotateCurrentSpan(attributes);
592
658
  }
593
- function annotateQuery(_query, _database) {
659
+ function annotateHttpRequest(method, url, statusCode, contentLength) {
660
+ const attributes = {
661
+ "http.method": method,
662
+ "http.url": url
663
+ };
664
+ if (statusCode !== void 0) attributes["http.status_code"] = statusCode;
665
+ if (contentLength !== void 0) attributes["http.response.content_length"] = contentLength;
666
+ return effect.Effect.annotateCurrentSpan(attributes);
594
667
  }
595
- function annotateHttpRequest(_method, _url, _statusCode) {
668
+ function annotateError(error, recoverable, errorType) {
669
+ const errorMessage = typeof error === "string" ? error : error.message;
670
+ const errorStack = typeof error === "string" ? void 0 : error.stack;
671
+ const attributes = {
672
+ "error.message": errorMessage,
673
+ "error.recoverable": recoverable
674
+ };
675
+ if (errorType) attributes["error.type"] = errorType;
676
+ if (errorStack) attributes["error.stack"] = errorStack;
677
+ return effect.Effect.annotateCurrentSpan(attributes);
596
678
  }
597
- function annotateError(_error, _context) {
679
+ function annotatePriority(priority, reason) {
680
+ const attributes = {
681
+ "operation.priority": priority
682
+ };
683
+ if (reason) attributes["operation.priority.reason"] = reason;
684
+ return effect.Effect.annotateCurrentSpan(attributes);
598
685
  }
599
- function annotatePriority(_priority) {
686
+ function annotateCache(hit, key, ttl) {
687
+ const attributes = {
688
+ "cache.hit": hit,
689
+ "cache.key": key
690
+ };
691
+ if (ttl !== void 0) attributes["cache.ttl.seconds"] = ttl;
692
+ return effect.Effect.annotateCurrentSpan(attributes);
600
693
  }
601
- function annotateCache(_operation, _hit) {
694
+ function extractEffectMetadata() {
695
+ return effect.Effect.gen(function* () {
696
+ const metadata = {};
697
+ const currentFiber = effect.Fiber.getCurrentFiber();
698
+ if (effect.Option.isSome(currentFiber)) {
699
+ const fiber = currentFiber.value;
700
+ const fiberId = fiber.id();
701
+ metadata["effect.fiber.id"] = effect.FiberId.threadName(fiberId);
702
+ const status = yield* effect.Fiber.status(fiber);
703
+ if (status._tag) {
704
+ metadata["effect.fiber.status"] = status._tag;
705
+ }
706
+ }
707
+ const parentSpanResult = yield* effect.Effect.currentSpan.pipe(
708
+ effect.Effect.option
709
+ // Convert NoSuchElementException to Option
710
+ );
711
+ if (effect.Option.isSome(parentSpanResult)) {
712
+ const parentSpan = parentSpanResult.value;
713
+ metadata["effect.operation.nested"] = true;
714
+ metadata["effect.operation.root"] = false;
715
+ if (parentSpan.spanId) {
716
+ metadata["effect.parent.span.id"] = parentSpan.spanId;
717
+ }
718
+ if (parentSpan.name) {
719
+ metadata["effect.parent.span.name"] = parentSpan.name;
720
+ }
721
+ if (parentSpan.traceId) {
722
+ metadata["effect.parent.trace.id"] = parentSpan.traceId;
723
+ }
724
+ } else {
725
+ metadata["effect.operation.nested"] = false;
726
+ metadata["effect.operation.root"] = true;
727
+ }
728
+ return metadata;
729
+ });
730
+ }
731
+ function autoEnrichSpan() {
732
+ return effect.Effect.gen(function* () {
733
+ const metadata = yield* extractEffectMetadata();
734
+ yield* effect.Effect.annotateCurrentSpan(metadata);
735
+ });
736
+ }
737
+ function withAutoEnrichedSpan(spanName, options) {
738
+ return (self) => {
739
+ return effect.Effect.gen(function* () {
740
+ yield* autoEnrichSpan();
741
+ return yield* self;
742
+ }).pipe(effect.Effect.withSpan(spanName, options));
743
+ };
602
744
  }
603
745
  var createLogicalParentLink = (parentSpan, useSpanLinks) => {
604
746
  if (!useSpanLinks) {
@@ -737,8 +879,11 @@ exports.annotatePriority = annotatePriority;
737
879
  exports.annotateQuery = annotateQuery;
738
880
  exports.annotateSpawnedTasks = annotateSpawnedTasks;
739
881
  exports.annotateUser = annotateUser;
882
+ exports.autoEnrichSpan = autoEnrichSpan;
740
883
  exports.createEffectInstrumentation = createEffectInstrumentation;
884
+ exports.extractEffectMetadata = extractEffectMetadata;
741
885
  exports.runIsolated = runIsolated;
742
886
  exports.runWithSpan = runWithSpan;
887
+ exports.withAutoEnrichedSpan = withAutoEnrichedSpan;
743
888
  //# sourceMappingURL=index.cjs.map
744
889
  //# sourceMappingURL=index.cjs.map