@atrim/instrument-node 0.5.0-c05e3a1-20251119131235 → 0.5.1-1451fcf-20260105212505
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 +97 -269
- package/package.json +18 -17
- package/target/dist/index.cjs +209 -117
- package/target/dist/index.cjs.map +1 -1
- package/target/dist/index.d.cts +168 -120
- package/target/dist/index.d.ts +168 -120
- package/target/dist/index.js +202 -116
- package/target/dist/index.js.map +1 -1
- package/target/dist/integrations/effect/index.cjs +287 -129
- package/target/dist/integrations/effect/index.cjs.map +1 -1
- package/target/dist/integrations/effect/index.d.cts +205 -36
- package/target/dist/integrations/effect/index.d.ts +205 -36
- package/target/dist/integrations/effect/index.js +284 -131
- package/target/dist/integrations/effect/index.js.map +1 -1
|
@@ -1,13 +1,15 @@
|
|
|
1
|
-
import { Data, Context, Effect, Layer, FiberSet as FiberSet$1,
|
|
1
|
+
import { Data, Context, Effect, Layer, Tracer, FiberSet as FiberSet$1, Fiber, Option, FiberId } from 'effect';
|
|
2
|
+
import * as OtelTracer from '@effect/opentelemetry/Tracer';
|
|
3
|
+
import * as Resource from '@effect/opentelemetry/Resource';
|
|
2
4
|
import * as Otlp from '@effect/opentelemetry/Otlp';
|
|
3
5
|
import { FetchHttpClient } from '@effect/platform';
|
|
4
6
|
import { TraceFlags, trace, context } from '@opentelemetry/api';
|
|
7
|
+
import { TELEMETRY_SDK_LANGUAGE_VALUE_NODEJS, ATTR_TELEMETRY_SDK_NAME, ATTR_TELEMETRY_SDK_LANGUAGE } from '@opentelemetry/semantic-conventions';
|
|
5
8
|
import { FileSystem } from '@effect/platform/FileSystem';
|
|
6
9
|
import * as HttpClient from '@effect/platform/HttpClient';
|
|
7
10
|
import * as HttpClientRequest from '@effect/platform/HttpClientRequest';
|
|
8
11
|
import { parse } from 'yaml';
|
|
9
12
|
import { z } from 'zod';
|
|
10
|
-
import { NodeContext } from '@effect/platform-node';
|
|
11
13
|
|
|
12
14
|
// src/integrations/effect/effect-tracer.ts
|
|
13
15
|
var __defProp = Object.defineProperty;
|
|
@@ -71,11 +73,50 @@ var InstrumentationConfigSchema = z.object({
|
|
|
71
73
|
ignore_patterns: z.array(PatternConfigSchema)
|
|
72
74
|
}),
|
|
73
75
|
effect: z.object({
|
|
76
|
+
// Enable/disable Effect tracing entirely
|
|
77
|
+
// When false, EffectInstrumentationLive returns Layer.empty
|
|
78
|
+
enabled: z.boolean().default(true),
|
|
79
|
+
// Exporter mode:
|
|
80
|
+
// - "unified": Use global TracerProvider from Node SDK (recommended, enables filtering)
|
|
81
|
+
// - "standalone": Use Effect's own OTLP exporter (bypasses Node SDK filtering)
|
|
82
|
+
exporter: z.enum(["unified", "standalone"]).default("unified"),
|
|
74
83
|
auto_extract_metadata: z.boolean(),
|
|
75
84
|
auto_isolation: AutoIsolationConfigSchema.optional()
|
|
76
85
|
}).optional(),
|
|
77
86
|
http: HttpFilteringConfigSchema.optional()
|
|
78
87
|
});
|
|
88
|
+
var defaultConfig = {
|
|
89
|
+
version: "1.0",
|
|
90
|
+
instrumentation: {
|
|
91
|
+
enabled: true,
|
|
92
|
+
logging: "on",
|
|
93
|
+
description: "Default instrumentation configuration",
|
|
94
|
+
instrument_patterns: [
|
|
95
|
+
{ pattern: "^app\\.", enabled: true, description: "Application operations" },
|
|
96
|
+
{ pattern: "^http\\.server\\.", enabled: true, description: "HTTP server operations" },
|
|
97
|
+
{ pattern: "^http\\.client\\.", enabled: true, description: "HTTP client operations" }
|
|
98
|
+
],
|
|
99
|
+
ignore_patterns: [
|
|
100
|
+
{ pattern: "^test\\.", description: "Test utilities" },
|
|
101
|
+
{ pattern: "^internal\\.", description: "Internal operations" },
|
|
102
|
+
{ pattern: "^health\\.", description: "Health checks" }
|
|
103
|
+
]
|
|
104
|
+
},
|
|
105
|
+
effect: {
|
|
106
|
+
enabled: true,
|
|
107
|
+
exporter: "unified",
|
|
108
|
+
auto_extract_metadata: true
|
|
109
|
+
}
|
|
110
|
+
};
|
|
111
|
+
function parseAndValidateConfig(content) {
|
|
112
|
+
let parsed;
|
|
113
|
+
if (typeof content === "string") {
|
|
114
|
+
parsed = parse(content);
|
|
115
|
+
} else {
|
|
116
|
+
parsed = content;
|
|
117
|
+
}
|
|
118
|
+
return InstrumentationConfigSchema.parse(parsed);
|
|
119
|
+
}
|
|
79
120
|
(class extends Data.TaggedError("ConfigError") {
|
|
80
121
|
get message() {
|
|
81
122
|
return this.reason;
|
|
@@ -253,7 +294,7 @@ var makeConfigLoader = Effect.gen(function* () {
|
|
|
253
294
|
})
|
|
254
295
|
});
|
|
255
296
|
});
|
|
256
|
-
|
|
297
|
+
Layer.effect(ConfigLoader, makeConfigLoader);
|
|
257
298
|
var PatternMatcher = class {
|
|
258
299
|
constructor(config) {
|
|
259
300
|
__publicField(this, "ignorePatterns", []);
|
|
@@ -401,83 +442,73 @@ var Logger = class {
|
|
|
401
442
|
}
|
|
402
443
|
};
|
|
403
444
|
var logger = new Logger();
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
);
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
}).pipe(Effect.provide(NodeConfigLoaderLive))
|
|
414
|
-
);
|
|
445
|
+
async function loadFromFile(filePath) {
|
|
446
|
+
const { readFile } = await import('fs/promises');
|
|
447
|
+
const content = await readFile(filePath, "utf-8");
|
|
448
|
+
return parseAndValidateConfig(content);
|
|
449
|
+
}
|
|
450
|
+
async function loadFromUrl(url) {
|
|
451
|
+
const response = await fetch(url);
|
|
452
|
+
if (!response.ok) {
|
|
453
|
+
throw new Error(`Failed to fetch config from ${url}: ${response.statusText}`);
|
|
415
454
|
}
|
|
416
|
-
|
|
455
|
+
const content = await response.text();
|
|
456
|
+
return parseAndValidateConfig(content);
|
|
417
457
|
}
|
|
418
|
-
async function loadConfig(uri,
|
|
419
|
-
if (
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
return
|
|
458
|
+
async function loadConfig(uri, _options) {
|
|
459
|
+
if (uri.startsWith("http://") || uri.startsWith("https://")) {
|
|
460
|
+
return loadFromUrl(uri);
|
|
461
|
+
}
|
|
462
|
+
if (uri.startsWith("file://")) {
|
|
463
|
+
const filePath = uri.slice(7);
|
|
464
|
+
return loadFromFile(filePath);
|
|
425
465
|
}
|
|
426
|
-
|
|
427
|
-
return Effect.runPromise(loader.loadFromUri(uri));
|
|
466
|
+
return loadFromFile(uri);
|
|
428
467
|
}
|
|
429
468
|
async function loadConfigFromInline(content) {
|
|
430
|
-
|
|
431
|
-
return Effect.runPromise(loader.loadFromInline(content));
|
|
432
|
-
}
|
|
433
|
-
function getDefaultConfig() {
|
|
434
|
-
return {
|
|
435
|
-
version: "1.0",
|
|
436
|
-
instrumentation: {
|
|
437
|
-
enabled: true,
|
|
438
|
-
logging: "on",
|
|
439
|
-
description: "Default instrumentation configuration",
|
|
440
|
-
instrument_patterns: [
|
|
441
|
-
{ pattern: "^app\\.", enabled: true, description: "Application operations" },
|
|
442
|
-
{ pattern: "^http\\.server\\.", enabled: true, description: "HTTP server operations" },
|
|
443
|
-
{ pattern: "^http\\.client\\.", enabled: true, description: "HTTP client operations" }
|
|
444
|
-
],
|
|
445
|
-
ignore_patterns: [
|
|
446
|
-
{ pattern: "^test\\.", description: "Test utilities" },
|
|
447
|
-
{ pattern: "^internal\\.", description: "Internal operations" },
|
|
448
|
-
{ pattern: "^health\\.", description: "Health checks" }
|
|
449
|
-
]
|
|
450
|
-
},
|
|
451
|
-
effect: {
|
|
452
|
-
auto_extract_metadata: true
|
|
453
|
-
}
|
|
454
|
-
};
|
|
469
|
+
return parseAndValidateConfig(content);
|
|
455
470
|
}
|
|
456
471
|
async function loadConfigWithOptions(options = {}) {
|
|
457
|
-
const loadOptions = options.cacheTimeout !== void 0 ? { cacheTimeout: options.cacheTimeout } : void 0;
|
|
458
472
|
if (options.config) {
|
|
459
473
|
return loadConfigFromInline(options.config);
|
|
460
474
|
}
|
|
461
475
|
const envConfigPath = process.env.ATRIM_INSTRUMENTATION_CONFIG;
|
|
462
476
|
if (envConfigPath) {
|
|
463
|
-
return loadConfig(envConfigPath
|
|
477
|
+
return loadConfig(envConfigPath);
|
|
464
478
|
}
|
|
465
479
|
if (options.configUrl) {
|
|
466
|
-
return loadConfig(options.configUrl
|
|
480
|
+
return loadConfig(options.configUrl);
|
|
467
481
|
}
|
|
468
482
|
if (options.configPath) {
|
|
469
|
-
return loadConfig(options.configPath
|
|
483
|
+
return loadConfig(options.configPath);
|
|
470
484
|
}
|
|
471
485
|
const { existsSync } = await import('fs');
|
|
472
486
|
const { join } = await import('path');
|
|
473
487
|
const defaultPath = join(process.cwd(), "instrumentation.yaml");
|
|
474
488
|
if (existsSync(defaultPath)) {
|
|
475
|
-
return loadConfig(defaultPath
|
|
489
|
+
return loadConfig(defaultPath);
|
|
476
490
|
}
|
|
477
|
-
return
|
|
491
|
+
return defaultConfig;
|
|
478
492
|
}
|
|
479
493
|
|
|
480
494
|
// src/integrations/effect/effect-tracer.ts
|
|
495
|
+
var SDK_NAME = "@effect/opentelemetry";
|
|
496
|
+
var ATTR_TELEMETRY_EXPORTER_MODE = "telemetry.exporter.mode";
|
|
497
|
+
var ATTR_EFFECT_INSTRUMENTED = "effect.instrumented";
|
|
498
|
+
var EffectAttributeTracerLayer = Layer.effect(
|
|
499
|
+
Tracer.Tracer,
|
|
500
|
+
Effect.gen(function* () {
|
|
501
|
+
const baseTracer = yield* OtelTracer.make;
|
|
502
|
+
return Tracer.make({
|
|
503
|
+
span: (name, parent, context2, links, startTime, kind, options) => {
|
|
504
|
+
const span = baseTracer.span(name, parent, context2, links, startTime, kind, options);
|
|
505
|
+
span.attribute(ATTR_EFFECT_INSTRUMENTED, true);
|
|
506
|
+
return span;
|
|
507
|
+
},
|
|
508
|
+
context: (f, fiber) => baseTracer.context(f, fiber)
|
|
509
|
+
});
|
|
510
|
+
}).pipe(Effect.provide(OtelTracer.layerGlobalTracer))
|
|
511
|
+
);
|
|
481
512
|
function createEffectInstrumentation(options = {}) {
|
|
482
513
|
return Layer.unwrapEffect(
|
|
483
514
|
Effect.gen(function* () {
|
|
@@ -488,106 +519,228 @@ function createEffectInstrumentation(options = {}) {
|
|
|
488
519
|
message: error instanceof Error ? error.message : String(error)
|
|
489
520
|
})
|
|
490
521
|
});
|
|
522
|
+
const effectEnabled = process.env.OTEL_EFFECT_ENABLED !== "false" && (config.effect?.enabled ?? true);
|
|
523
|
+
if (!effectEnabled) {
|
|
524
|
+
logger.log("@atrim/instrumentation/effect: Effect tracing disabled via config");
|
|
525
|
+
return Layer.empty;
|
|
526
|
+
}
|
|
491
527
|
yield* Effect.sync(() => {
|
|
492
528
|
const loggingLevel = config.instrumentation.logging || "on";
|
|
493
529
|
logger.setLevel(loggingLevel);
|
|
494
530
|
});
|
|
495
531
|
yield* Effect.sync(() => initializePatternMatcher(config));
|
|
496
|
-
const otlpEndpoint = options.otlpEndpoint || process.env.OTEL_EXPORTER_OTLP_ENDPOINT || "http://localhost:4318";
|
|
497
532
|
const serviceName = options.serviceName || process.env.OTEL_SERVICE_NAME || "effect-service";
|
|
498
533
|
const serviceVersion = options.serviceVersion || process.env.npm_package_version || "1.0.0";
|
|
499
|
-
const
|
|
500
|
-
const
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
534
|
+
const exporterMode = options.exporterMode ?? config.effect?.exporter ?? "unified";
|
|
535
|
+
const resourceAttributes = {
|
|
536
|
+
"platform.component": "effect",
|
|
537
|
+
[ATTR_TELEMETRY_SDK_LANGUAGE]: TELEMETRY_SDK_LANGUAGE_VALUE_NODEJS,
|
|
538
|
+
[ATTR_TELEMETRY_SDK_NAME]: SDK_NAME,
|
|
539
|
+
[ATTR_TELEMETRY_EXPORTER_MODE]: exporterMode
|
|
540
|
+
};
|
|
541
|
+
if (exporterMode === "standalone") {
|
|
542
|
+
const otlpEndpoint = options.otlpEndpoint || process.env.OTEL_EXPORTER_OTLP_ENDPOINT || "http://localhost:4318";
|
|
543
|
+
logger.log("Effect OpenTelemetry instrumentation (standalone)");
|
|
544
|
+
logger.log(` Service: ${serviceName}`);
|
|
545
|
+
logger.log(` Endpoint: ${otlpEndpoint}`);
|
|
546
|
+
logger.log(" WARNING: Standalone mode bypasses Node SDK filtering");
|
|
547
|
+
return Otlp.layer({
|
|
548
|
+
baseUrl: otlpEndpoint,
|
|
549
|
+
resource: {
|
|
550
|
+
serviceName,
|
|
551
|
+
serviceVersion,
|
|
552
|
+
attributes: resourceAttributes
|
|
553
|
+
},
|
|
554
|
+
// Bridge Effect context to OpenTelemetry global context
|
|
555
|
+
tracerContext: (f, span) => {
|
|
556
|
+
if (span._tag !== "Span") {
|
|
557
|
+
return f();
|
|
558
|
+
}
|
|
559
|
+
const spanContext = {
|
|
560
|
+
traceId: span.traceId,
|
|
561
|
+
spanId: span.spanId,
|
|
562
|
+
traceFlags: span.sampled ? TraceFlags.SAMPLED : TraceFlags.NONE
|
|
563
|
+
};
|
|
564
|
+
const otelSpan = trace.wrapSpanContext(spanContext);
|
|
565
|
+
return context.with(trace.setSpan(context.active(), otelSpan), f);
|
|
522
566
|
}
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
567
|
+
}).pipe(Layer.provide(FetchHttpClient.layer));
|
|
568
|
+
} else {
|
|
569
|
+
logger.log("Effect OpenTelemetry instrumentation (unified)");
|
|
570
|
+
logger.log(` Service: ${serviceName}`);
|
|
571
|
+
logger.log(" Using global TracerProvider for span export");
|
|
572
|
+
return EffectAttributeTracerLayer.pipe(
|
|
573
|
+
Layer.provide(
|
|
574
|
+
Resource.layer({
|
|
575
|
+
serviceName,
|
|
576
|
+
serviceVersion,
|
|
577
|
+
attributes: resourceAttributes
|
|
578
|
+
})
|
|
579
|
+
)
|
|
580
|
+
);
|
|
534
581
|
}
|
|
535
|
-
return otlpLayer;
|
|
536
582
|
})
|
|
537
583
|
).pipe(Layer.orDie);
|
|
538
584
|
}
|
|
539
585
|
var EffectInstrumentationLive = Effect.sync(() => {
|
|
540
|
-
const endpoint = process.env.OTEL_EXPORTER_OTLP_ENDPOINT || "http://localhost:4318";
|
|
541
586
|
const serviceName = process.env.OTEL_SERVICE_NAME || "effect-service";
|
|
542
587
|
const serviceVersion = process.env.npm_package_version || "1.0.0";
|
|
543
588
|
logger.minimal(`@atrim/instrumentation/effect: Effect tracing enabled (${serviceName})`);
|
|
544
|
-
logger.log("
|
|
545
|
-
logger.log(`
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
return f();
|
|
561
|
-
}
|
|
562
|
-
const spanContext = {
|
|
563
|
-
traceId: span.traceId,
|
|
564
|
-
spanId: span.spanId,
|
|
565
|
-
traceFlags: span.sampled ? TraceFlags.SAMPLED : TraceFlags.NONE
|
|
566
|
-
};
|
|
567
|
-
const otelSpan = trace.wrapSpanContext(spanContext);
|
|
568
|
-
return context.with(trace.setSpan(context.active(), otelSpan), f);
|
|
569
|
-
}
|
|
570
|
-
}).pipe(Layer.provide(FetchHttpClient.layer));
|
|
589
|
+
logger.log("Effect OpenTelemetry tracer (unified)");
|
|
590
|
+
logger.log(` Service: ${serviceName}`);
|
|
591
|
+
return EffectAttributeTracerLayer.pipe(
|
|
592
|
+
Layer.provide(
|
|
593
|
+
Resource.layer({
|
|
594
|
+
serviceName,
|
|
595
|
+
serviceVersion,
|
|
596
|
+
attributes: {
|
|
597
|
+
"platform.component": "effect",
|
|
598
|
+
[ATTR_TELEMETRY_SDK_LANGUAGE]: TELEMETRY_SDK_LANGUAGE_VALUE_NODEJS,
|
|
599
|
+
[ATTR_TELEMETRY_SDK_NAME]: SDK_NAME,
|
|
600
|
+
[ATTR_TELEMETRY_EXPORTER_MODE]: "unified"
|
|
601
|
+
}
|
|
602
|
+
})
|
|
603
|
+
)
|
|
604
|
+
);
|
|
571
605
|
}).pipe(Layer.unwrapEffect);
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
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.annotateCurrentSpan(attributes);
|
|
575
613
|
}
|
|
576
|
-
function annotateDataSize(
|
|
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.annotateCurrentSpan(attributes);
|
|
577
623
|
}
|
|
578
|
-
function annotateBatch(
|
|
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.annotateCurrentSpan(attributes);
|
|
579
637
|
}
|
|
580
|
-
function annotateLLM(
|
|
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.annotateCurrentSpan(attributes);
|
|
649
|
+
}
|
|
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.annotateCurrentSpan(attributes);
|
|
658
|
+
}
|
|
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.annotateCurrentSpan(attributes);
|
|
667
|
+
}
|
|
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.annotateCurrentSpan(attributes);
|
|
581
678
|
}
|
|
582
|
-
function
|
|
679
|
+
function annotatePriority(priority, reason) {
|
|
680
|
+
const attributes = {
|
|
681
|
+
"operation.priority": priority
|
|
682
|
+
};
|
|
683
|
+
if (reason) attributes["operation.priority.reason"] = reason;
|
|
684
|
+
return Effect.annotateCurrentSpan(attributes);
|
|
583
685
|
}
|
|
584
|
-
function
|
|
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.annotateCurrentSpan(attributes);
|
|
585
693
|
}
|
|
586
|
-
function
|
|
694
|
+
function extractEffectMetadata() {
|
|
695
|
+
return Effect.gen(function* () {
|
|
696
|
+
const metadata = {};
|
|
697
|
+
const currentFiber = Fiber.getCurrentFiber();
|
|
698
|
+
if (Option.isSome(currentFiber)) {
|
|
699
|
+
const fiber = currentFiber.value;
|
|
700
|
+
const fiberId = fiber.id();
|
|
701
|
+
metadata["effect.fiber.id"] = FiberId.threadName(fiberId);
|
|
702
|
+
const status = yield* Fiber.status(fiber);
|
|
703
|
+
if (status._tag) {
|
|
704
|
+
metadata["effect.fiber.status"] = status._tag;
|
|
705
|
+
}
|
|
706
|
+
}
|
|
707
|
+
const parentSpanResult = yield* Effect.currentSpan.pipe(
|
|
708
|
+
Effect.option
|
|
709
|
+
// Convert NoSuchElementException to Option
|
|
710
|
+
);
|
|
711
|
+
if (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
|
+
});
|
|
587
730
|
}
|
|
588
|
-
function
|
|
731
|
+
function autoEnrichSpan() {
|
|
732
|
+
return Effect.gen(function* () {
|
|
733
|
+
const metadata = yield* extractEffectMetadata();
|
|
734
|
+
yield* Effect.annotateCurrentSpan(metadata);
|
|
735
|
+
});
|
|
589
736
|
}
|
|
590
|
-
function
|
|
737
|
+
function withAutoEnrichedSpan(spanName, options) {
|
|
738
|
+
return (self) => {
|
|
739
|
+
return Effect.gen(function* () {
|
|
740
|
+
yield* autoEnrichSpan();
|
|
741
|
+
return yield* self;
|
|
742
|
+
}).pipe(Effect.withSpan(spanName, options));
|
|
743
|
+
};
|
|
591
744
|
}
|
|
592
745
|
var createLogicalParentLink = (parentSpan, useSpanLinks) => {
|
|
593
746
|
if (!useSpanLinks) {
|
|
@@ -714,6 +867,6 @@ var FiberSet = {
|
|
|
714
867
|
runWithSpan
|
|
715
868
|
};
|
|
716
869
|
|
|
717
|
-
export { EffectInstrumentationLive, FiberSet, annotateBatch, annotateCache, annotateDataSize, annotateError, annotateHttpRequest, annotateLLM, annotatePriority, annotateQuery, annotateSpawnedTasks, annotateUser, createEffectInstrumentation, runIsolated, runWithSpan };
|
|
870
|
+
export { EffectInstrumentationLive, FiberSet, annotateBatch, annotateCache, annotateDataSize, annotateError, annotateHttpRequest, annotateLLM, annotatePriority, annotateQuery, annotateSpawnedTasks, annotateUser, autoEnrichSpan, createEffectInstrumentation, extractEffectMetadata, runIsolated, runWithSpan, withAutoEnrichedSpan };
|
|
718
871
|
//# sourceMappingURL=index.js.map
|
|
719
872
|
//# sourceMappingURL=index.js.map
|