@atrim/instrument-node 0.5.0-c05e3a1-20251119131235 → 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);
@@ -502,6 +507,7 @@ async function loadConfigWithOptions(options = {}) {
502
507
  }
503
508
 
504
509
  // src/integrations/effect/effect-tracer.ts
510
+ var SDK_NAME = "@effect/opentelemetry-otlp";
505
511
  function createEffectInstrumentation(options = {}) {
506
512
  return effect.Layer.unwrapEffect(
507
513
  effect.Effect.gen(function* () {
@@ -535,7 +541,9 @@ function createEffectInstrumentation(options = {}) {
535
541
  attributes: {
536
542
  "platform.component": "effect",
537
543
  "effect.auto_metadata": autoExtractMetadata,
538
- "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
539
547
  }
540
548
  },
541
549
  // Bridge Effect context to OpenTelemetry global context
@@ -574,7 +582,9 @@ var EffectInstrumentationLive = effect.Effect.sync(() => {
574
582
  serviceName,
575
583
  serviceVersion,
576
584
  attributes: {
577
- "platform.component": "effect"
585
+ "platform.component": "effect",
586
+ [ATTR_TELEMETRY_SDK_LANGUAGE]: TELEMETRY_SDK_LANGUAGE_VALUE_NODEJS,
587
+ [ATTR_TELEMETRY_SDK_NAME]: SDK_NAME
578
588
  }
579
589
  },
580
590
  // CRITICAL: Bridge Effect context to OpenTelemetry global context
@@ -593,25 +603,144 @@ var EffectInstrumentationLive = effect.Effect.sync(() => {
593
603
  }
594
604
  }).pipe(effect.Layer.provide(platform.FetchHttpClient.layer));
595
605
  }).pipe(effect.Layer.unwrapEffect);
596
-
597
- // src/integrations/effect/effect-helpers.ts
598
- 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);
599
623
  }
600
- 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);
601
637
  }
602
- 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);
603
649
  }
604
- 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);
605
658
  }
606
- 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);
607
667
  }
608
- 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);
609
678
  }
610
- 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);
611
685
  }
612
- 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);
613
693
  }
614
- 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
+ };
615
744
  }
616
745
  var createLogicalParentLink = (parentSpan, useSpanLinks) => {
617
746
  if (!useSpanLinks) {
@@ -750,8 +879,11 @@ exports.annotatePriority = annotatePriority;
750
879
  exports.annotateQuery = annotateQuery;
751
880
  exports.annotateSpawnedTasks = annotateSpawnedTasks;
752
881
  exports.annotateUser = annotateUser;
882
+ exports.autoEnrichSpan = autoEnrichSpan;
753
883
  exports.createEffectInstrumentation = createEffectInstrumentation;
884
+ exports.extractEffectMetadata = extractEffectMetadata;
754
885
  exports.runIsolated = runIsolated;
755
886
  exports.runWithSpan = runWithSpan;
887
+ exports.withAutoEnrichedSpan = withAutoEnrichedSpan;
756
888
  //# sourceMappingURL=index.cjs.map
757
889
  //# sourceMappingURL=index.cjs.map