@atrim/instrument-node 0.5.0 → 0.5.1-3a86b84-20260105170223
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 +73 -274
- package/package.json +20 -19
- package/target/dist/index.cjs +149 -60
- package/target/dist/index.cjs.map +1 -1
- package/target/dist/index.d.cts +28 -13
- package/target/dist/index.d.ts +28 -13
- package/target/dist/index.js +148 -60
- package/target/dist/index.js.map +1 -1
- package/target/dist/integrations/effect/index.cjs +286 -130
- package/target/dist/integrations/effect/index.cjs.map +1 -1
- package/target/dist/integrations/effect/index.d.cts +206 -36
- package/target/dist/integrations/effect/index.d.ts +206 -36
- package/target/dist/integrations/effect/index.js +285 -134
- package/target/dist/integrations/effect/index.js.map +1 -1
|
@@ -1,13 +1,15 @@
|
|
|
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 as Tracer$1 } from 'effect';
|
|
2
|
+
import * as Tracer 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;
|
|
@@ -46,7 +48,20 @@ var HttpFilteringConfigSchema = z.object({
|
|
|
46
48
|
// Patterns to ignore for incoming HTTP requests (string patterns only in YAML)
|
|
47
49
|
ignore_incoming_paths: z.array(z.string()).optional(),
|
|
48
50
|
// Require parent span for outgoing requests (prevents root spans for HTTP calls)
|
|
49
|
-
require_parent_for_outgoing_spans: z.boolean().optional()
|
|
51
|
+
require_parent_for_outgoing_spans: z.boolean().optional(),
|
|
52
|
+
// Trace context propagation configuration
|
|
53
|
+
// Controls which cross-origin requests receive W3C Trace Context headers (traceparent, tracestate)
|
|
54
|
+
propagate_trace_context: z.object({
|
|
55
|
+
// Strategy for trace propagation
|
|
56
|
+
// - "all": Propagate to all cross-origin requests (may cause CORS errors)
|
|
57
|
+
// - "none": Never propagate trace headers
|
|
58
|
+
// - "same-origin": Only propagate to same-origin requests (default, safe)
|
|
59
|
+
// - "patterns": Propagate based on include_urls patterns
|
|
60
|
+
strategy: z.enum(["all", "none", "same-origin", "patterns"]).default("same-origin"),
|
|
61
|
+
// URL patterns to include when strategy is "patterns"
|
|
62
|
+
// Supports regex patterns (e.g., "^https://api\\.myapp\\.com")
|
|
63
|
+
include_urls: z.array(z.string()).optional()
|
|
64
|
+
}).optional()
|
|
50
65
|
});
|
|
51
66
|
var InstrumentationConfigSchema = z.object({
|
|
52
67
|
version: z.string(),
|
|
@@ -58,11 +73,50 @@ var InstrumentationConfigSchema = z.object({
|
|
|
58
73
|
ignore_patterns: z.array(PatternConfigSchema)
|
|
59
74
|
}),
|
|
60
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"),
|
|
61
83
|
auto_extract_metadata: z.boolean(),
|
|
62
84
|
auto_isolation: AutoIsolationConfigSchema.optional()
|
|
63
85
|
}).optional(),
|
|
64
86
|
http: HttpFilteringConfigSchema.optional()
|
|
65
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
|
+
}
|
|
66
120
|
(class extends Data.TaggedError("ConfigError") {
|
|
67
121
|
get message() {
|
|
68
122
|
return this.reason;
|
|
@@ -240,7 +294,7 @@ var makeConfigLoader = Effect.gen(function* () {
|
|
|
240
294
|
})
|
|
241
295
|
});
|
|
242
296
|
});
|
|
243
|
-
|
|
297
|
+
Layer.effect(ConfigLoader, makeConfigLoader);
|
|
244
298
|
var PatternMatcher = class {
|
|
245
299
|
constructor(config) {
|
|
246
300
|
__publicField(this, "ignorePatterns", []);
|
|
@@ -388,83 +442,58 @@ var Logger = class {
|
|
|
388
442
|
}
|
|
389
443
|
};
|
|
390
444
|
var logger = new Logger();
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
);
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
}).pipe(Effect.provide(NodeConfigLoaderLive))
|
|
401
|
-
);
|
|
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}`);
|
|
402
454
|
}
|
|
403
|
-
|
|
455
|
+
const content = await response.text();
|
|
456
|
+
return parseAndValidateConfig(content);
|
|
404
457
|
}
|
|
405
|
-
async function loadConfig(uri,
|
|
406
|
-
if (
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
return
|
|
412
|
-
}
|
|
413
|
-
|
|
414
|
-
return Effect.runPromise(loader.loadFromUri(uri));
|
|
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);
|
|
465
|
+
}
|
|
466
|
+
return loadFromFile(uri);
|
|
415
467
|
}
|
|
416
468
|
async function loadConfigFromInline(content) {
|
|
417
|
-
|
|
418
|
-
return Effect.runPromise(loader.loadFromInline(content));
|
|
419
|
-
}
|
|
420
|
-
function getDefaultConfig() {
|
|
421
|
-
return {
|
|
422
|
-
version: "1.0",
|
|
423
|
-
instrumentation: {
|
|
424
|
-
enabled: true,
|
|
425
|
-
logging: "on",
|
|
426
|
-
description: "Default instrumentation configuration",
|
|
427
|
-
instrument_patterns: [
|
|
428
|
-
{ pattern: "^app\\.", enabled: true, description: "Application operations" },
|
|
429
|
-
{ pattern: "^http\\.server\\.", enabled: true, description: "HTTP server operations" },
|
|
430
|
-
{ pattern: "^http\\.client\\.", enabled: true, description: "HTTP client operations" }
|
|
431
|
-
],
|
|
432
|
-
ignore_patterns: [
|
|
433
|
-
{ pattern: "^test\\.", description: "Test utilities" },
|
|
434
|
-
{ pattern: "^internal\\.", description: "Internal operations" },
|
|
435
|
-
{ pattern: "^health\\.", description: "Health checks" }
|
|
436
|
-
]
|
|
437
|
-
},
|
|
438
|
-
effect: {
|
|
439
|
-
auto_extract_metadata: true
|
|
440
|
-
}
|
|
441
|
-
};
|
|
469
|
+
return parseAndValidateConfig(content);
|
|
442
470
|
}
|
|
443
471
|
async function loadConfigWithOptions(options = {}) {
|
|
444
|
-
const loadOptions = options.cacheTimeout !== void 0 ? { cacheTimeout: options.cacheTimeout } : void 0;
|
|
445
472
|
if (options.config) {
|
|
446
473
|
return loadConfigFromInline(options.config);
|
|
447
474
|
}
|
|
448
475
|
const envConfigPath = process.env.ATRIM_INSTRUMENTATION_CONFIG;
|
|
449
476
|
if (envConfigPath) {
|
|
450
|
-
return loadConfig(envConfigPath
|
|
477
|
+
return loadConfig(envConfigPath);
|
|
451
478
|
}
|
|
452
479
|
if (options.configUrl) {
|
|
453
|
-
return loadConfig(options.configUrl
|
|
480
|
+
return loadConfig(options.configUrl);
|
|
454
481
|
}
|
|
455
482
|
if (options.configPath) {
|
|
456
|
-
return loadConfig(options.configPath
|
|
483
|
+
return loadConfig(options.configPath);
|
|
457
484
|
}
|
|
458
485
|
const { existsSync } = await import('fs');
|
|
459
486
|
const { join } = await import('path');
|
|
460
487
|
const defaultPath = join(process.cwd(), "instrumentation.yaml");
|
|
461
488
|
if (existsSync(defaultPath)) {
|
|
462
|
-
return loadConfig(defaultPath
|
|
489
|
+
return loadConfig(defaultPath);
|
|
463
490
|
}
|
|
464
|
-
return
|
|
491
|
+
return defaultConfig;
|
|
465
492
|
}
|
|
466
493
|
|
|
467
494
|
// src/integrations/effect/effect-tracer.ts
|
|
495
|
+
var SDK_NAME = "@effect/opentelemetry";
|
|
496
|
+
var ATTR_TELEMETRY_EXPORTER_MODE = "telemetry.exporter.mode";
|
|
468
497
|
function createEffectInstrumentation(options = {}) {
|
|
469
498
|
return Layer.unwrapEffect(
|
|
470
499
|
Effect.gen(function* () {
|
|
@@ -475,106 +504,228 @@ function createEffectInstrumentation(options = {}) {
|
|
|
475
504
|
message: error instanceof Error ? error.message : String(error)
|
|
476
505
|
})
|
|
477
506
|
});
|
|
507
|
+
const effectEnabled = process.env.OTEL_EFFECT_ENABLED !== "false" && (config.effect?.enabled ?? true);
|
|
508
|
+
if (!effectEnabled) {
|
|
509
|
+
logger.log("@atrim/instrumentation/effect: Effect tracing disabled via config");
|
|
510
|
+
return Layer.empty;
|
|
511
|
+
}
|
|
478
512
|
yield* Effect.sync(() => {
|
|
479
513
|
const loggingLevel = config.instrumentation.logging || "on";
|
|
480
514
|
logger.setLevel(loggingLevel);
|
|
481
515
|
});
|
|
482
516
|
yield* Effect.sync(() => initializePatternMatcher(config));
|
|
483
|
-
const otlpEndpoint = options.otlpEndpoint || process.env.OTEL_EXPORTER_OTLP_ENDPOINT || "http://localhost:4318";
|
|
484
517
|
const serviceName = options.serviceName || process.env.OTEL_SERVICE_NAME || "effect-service";
|
|
485
518
|
const serviceVersion = options.serviceVersion || process.env.npm_package_version || "1.0.0";
|
|
486
|
-
const
|
|
487
|
-
const
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
519
|
+
const exporterMode = options.exporterMode ?? config.effect?.exporter ?? "unified";
|
|
520
|
+
const resourceAttributes = {
|
|
521
|
+
"platform.component": "effect",
|
|
522
|
+
[ATTR_TELEMETRY_SDK_LANGUAGE]: TELEMETRY_SDK_LANGUAGE_VALUE_NODEJS,
|
|
523
|
+
[ATTR_TELEMETRY_SDK_NAME]: SDK_NAME,
|
|
524
|
+
[ATTR_TELEMETRY_EXPORTER_MODE]: exporterMode
|
|
525
|
+
};
|
|
526
|
+
if (exporterMode === "standalone") {
|
|
527
|
+
const otlpEndpoint = options.otlpEndpoint || process.env.OTEL_EXPORTER_OTLP_ENDPOINT || "http://localhost:4318";
|
|
528
|
+
logger.log("Effect OpenTelemetry instrumentation (standalone)");
|
|
529
|
+
logger.log(` Service: ${serviceName}`);
|
|
530
|
+
logger.log(` Endpoint: ${otlpEndpoint}`);
|
|
531
|
+
logger.log(" WARNING: Standalone mode bypasses Node SDK filtering");
|
|
532
|
+
return Otlp.layer({
|
|
533
|
+
baseUrl: otlpEndpoint,
|
|
534
|
+
resource: {
|
|
535
|
+
serviceName,
|
|
536
|
+
serviceVersion,
|
|
537
|
+
attributes: resourceAttributes
|
|
538
|
+
},
|
|
539
|
+
// Bridge Effect context to OpenTelemetry global context
|
|
540
|
+
tracerContext: (f, span) => {
|
|
541
|
+
if (span._tag !== "Span") {
|
|
542
|
+
return f();
|
|
543
|
+
}
|
|
544
|
+
const spanContext = {
|
|
545
|
+
traceId: span.traceId,
|
|
546
|
+
spanId: span.spanId,
|
|
547
|
+
traceFlags: span.sampled ? TraceFlags.SAMPLED : TraceFlags.NONE
|
|
548
|
+
};
|
|
549
|
+
const otelSpan = trace.wrapSpanContext(spanContext);
|
|
550
|
+
return context.with(trace.setSpan(context.active(), otelSpan), f);
|
|
509
551
|
}
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
552
|
+
}).pipe(Layer.provide(FetchHttpClient.layer));
|
|
553
|
+
} else {
|
|
554
|
+
logger.log("Effect OpenTelemetry instrumentation (unified)");
|
|
555
|
+
logger.log(` Service: ${serviceName}`);
|
|
556
|
+
logger.log(" Using global TracerProvider for span export");
|
|
557
|
+
return Tracer.layerGlobal.pipe(
|
|
558
|
+
Layer.provide(
|
|
559
|
+
Resource.layer({
|
|
560
|
+
serviceName,
|
|
561
|
+
serviceVersion,
|
|
562
|
+
attributes: resourceAttributes
|
|
563
|
+
})
|
|
564
|
+
)
|
|
565
|
+
);
|
|
521
566
|
}
|
|
522
|
-
return otlpLayer;
|
|
523
567
|
})
|
|
524
568
|
).pipe(Layer.orDie);
|
|
525
569
|
}
|
|
526
570
|
var EffectInstrumentationLive = Effect.sync(() => {
|
|
527
|
-
const endpoint = process.env.OTEL_EXPORTER_OTLP_ENDPOINT || "http://localhost:4318";
|
|
528
571
|
const serviceName = process.env.OTEL_SERVICE_NAME || "effect-service";
|
|
529
572
|
const serviceVersion = process.env.npm_package_version || "1.0.0";
|
|
530
573
|
logger.minimal(`@atrim/instrumentation/effect: Effect tracing enabled (${serviceName})`);
|
|
531
|
-
logger.log("
|
|
532
|
-
logger.log(`
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
return f();
|
|
548
|
-
}
|
|
549
|
-
const spanContext = {
|
|
550
|
-
traceId: span.traceId,
|
|
551
|
-
spanId: span.spanId,
|
|
552
|
-
traceFlags: span.sampled ? TraceFlags.SAMPLED : TraceFlags.NONE
|
|
553
|
-
};
|
|
554
|
-
const otelSpan = trace.wrapSpanContext(spanContext);
|
|
555
|
-
return context.with(trace.setSpan(context.active(), otelSpan), f);
|
|
556
|
-
}
|
|
557
|
-
}).pipe(Layer.provide(FetchHttpClient.layer));
|
|
574
|
+
logger.log("Effect OpenTelemetry tracer (unified)");
|
|
575
|
+
logger.log(` Service: ${serviceName}`);
|
|
576
|
+
return Tracer.layerGlobal.pipe(
|
|
577
|
+
Layer.provide(
|
|
578
|
+
Resource.layer({
|
|
579
|
+
serviceName,
|
|
580
|
+
serviceVersion,
|
|
581
|
+
attributes: {
|
|
582
|
+
"platform.component": "effect",
|
|
583
|
+
[ATTR_TELEMETRY_SDK_LANGUAGE]: TELEMETRY_SDK_LANGUAGE_VALUE_NODEJS,
|
|
584
|
+
[ATTR_TELEMETRY_SDK_NAME]: SDK_NAME,
|
|
585
|
+
[ATTR_TELEMETRY_EXPORTER_MODE]: "unified"
|
|
586
|
+
}
|
|
587
|
+
})
|
|
588
|
+
)
|
|
589
|
+
);
|
|
558
590
|
}).pipe(Layer.unwrapEffect);
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
591
|
+
function annotateUser(userId, email, username) {
|
|
592
|
+
const attributes = {
|
|
593
|
+
"user.id": userId
|
|
594
|
+
};
|
|
595
|
+
if (email) attributes["user.email"] = email;
|
|
596
|
+
if (username) attributes["user.name"] = username;
|
|
597
|
+
return Effect.annotateCurrentSpan(attributes);
|
|
562
598
|
}
|
|
563
|
-
function annotateDataSize(
|
|
599
|
+
function annotateDataSize(bytes, items, compressionRatio) {
|
|
600
|
+
const attributes = {
|
|
601
|
+
"data.size.bytes": bytes,
|
|
602
|
+
"data.size.items": items
|
|
603
|
+
};
|
|
604
|
+
if (compressionRatio !== void 0) {
|
|
605
|
+
attributes["data.compression.ratio"] = compressionRatio;
|
|
606
|
+
}
|
|
607
|
+
return Effect.annotateCurrentSpan(attributes);
|
|
608
|
+
}
|
|
609
|
+
function annotateBatch(totalItems, batchSize, successCount, failureCount) {
|
|
610
|
+
const attributes = {
|
|
611
|
+
"batch.size": batchSize,
|
|
612
|
+
"batch.total_items": totalItems,
|
|
613
|
+
"batch.count": Math.ceil(totalItems / batchSize)
|
|
614
|
+
};
|
|
615
|
+
if (successCount !== void 0) {
|
|
616
|
+
attributes["batch.success_count"] = successCount;
|
|
617
|
+
}
|
|
618
|
+
if (failureCount !== void 0) {
|
|
619
|
+
attributes["batch.failure_count"] = failureCount;
|
|
620
|
+
}
|
|
621
|
+
return Effect.annotateCurrentSpan(attributes);
|
|
622
|
+
}
|
|
623
|
+
function annotateLLM(model, provider, tokens) {
|
|
624
|
+
const attributes = {
|
|
625
|
+
"llm.model": model,
|
|
626
|
+
"llm.provider": provider
|
|
627
|
+
};
|
|
628
|
+
if (tokens) {
|
|
629
|
+
if (tokens.prompt !== void 0) attributes["llm.tokens.prompt"] = tokens.prompt;
|
|
630
|
+
if (tokens.completion !== void 0) attributes["llm.tokens.completion"] = tokens.completion;
|
|
631
|
+
if (tokens.total !== void 0) attributes["llm.tokens.total"] = tokens.total;
|
|
632
|
+
}
|
|
633
|
+
return Effect.annotateCurrentSpan(attributes);
|
|
564
634
|
}
|
|
565
|
-
function
|
|
635
|
+
function annotateQuery(query, duration, rowCount, database) {
|
|
636
|
+
const attributes = {
|
|
637
|
+
"db.statement": query.length > 1e3 ? query.substring(0, 1e3) + "..." : query
|
|
638
|
+
};
|
|
639
|
+
if (duration !== void 0) attributes["db.duration.ms"] = duration;
|
|
640
|
+
if (rowCount !== void 0) attributes["db.row_count"] = rowCount;
|
|
641
|
+
if (database) attributes["db.name"] = database;
|
|
642
|
+
return Effect.annotateCurrentSpan(attributes);
|
|
566
643
|
}
|
|
567
|
-
function
|
|
644
|
+
function annotateHttpRequest(method, url, statusCode, contentLength) {
|
|
645
|
+
const attributes = {
|
|
646
|
+
"http.method": method,
|
|
647
|
+
"http.url": url
|
|
648
|
+
};
|
|
649
|
+
if (statusCode !== void 0) attributes["http.status_code"] = statusCode;
|
|
650
|
+
if (contentLength !== void 0) attributes["http.response.content_length"] = contentLength;
|
|
651
|
+
return Effect.annotateCurrentSpan(attributes);
|
|
568
652
|
}
|
|
569
|
-
function
|
|
653
|
+
function annotateError(error, recoverable, errorType) {
|
|
654
|
+
const errorMessage = typeof error === "string" ? error : error.message;
|
|
655
|
+
const errorStack = typeof error === "string" ? void 0 : error.stack;
|
|
656
|
+
const attributes = {
|
|
657
|
+
"error.message": errorMessage,
|
|
658
|
+
"error.recoverable": recoverable
|
|
659
|
+
};
|
|
660
|
+
if (errorType) attributes["error.type"] = errorType;
|
|
661
|
+
if (errorStack) attributes["error.stack"] = errorStack;
|
|
662
|
+
return Effect.annotateCurrentSpan(attributes);
|
|
663
|
+
}
|
|
664
|
+
function annotatePriority(priority, reason) {
|
|
665
|
+
const attributes = {
|
|
666
|
+
"operation.priority": priority
|
|
667
|
+
};
|
|
668
|
+
if (reason) attributes["operation.priority.reason"] = reason;
|
|
669
|
+
return Effect.annotateCurrentSpan(attributes);
|
|
570
670
|
}
|
|
571
|
-
function
|
|
671
|
+
function annotateCache(hit, key, ttl) {
|
|
672
|
+
const attributes = {
|
|
673
|
+
"cache.hit": hit,
|
|
674
|
+
"cache.key": key
|
|
675
|
+
};
|
|
676
|
+
if (ttl !== void 0) attributes["cache.ttl.seconds"] = ttl;
|
|
677
|
+
return Effect.annotateCurrentSpan(attributes);
|
|
572
678
|
}
|
|
573
|
-
function
|
|
679
|
+
function extractEffectMetadata() {
|
|
680
|
+
return Effect.gen(function* () {
|
|
681
|
+
const metadata = {};
|
|
682
|
+
const currentFiber = Fiber.getCurrentFiber();
|
|
683
|
+
if (Option.isSome(currentFiber)) {
|
|
684
|
+
const fiber = currentFiber.value;
|
|
685
|
+
const fiberId = fiber.id();
|
|
686
|
+
metadata["effect.fiber.id"] = FiberId.threadName(fiberId);
|
|
687
|
+
const status = yield* Fiber.status(fiber);
|
|
688
|
+
if (status._tag) {
|
|
689
|
+
metadata["effect.fiber.status"] = status._tag;
|
|
690
|
+
}
|
|
691
|
+
}
|
|
692
|
+
const parentSpanResult = yield* Effect.currentSpan.pipe(
|
|
693
|
+
Effect.option
|
|
694
|
+
// Convert NoSuchElementException to Option
|
|
695
|
+
);
|
|
696
|
+
if (Option.isSome(parentSpanResult)) {
|
|
697
|
+
const parentSpan = parentSpanResult.value;
|
|
698
|
+
metadata["effect.operation.nested"] = true;
|
|
699
|
+
metadata["effect.operation.root"] = false;
|
|
700
|
+
if (parentSpan.spanId) {
|
|
701
|
+
metadata["effect.parent.span.id"] = parentSpan.spanId;
|
|
702
|
+
}
|
|
703
|
+
if (parentSpan.name) {
|
|
704
|
+
metadata["effect.parent.span.name"] = parentSpan.name;
|
|
705
|
+
}
|
|
706
|
+
if (parentSpan.traceId) {
|
|
707
|
+
metadata["effect.parent.trace.id"] = parentSpan.traceId;
|
|
708
|
+
}
|
|
709
|
+
} else {
|
|
710
|
+
metadata["effect.operation.nested"] = false;
|
|
711
|
+
metadata["effect.operation.root"] = true;
|
|
712
|
+
}
|
|
713
|
+
return metadata;
|
|
714
|
+
});
|
|
574
715
|
}
|
|
575
|
-
function
|
|
716
|
+
function autoEnrichSpan() {
|
|
717
|
+
return Effect.gen(function* () {
|
|
718
|
+
const metadata = yield* extractEffectMetadata();
|
|
719
|
+
yield* Effect.annotateCurrentSpan(metadata);
|
|
720
|
+
});
|
|
576
721
|
}
|
|
577
|
-
function
|
|
722
|
+
function withAutoEnrichedSpan(spanName, options) {
|
|
723
|
+
return (self) => {
|
|
724
|
+
return Effect.gen(function* () {
|
|
725
|
+
yield* autoEnrichSpan();
|
|
726
|
+
return yield* self;
|
|
727
|
+
}).pipe(Effect.withSpan(spanName, options));
|
|
728
|
+
};
|
|
578
729
|
}
|
|
579
730
|
var createLogicalParentLink = (parentSpan, useSpanLinks) => {
|
|
580
731
|
if (!useSpanLinks) {
|
|
@@ -624,7 +775,7 @@ var runIsolated = (set, effect, name, options) => {
|
|
|
624
775
|
return FiberSet$1.run(set, effect, { propagateInterruption });
|
|
625
776
|
}
|
|
626
777
|
return Effect.gen(function* () {
|
|
627
|
-
const maybeParent = yield* Effect.serviceOption(Tracer.ParentSpan);
|
|
778
|
+
const maybeParent = yield* Effect.serviceOption(Tracer$1.ParentSpan);
|
|
628
779
|
if (maybeParent._tag === "None" || !captureLogicalParent) {
|
|
629
780
|
const isolated2 = effect.pipe(
|
|
630
781
|
Effect.withSpan(name, {
|
|
@@ -701,6 +852,6 @@ var FiberSet = {
|
|
|
701
852
|
runWithSpan
|
|
702
853
|
};
|
|
703
854
|
|
|
704
|
-
export { EffectInstrumentationLive, FiberSet, annotateBatch, annotateCache, annotateDataSize, annotateError, annotateHttpRequest, annotateLLM, annotatePriority, annotateQuery, annotateSpawnedTasks, annotateUser, createEffectInstrumentation, runIsolated, runWithSpan };
|
|
855
|
+
export { EffectInstrumentationLive, FiberSet, annotateBatch, annotateCache, annotateDataSize, annotateError, annotateHttpRequest, annotateLLM, annotatePriority, annotateQuery, annotateSpawnedTasks, annotateUser, autoEnrichSpan, createEffectInstrumentation, extractEffectMetadata, runIsolated, runWithSpan, withAutoEnrichedSpan };
|
|
705
856
|
//# sourceMappingURL=index.js.map
|
|
706
857
|
//# sourceMappingURL=index.js.map
|