@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.
- package/README.md +66 -0
- package/package.json +8 -8
- package/target/dist/index.cjs +14 -1
- package/target/dist/index.cjs.map +1 -1
- package/target/dist/index.js +14 -1
- package/target/dist/index.js.map +1 -1
- package/target/dist/integrations/effect/index.cjs +159 -14
- package/target/dist/integrations/effect/index.cjs.map +1 -1
- package/target/dist/integrations/effect/index.d.cts +187 -12
- package/target/dist/integrations/effect/index.d.ts +187 -12
- package/target/dist/integrations/effect/index.js +158 -16
- package/target/dist/integrations/effect/index.js.map +1 -1
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Data, Context, Effect, Layer, FiberSet as FiberSet$1, Tracer } from 'effect';
|
|
1
|
+
import { Data, Context, Effect, Layer, FiberSet as FiberSet$1, Fiber, Option, FiberId, Tracer } from 'effect';
|
|
2
2
|
import * as Otlp from '@effect/opentelemetry/Otlp';
|
|
3
3
|
import { FetchHttpClient } from '@effect/platform';
|
|
4
4
|
import { TraceFlags, trace, context } from '@opentelemetry/api';
|
|
@@ -10,6 +10,11 @@ import { z } from 'zod';
|
|
|
10
10
|
import { NodeContext } from '@effect/platform-node';
|
|
11
11
|
|
|
12
12
|
// src/integrations/effect/effect-tracer.ts
|
|
13
|
+
|
|
14
|
+
// ../../node_modules/.pnpm/@opentelemetry+semantic-conventions@1.38.0/node_modules/@opentelemetry/semantic-conventions/build/esm/stable_attributes.js
|
|
15
|
+
var ATTR_TELEMETRY_SDK_LANGUAGE = "telemetry.sdk.language";
|
|
16
|
+
var TELEMETRY_SDK_LANGUAGE_VALUE_NODEJS = "nodejs";
|
|
17
|
+
var ATTR_TELEMETRY_SDK_NAME = "telemetry.sdk.name";
|
|
13
18
|
var __defProp = Object.defineProperty;
|
|
14
19
|
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
15
20
|
var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
@@ -46,7 +51,20 @@ var HttpFilteringConfigSchema = z.object({
|
|
|
46
51
|
// Patterns to ignore for incoming HTTP requests (string patterns only in YAML)
|
|
47
52
|
ignore_incoming_paths: z.array(z.string()).optional(),
|
|
48
53
|
// Require parent span for outgoing requests (prevents root spans for HTTP calls)
|
|
49
|
-
require_parent_for_outgoing_spans: z.boolean().optional()
|
|
54
|
+
require_parent_for_outgoing_spans: z.boolean().optional(),
|
|
55
|
+
// Trace context propagation configuration
|
|
56
|
+
// Controls which cross-origin requests receive W3C Trace Context headers (traceparent, tracestate)
|
|
57
|
+
propagate_trace_context: z.object({
|
|
58
|
+
// Strategy for trace propagation
|
|
59
|
+
// - "all": Propagate to all cross-origin requests (may cause CORS errors)
|
|
60
|
+
// - "none": Never propagate trace headers
|
|
61
|
+
// - "same-origin": Only propagate to same-origin requests (default, safe)
|
|
62
|
+
// - "patterns": Propagate based on include_urls patterns
|
|
63
|
+
strategy: z.enum(["all", "none", "same-origin", "patterns"]).default("same-origin"),
|
|
64
|
+
// URL patterns to include when strategy is "patterns"
|
|
65
|
+
// Supports regex patterns (e.g., "^https://api\\.myapp\\.com")
|
|
66
|
+
include_urls: z.array(z.string()).optional()
|
|
67
|
+
}).optional()
|
|
50
68
|
});
|
|
51
69
|
var InstrumentationConfigSchema = z.object({
|
|
52
70
|
version: z.string(),
|
|
@@ -465,6 +483,7 @@ async function loadConfigWithOptions(options = {}) {
|
|
|
465
483
|
}
|
|
466
484
|
|
|
467
485
|
// src/integrations/effect/effect-tracer.ts
|
|
486
|
+
var SDK_NAME = "@effect/opentelemetry-otlp";
|
|
468
487
|
function createEffectInstrumentation(options = {}) {
|
|
469
488
|
return Layer.unwrapEffect(
|
|
470
489
|
Effect.gen(function* () {
|
|
@@ -498,7 +517,9 @@ function createEffectInstrumentation(options = {}) {
|
|
|
498
517
|
attributes: {
|
|
499
518
|
"platform.component": "effect",
|
|
500
519
|
"effect.auto_metadata": autoExtractMetadata,
|
|
501
|
-
"effect.context_propagation": continueExistingTraces
|
|
520
|
+
"effect.context_propagation": continueExistingTraces,
|
|
521
|
+
[ATTR_TELEMETRY_SDK_LANGUAGE]: TELEMETRY_SDK_LANGUAGE_VALUE_NODEJS,
|
|
522
|
+
[ATTR_TELEMETRY_SDK_NAME]: SDK_NAME
|
|
502
523
|
}
|
|
503
524
|
},
|
|
504
525
|
// Bridge Effect context to OpenTelemetry global context
|
|
@@ -537,7 +558,9 @@ var EffectInstrumentationLive = Effect.sync(() => {
|
|
|
537
558
|
serviceName,
|
|
538
559
|
serviceVersion,
|
|
539
560
|
attributes: {
|
|
540
|
-
"platform.component": "effect"
|
|
561
|
+
"platform.component": "effect",
|
|
562
|
+
[ATTR_TELEMETRY_SDK_LANGUAGE]: TELEMETRY_SDK_LANGUAGE_VALUE_NODEJS,
|
|
563
|
+
[ATTR_TELEMETRY_SDK_NAME]: SDK_NAME
|
|
541
564
|
}
|
|
542
565
|
},
|
|
543
566
|
// CRITICAL: Bridge Effect context to OpenTelemetry global context
|
|
@@ -556,25 +579,144 @@ var EffectInstrumentationLive = Effect.sync(() => {
|
|
|
556
579
|
}
|
|
557
580
|
}).pipe(Layer.provide(FetchHttpClient.layer));
|
|
558
581
|
}).pipe(Layer.unwrapEffect);
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
582
|
+
function annotateUser(userId, email, username) {
|
|
583
|
+
const attributes = {
|
|
584
|
+
"user.id": userId
|
|
585
|
+
};
|
|
586
|
+
if (email) attributes["user.email"] = email;
|
|
587
|
+
if (username) attributes["user.name"] = username;
|
|
588
|
+
return Effect.annotateCurrentSpan(attributes);
|
|
589
|
+
}
|
|
590
|
+
function annotateDataSize(bytes, items, compressionRatio) {
|
|
591
|
+
const attributes = {
|
|
592
|
+
"data.size.bytes": bytes,
|
|
593
|
+
"data.size.items": items
|
|
594
|
+
};
|
|
595
|
+
if (compressionRatio !== void 0) {
|
|
596
|
+
attributes["data.compression.ratio"] = compressionRatio;
|
|
597
|
+
}
|
|
598
|
+
return Effect.annotateCurrentSpan(attributes);
|
|
562
599
|
}
|
|
563
|
-
function
|
|
600
|
+
function annotateBatch(totalItems, batchSize, successCount, failureCount) {
|
|
601
|
+
const attributes = {
|
|
602
|
+
"batch.size": batchSize,
|
|
603
|
+
"batch.total_items": totalItems,
|
|
604
|
+
"batch.count": Math.ceil(totalItems / batchSize)
|
|
605
|
+
};
|
|
606
|
+
if (successCount !== void 0) {
|
|
607
|
+
attributes["batch.success_count"] = successCount;
|
|
608
|
+
}
|
|
609
|
+
if (failureCount !== void 0) {
|
|
610
|
+
attributes["batch.failure_count"] = failureCount;
|
|
611
|
+
}
|
|
612
|
+
return Effect.annotateCurrentSpan(attributes);
|
|
564
613
|
}
|
|
565
|
-
function
|
|
614
|
+
function annotateLLM(model, provider, tokens) {
|
|
615
|
+
const attributes = {
|
|
616
|
+
"llm.model": model,
|
|
617
|
+
"llm.provider": provider
|
|
618
|
+
};
|
|
619
|
+
if (tokens) {
|
|
620
|
+
if (tokens.prompt !== void 0) attributes["llm.tokens.prompt"] = tokens.prompt;
|
|
621
|
+
if (tokens.completion !== void 0) attributes["llm.tokens.completion"] = tokens.completion;
|
|
622
|
+
if (tokens.total !== void 0) attributes["llm.tokens.total"] = tokens.total;
|
|
623
|
+
}
|
|
624
|
+
return Effect.annotateCurrentSpan(attributes);
|
|
566
625
|
}
|
|
567
|
-
function
|
|
626
|
+
function annotateQuery(query, duration, rowCount, database) {
|
|
627
|
+
const attributes = {
|
|
628
|
+
"db.statement": query.length > 1e3 ? query.substring(0, 1e3) + "..." : query
|
|
629
|
+
};
|
|
630
|
+
if (duration !== void 0) attributes["db.duration.ms"] = duration;
|
|
631
|
+
if (rowCount !== void 0) attributes["db.row_count"] = rowCount;
|
|
632
|
+
if (database) attributes["db.name"] = database;
|
|
633
|
+
return Effect.annotateCurrentSpan(attributes);
|
|
568
634
|
}
|
|
569
|
-
function
|
|
635
|
+
function annotateHttpRequest(method, url, statusCode, contentLength) {
|
|
636
|
+
const attributes = {
|
|
637
|
+
"http.method": method,
|
|
638
|
+
"http.url": url
|
|
639
|
+
};
|
|
640
|
+
if (statusCode !== void 0) attributes["http.status_code"] = statusCode;
|
|
641
|
+
if (contentLength !== void 0) attributes["http.response.content_length"] = contentLength;
|
|
642
|
+
return Effect.annotateCurrentSpan(attributes);
|
|
570
643
|
}
|
|
571
|
-
function
|
|
644
|
+
function annotateError(error, recoverable, errorType) {
|
|
645
|
+
const errorMessage = typeof error === "string" ? error : error.message;
|
|
646
|
+
const errorStack = typeof error === "string" ? void 0 : error.stack;
|
|
647
|
+
const attributes = {
|
|
648
|
+
"error.message": errorMessage,
|
|
649
|
+
"error.recoverable": recoverable
|
|
650
|
+
};
|
|
651
|
+
if (errorType) attributes["error.type"] = errorType;
|
|
652
|
+
if (errorStack) attributes["error.stack"] = errorStack;
|
|
653
|
+
return Effect.annotateCurrentSpan(attributes);
|
|
572
654
|
}
|
|
573
|
-
function
|
|
655
|
+
function annotatePriority(priority, reason) {
|
|
656
|
+
const attributes = {
|
|
657
|
+
"operation.priority": priority
|
|
658
|
+
};
|
|
659
|
+
if (reason) attributes["operation.priority.reason"] = reason;
|
|
660
|
+
return Effect.annotateCurrentSpan(attributes);
|
|
574
661
|
}
|
|
575
|
-
function
|
|
662
|
+
function annotateCache(hit, key, ttl) {
|
|
663
|
+
const attributes = {
|
|
664
|
+
"cache.hit": hit,
|
|
665
|
+
"cache.key": key
|
|
666
|
+
};
|
|
667
|
+
if (ttl !== void 0) attributes["cache.ttl.seconds"] = ttl;
|
|
668
|
+
return Effect.annotateCurrentSpan(attributes);
|
|
576
669
|
}
|
|
577
|
-
function
|
|
670
|
+
function extractEffectMetadata() {
|
|
671
|
+
return Effect.gen(function* () {
|
|
672
|
+
const metadata = {};
|
|
673
|
+
const currentFiber = Fiber.getCurrentFiber();
|
|
674
|
+
if (Option.isSome(currentFiber)) {
|
|
675
|
+
const fiber = currentFiber.value;
|
|
676
|
+
const fiberId = fiber.id();
|
|
677
|
+
metadata["effect.fiber.id"] = FiberId.threadName(fiberId);
|
|
678
|
+
const status = yield* Fiber.status(fiber);
|
|
679
|
+
if (status._tag) {
|
|
680
|
+
metadata["effect.fiber.status"] = status._tag;
|
|
681
|
+
}
|
|
682
|
+
}
|
|
683
|
+
const parentSpanResult = yield* Effect.currentSpan.pipe(
|
|
684
|
+
Effect.option
|
|
685
|
+
// Convert NoSuchElementException to Option
|
|
686
|
+
);
|
|
687
|
+
if (Option.isSome(parentSpanResult)) {
|
|
688
|
+
const parentSpan = parentSpanResult.value;
|
|
689
|
+
metadata["effect.operation.nested"] = true;
|
|
690
|
+
metadata["effect.operation.root"] = false;
|
|
691
|
+
if (parentSpan.spanId) {
|
|
692
|
+
metadata["effect.parent.span.id"] = parentSpan.spanId;
|
|
693
|
+
}
|
|
694
|
+
if (parentSpan.name) {
|
|
695
|
+
metadata["effect.parent.span.name"] = parentSpan.name;
|
|
696
|
+
}
|
|
697
|
+
if (parentSpan.traceId) {
|
|
698
|
+
metadata["effect.parent.trace.id"] = parentSpan.traceId;
|
|
699
|
+
}
|
|
700
|
+
} else {
|
|
701
|
+
metadata["effect.operation.nested"] = false;
|
|
702
|
+
metadata["effect.operation.root"] = true;
|
|
703
|
+
}
|
|
704
|
+
return metadata;
|
|
705
|
+
});
|
|
706
|
+
}
|
|
707
|
+
function autoEnrichSpan() {
|
|
708
|
+
return Effect.gen(function* () {
|
|
709
|
+
const metadata = yield* extractEffectMetadata();
|
|
710
|
+
yield* Effect.annotateCurrentSpan(metadata);
|
|
711
|
+
});
|
|
712
|
+
}
|
|
713
|
+
function withAutoEnrichedSpan(spanName, options) {
|
|
714
|
+
return (self) => {
|
|
715
|
+
return Effect.gen(function* () {
|
|
716
|
+
yield* autoEnrichSpan();
|
|
717
|
+
return yield* self;
|
|
718
|
+
}).pipe(Effect.withSpan(spanName, options));
|
|
719
|
+
};
|
|
578
720
|
}
|
|
579
721
|
var createLogicalParentLink = (parentSpan, useSpanLinks) => {
|
|
580
722
|
if (!useSpanLinks) {
|
|
@@ -701,6 +843,6 @@ var FiberSet = {
|
|
|
701
843
|
runWithSpan
|
|
702
844
|
};
|
|
703
845
|
|
|
704
|
-
export { EffectInstrumentationLive, FiberSet, annotateBatch, annotateCache, annotateDataSize, annotateError, annotateHttpRequest, annotateLLM, annotatePriority, annotateQuery, annotateSpawnedTasks, annotateUser, createEffectInstrumentation, runIsolated, runWithSpan };
|
|
846
|
+
export { EffectInstrumentationLive, FiberSet, annotateBatch, annotateCache, annotateDataSize, annotateError, annotateHttpRequest, annotateLLM, annotatePriority, annotateQuery, annotateSpawnedTasks, annotateUser, autoEnrichSpan, createEffectInstrumentation, extractEffectMetadata, runIsolated, runWithSpan, withAutoEnrichedSpan };
|
|
705
847
|
//# sourceMappingURL=index.js.map
|
|
706
848
|
//# sourceMappingURL=index.js.map
|