@atrim/instrument-node 0.4.1 → 0.5.0-14fdea7-20260108232035

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.
@@ -1,706 +0,0 @@
1
- import { Data, Context, Effect, Layer, FiberSet as FiberSet$1, Tracer } from 'effect';
2
- import * as Otlp from '@effect/opentelemetry/Otlp';
3
- import { FetchHttpClient } from '@effect/platform';
4
- import { TraceFlags, trace, context } from '@opentelemetry/api';
5
- import { FileSystem } from '@effect/platform/FileSystem';
6
- import * as HttpClient from '@effect/platform/HttpClient';
7
- import * as HttpClientRequest from '@effect/platform/HttpClientRequest';
8
- import { parse } from 'yaml';
9
- import { z } from 'zod';
10
- import { NodeContext } from '@effect/platform-node';
11
-
12
- // src/integrations/effect/effect-tracer.ts
13
- var __defProp = Object.defineProperty;
14
- var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
15
- var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
16
- var PatternConfigSchema = z.object({
17
- pattern: z.string(),
18
- enabled: z.boolean().optional(),
19
- description: z.string().optional()
20
- });
21
- var AutoIsolationConfigSchema = z.object({
22
- // Global enable/disable for auto-isolation
23
- enabled: z.boolean().default(false),
24
- // Which operators to auto-isolate
25
- operators: z.object({
26
- fiberset_run: z.boolean().default(true),
27
- effect_fork: z.boolean().default(true),
28
- effect_fork_daemon: z.boolean().default(true),
29
- effect_fork_in: z.boolean().default(false)
30
- }).default({}),
31
- // Virtual parent tracking configuration
32
- tracking: z.object({
33
- use_span_links: z.boolean().default(true),
34
- use_attributes: z.boolean().default(true),
35
- capture_logical_parent: z.boolean().default(true)
36
- }).default({}),
37
- // Span categorization
38
- attributes: z.object({
39
- category: z.string().default("background_task"),
40
- add_metadata: z.boolean().default(true)
41
- }).default({})
42
- });
43
- var HttpFilteringConfigSchema = z.object({
44
- // Patterns to ignore for outgoing HTTP requests (string patterns only in YAML)
45
- ignore_outgoing_urls: z.array(z.string()).optional(),
46
- // Patterns to ignore for incoming HTTP requests (string patterns only in YAML)
47
- ignore_incoming_paths: z.array(z.string()).optional(),
48
- // Require parent span for outgoing requests (prevents root spans for HTTP calls)
49
- require_parent_for_outgoing_spans: z.boolean().optional()
50
- });
51
- var InstrumentationConfigSchema = z.object({
52
- version: z.string(),
53
- instrumentation: z.object({
54
- enabled: z.boolean(),
55
- description: z.string().optional(),
56
- logging: z.enum(["on", "off", "minimal"]).optional().default("on"),
57
- instrument_patterns: z.array(PatternConfigSchema),
58
- ignore_patterns: z.array(PatternConfigSchema)
59
- }),
60
- effect: z.object({
61
- auto_extract_metadata: z.boolean(),
62
- auto_isolation: AutoIsolationConfigSchema.optional()
63
- }).optional(),
64
- http: HttpFilteringConfigSchema.optional()
65
- });
66
- (class extends Data.TaggedError("ConfigError") {
67
- get message() {
68
- return this.reason;
69
- }
70
- });
71
- var ConfigUrlError = class extends Data.TaggedError("ConfigUrlError") {
72
- get message() {
73
- return this.reason;
74
- }
75
- };
76
- var ConfigValidationError = class extends Data.TaggedError("ConfigValidationError") {
77
- get message() {
78
- return this.reason;
79
- }
80
- };
81
- var ConfigFileError = class extends Data.TaggedError("ConfigFileError") {
82
- get message() {
83
- return this.reason;
84
- }
85
- };
86
- (class extends Data.TaggedError("ServiceDetectionError") {
87
- get message() {
88
- return this.reason;
89
- }
90
- });
91
- (class extends Data.TaggedError("InitializationError") {
92
- get message() {
93
- return this.reason;
94
- }
95
- });
96
- (class extends Data.TaggedError("ExportError") {
97
- get message() {
98
- return this.reason;
99
- }
100
- });
101
- (class extends Data.TaggedError("ShutdownError") {
102
- get message() {
103
- return this.reason;
104
- }
105
- });
106
- var SECURITY_DEFAULTS = {
107
- maxConfigSize: 1e6,
108
- // 1MB
109
- requestTimeout: 5e3
110
- // 5 seconds
111
- };
112
- var ConfigLoader = class extends Context.Tag("ConfigLoader")() {
113
- };
114
- var parseYamlContent = (content, uri) => Effect.gen(function* () {
115
- const parsed = yield* Effect.try({
116
- try: () => parse(content),
117
- catch: (error) => new ConfigValidationError({
118
- reason: uri ? `Failed to parse YAML from ${uri}` : "Failed to parse YAML",
119
- cause: error
120
- })
121
- });
122
- return yield* Effect.try({
123
- try: () => InstrumentationConfigSchema.parse(parsed),
124
- catch: (error) => new ConfigValidationError({
125
- reason: uri ? `Invalid configuration schema from ${uri}` : "Invalid configuration schema",
126
- cause: error
127
- })
128
- });
129
- });
130
- var loadFromFileWithFs = (fs, path, uri) => Effect.gen(function* () {
131
- const content = yield* fs.readFileString(path).pipe(
132
- Effect.mapError(
133
- (error) => new ConfigFileError({
134
- reason: `Failed to read config file at ${uri}`,
135
- cause: error
136
- })
137
- )
138
- );
139
- if (content.length > SECURITY_DEFAULTS.maxConfigSize) {
140
- return yield* Effect.fail(
141
- new ConfigFileError({
142
- reason: `Config file exceeds maximum size of ${SECURITY_DEFAULTS.maxConfigSize} bytes`
143
- })
144
- );
145
- }
146
- return yield* parseYamlContent(content, uri);
147
- });
148
- var loadFromHttpWithClient = (client, url) => Effect.scoped(
149
- Effect.gen(function* () {
150
- if (url.startsWith("http://")) {
151
- return yield* Effect.fail(
152
- new ConfigUrlError({
153
- reason: "Insecure protocol: only HTTPS URLs are allowed"
154
- })
155
- );
156
- }
157
- const request = HttpClientRequest.get(url).pipe(
158
- HttpClientRequest.setHeaders({
159
- Accept: "application/yaml, text/yaml, application/x-yaml"
160
- })
161
- );
162
- const response = yield* client.execute(request).pipe(
163
- Effect.timeout(`${SECURITY_DEFAULTS.requestTimeout} millis`),
164
- Effect.mapError((error) => {
165
- if (error._tag === "TimeoutException") {
166
- return new ConfigUrlError({
167
- reason: `Config fetch timeout after ${SECURITY_DEFAULTS.requestTimeout}ms from ${url}`
168
- });
169
- }
170
- return new ConfigUrlError({
171
- reason: `Failed to load config from URL: ${url}`,
172
- cause: error
173
- });
174
- })
175
- );
176
- if (response.status >= 400) {
177
- return yield* Effect.fail(
178
- new ConfigUrlError({
179
- reason: `HTTP ${response.status} from ${url}`
180
- })
181
- );
182
- }
183
- const text = yield* response.text.pipe(
184
- Effect.mapError(
185
- (error) => new ConfigUrlError({
186
- reason: `Failed to read response body from ${url}`,
187
- cause: error
188
- })
189
- )
190
- );
191
- if (text.length > SECURITY_DEFAULTS.maxConfigSize) {
192
- return yield* Effect.fail(
193
- new ConfigUrlError({
194
- reason: `Config exceeds maximum size of ${SECURITY_DEFAULTS.maxConfigSize} bytes`
195
- })
196
- );
197
- }
198
- return yield* parseYamlContent(text, url);
199
- })
200
- );
201
- var makeConfigLoader = Effect.gen(function* () {
202
- const fs = yield* Effect.serviceOption(FileSystem);
203
- const http = yield* HttpClient.HttpClient;
204
- const loadFromUriUncached = (uri) => Effect.gen(function* () {
205
- if (uri.startsWith("file://")) {
206
- const path = uri.slice(7);
207
- if (fs._tag === "None") {
208
- return yield* Effect.fail(
209
- new ConfigFileError({
210
- reason: "FileSystem not available (browser environment?)",
211
- cause: { uri }
212
- })
213
- );
214
- }
215
- return yield* loadFromFileWithFs(fs.value, path, uri);
216
- }
217
- if (uri.startsWith("http://") || uri.startsWith("https://")) {
218
- return yield* loadFromHttpWithClient(http, uri);
219
- }
220
- if (fs._tag === "Some") {
221
- return yield* loadFromFileWithFs(fs.value, uri, uri);
222
- } else {
223
- return yield* loadFromHttpWithClient(http, uri);
224
- }
225
- });
226
- const loadFromUriCached = yield* Effect.cachedFunction(loadFromUriUncached);
227
- return ConfigLoader.of({
228
- loadFromUri: loadFromUriCached,
229
- loadFromInline: (content) => Effect.gen(function* () {
230
- if (typeof content === "string") {
231
- return yield* parseYamlContent(content);
232
- }
233
- return yield* Effect.try({
234
- try: () => InstrumentationConfigSchema.parse(content),
235
- catch: (error) => new ConfigValidationError({
236
- reason: "Invalid configuration schema",
237
- cause: error
238
- })
239
- });
240
- })
241
- });
242
- });
243
- var ConfigLoaderLive = Layer.effect(ConfigLoader, makeConfigLoader);
244
- var PatternMatcher = class {
245
- constructor(config) {
246
- __publicField(this, "ignorePatterns", []);
247
- __publicField(this, "instrumentPatterns", []);
248
- __publicField(this, "enabled", true);
249
- this.enabled = config.instrumentation.enabled;
250
- this.ignorePatterns = config.instrumentation.ignore_patterns.map((p) => this.compilePattern(p));
251
- this.instrumentPatterns = config.instrumentation.instrument_patterns.filter((p) => p.enabled !== false).map((p) => this.compilePattern(p));
252
- }
253
- /**
254
- * Compile a pattern configuration into a RegExp
255
- */
256
- compilePattern(pattern) {
257
- try {
258
- const compiled = {
259
- regex: new RegExp(pattern.pattern),
260
- enabled: pattern.enabled !== false
261
- };
262
- if (pattern.description !== void 0) {
263
- compiled.description = pattern.description;
264
- }
265
- return compiled;
266
- } catch (error) {
267
- throw new Error(
268
- `Failed to compile pattern "${pattern.pattern}": ${error instanceof Error ? error.message : String(error)}`
269
- );
270
- }
271
- }
272
- /**
273
- * Check if a span should be instrumented
274
- *
275
- * Returns true if the span should be created, false otherwise.
276
- *
277
- * Logic:
278
- * 1. If instrumentation disabled globally, return false
279
- * 2. Check ignore patterns - if any match, return false
280
- * 3. Check instrument patterns - if any match, return true
281
- * 4. Default: return true (fail-open - create span if no patterns match)
282
- */
283
- shouldInstrument(spanName) {
284
- if (!this.enabled) {
285
- return false;
286
- }
287
- for (const pattern of this.ignorePatterns) {
288
- if (pattern.regex.test(spanName)) {
289
- return false;
290
- }
291
- }
292
- for (const pattern of this.instrumentPatterns) {
293
- if (pattern.enabled && pattern.regex.test(spanName)) {
294
- return true;
295
- }
296
- }
297
- return true;
298
- }
299
- /**
300
- * Get statistics about pattern matching (for debugging/monitoring)
301
- */
302
- getStats() {
303
- return {
304
- enabled: this.enabled,
305
- ignorePatternCount: this.ignorePatterns.length,
306
- instrumentPatternCount: this.instrumentPatterns.filter((p) => p.enabled).length
307
- };
308
- }
309
- };
310
- function initializePatternMatcher(config) {
311
- new PatternMatcher(config);
312
- }
313
- var Logger = class {
314
- constructor() {
315
- __publicField(this, "level", "on");
316
- __publicField(this, "hasLoggedMinimal", false);
317
- }
318
- /**
319
- * Set the logging level
320
- */
321
- setLevel(level) {
322
- this.level = level;
323
- this.hasLoggedMinimal = false;
324
- }
325
- /**
326
- * Get the current logging level
327
- */
328
- getLevel() {
329
- return this.level;
330
- }
331
- /**
332
- * Log a minimal initialization message (only shown once in minimal mode)
333
- */
334
- minimal(message) {
335
- if (this.level === "off") {
336
- return;
337
- }
338
- if (this.level === "minimal" && !this.hasLoggedMinimal) {
339
- console.log(message);
340
- this.hasLoggedMinimal = true;
341
- return;
342
- }
343
- if (this.level === "on") {
344
- console.log(message);
345
- }
346
- }
347
- /**
348
- * Log an informational message
349
- */
350
- log(...args) {
351
- if (this.level === "on") {
352
- console.log(...args);
353
- }
354
- }
355
- /**
356
- * Log a warning message (shown in minimal mode)
357
- */
358
- warn(...args) {
359
- if (this.level !== "off") {
360
- console.warn(...args);
361
- }
362
- }
363
- /**
364
- * Log an error message (shown in minimal mode)
365
- */
366
- error(...args) {
367
- if (this.level !== "off") {
368
- console.error(...args);
369
- }
370
- }
371
- /**
372
- * Check if full logging is enabled
373
- */
374
- isEnabled() {
375
- return this.level === "on";
376
- }
377
- /**
378
- * Check if minimal logging is enabled
379
- */
380
- isMinimal() {
381
- return this.level === "minimal";
382
- }
383
- /**
384
- * Check if logging is completely disabled
385
- */
386
- isDisabled() {
387
- return this.level === "off";
388
- }
389
- };
390
- var logger = new Logger();
391
- var NodeConfigLoaderLive = ConfigLoaderLive.pipe(
392
- Layer.provide(Layer.mergeAll(NodeContext.layer, FetchHttpClient.layer))
393
- );
394
- var cachedLoaderPromise = null;
395
- function getCachedLoader() {
396
- if (!cachedLoaderPromise) {
397
- cachedLoaderPromise = Effect.runPromise(
398
- Effect.gen(function* () {
399
- return yield* ConfigLoader;
400
- }).pipe(Effect.provide(NodeConfigLoaderLive))
401
- );
402
- }
403
- return cachedLoaderPromise;
404
- }
405
- async function loadConfig(uri, options) {
406
- if (options?.cacheTimeout === 0) {
407
- const program = Effect.gen(function* () {
408
- const loader2 = yield* ConfigLoader;
409
- return yield* loader2.loadFromUri(uri);
410
- });
411
- return Effect.runPromise(program.pipe(Effect.provide(NodeConfigLoaderLive)));
412
- }
413
- const loader = await getCachedLoader();
414
- return Effect.runPromise(loader.loadFromUri(uri));
415
- }
416
- async function loadConfigFromInline(content) {
417
- const loader = await getCachedLoader();
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
- };
442
- }
443
- async function loadConfigWithOptions(options = {}) {
444
- const loadOptions = options.cacheTimeout !== void 0 ? { cacheTimeout: options.cacheTimeout } : void 0;
445
- if (options.config) {
446
- return loadConfigFromInline(options.config);
447
- }
448
- const envConfigPath = process.env.ATRIM_INSTRUMENTATION_CONFIG;
449
- if (envConfigPath) {
450
- return loadConfig(envConfigPath, loadOptions);
451
- }
452
- if (options.configUrl) {
453
- return loadConfig(options.configUrl, loadOptions);
454
- }
455
- if (options.configPath) {
456
- return loadConfig(options.configPath, loadOptions);
457
- }
458
- const { existsSync } = await import('fs');
459
- const { join } = await import('path');
460
- const defaultPath = join(process.cwd(), "instrumentation.yaml");
461
- if (existsSync(defaultPath)) {
462
- return loadConfig(defaultPath, loadOptions);
463
- }
464
- return getDefaultConfig();
465
- }
466
-
467
- // src/integrations/effect/effect-tracer.ts
468
- function createEffectInstrumentation(options = {}) {
469
- return Layer.unwrapEffect(
470
- Effect.gen(function* () {
471
- const config = yield* Effect.tryPromise({
472
- try: () => loadConfigWithOptions(options),
473
- catch: (error) => ({
474
- _tag: "ConfigError",
475
- message: error instanceof Error ? error.message : String(error)
476
- })
477
- });
478
- yield* Effect.sync(() => {
479
- const loggingLevel = config.instrumentation.logging || "on";
480
- logger.setLevel(loggingLevel);
481
- });
482
- yield* Effect.sync(() => initializePatternMatcher(config));
483
- const otlpEndpoint = options.otlpEndpoint || process.env.OTEL_EXPORTER_OTLP_ENDPOINT || "http://localhost:4318";
484
- const serviceName = options.serviceName || process.env.OTEL_SERVICE_NAME || "effect-service";
485
- const serviceVersion = options.serviceVersion || process.env.npm_package_version || "1.0.0";
486
- const autoExtractMetadata = options.autoExtractMetadata ?? config.effect?.auto_extract_metadata ?? true;
487
- const continueExistingTraces = options.continueExistingTraces ?? true;
488
- logger.log("\u{1F50D} Effect OpenTelemetry instrumentation");
489
- logger.log(` \u{1F4E1} Endpoint: ${otlpEndpoint}`);
490
- logger.log(` \u{1F3F7}\uFE0F Service: ${serviceName}`);
491
- logger.log(` \u2705 Auto metadata extraction: ${autoExtractMetadata}`);
492
- logger.log(` \u2705 Continue existing traces: ${continueExistingTraces}`);
493
- const otlpLayer = Otlp.layer({
494
- baseUrl: otlpEndpoint,
495
- resource: {
496
- serviceName,
497
- serviceVersion,
498
- attributes: {
499
- "platform.component": "effect",
500
- "effect.auto_metadata": autoExtractMetadata,
501
- "effect.context_propagation": continueExistingTraces
502
- }
503
- },
504
- // Bridge Effect context to OpenTelemetry global context
505
- // This is essential for context propagation to work properly
506
- tracerContext: (f, span) => {
507
- if (span._tag !== "Span") {
508
- return f();
509
- }
510
- const spanContext = {
511
- traceId: span.traceId,
512
- spanId: span.spanId,
513
- traceFlags: span.sampled ? TraceFlags.SAMPLED : TraceFlags.NONE
514
- };
515
- const otelSpan = trace.wrapSpanContext(spanContext);
516
- return context.with(trace.setSpan(context.active(), otelSpan), f);
517
- }
518
- }).pipe(Layer.provide(FetchHttpClient.layer));
519
- if (autoExtractMetadata) {
520
- return otlpLayer;
521
- }
522
- return otlpLayer;
523
- })
524
- ).pipe(Layer.orDie);
525
- }
526
- var EffectInstrumentationLive = Effect.sync(() => {
527
- const endpoint = process.env.OTEL_EXPORTER_OTLP_ENDPOINT || "http://localhost:4318";
528
- const serviceName = process.env.OTEL_SERVICE_NAME || "effect-service";
529
- const serviceVersion = process.env.npm_package_version || "1.0.0";
530
- logger.minimal(`@atrim/instrumentation/effect: Effect tracing enabled (${serviceName})`);
531
- logger.log("\u{1F50D} Effect OpenTelemetry tracer");
532
- logger.log(` \u{1F4E1} Endpoint: ${endpoint}`);
533
- logger.log(` \u{1F3F7}\uFE0F Service: ${serviceName}`);
534
- return Otlp.layer({
535
- baseUrl: endpoint,
536
- resource: {
537
- serviceName,
538
- serviceVersion,
539
- attributes: {
540
- "platform.component": "effect"
541
- }
542
- },
543
- // CRITICAL: Bridge Effect context to OpenTelemetry global context
544
- // This allows NodeSDK auto-instrumentation to see Effect spans as parent spans
545
- tracerContext: (f, span) => {
546
- if (span._tag !== "Span") {
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));
558
- }).pipe(Layer.unwrapEffect);
559
-
560
- // src/integrations/effect/effect-helpers.ts
561
- function annotateUser(_userId, _email) {
562
- }
563
- function annotateDataSize(_bytes, _count) {
564
- }
565
- function annotateBatch(_size, _batchSize) {
566
- }
567
- function annotateLLM(_model, _operation, _inputTokens, _outputTokens) {
568
- }
569
- function annotateQuery(_query, _database) {
570
- }
571
- function annotateHttpRequest(_method, _url, _statusCode) {
572
- }
573
- function annotateError(_error, _context) {
574
- }
575
- function annotatePriority(_priority) {
576
- }
577
- function annotateCache(_operation, _hit) {
578
- }
579
- var createLogicalParentLink = (parentSpan, useSpanLinks) => {
580
- if (!useSpanLinks) {
581
- return [];
582
- }
583
- return [
584
- {
585
- _tag: "SpanLink",
586
- span: parentSpan,
587
- attributes: {
588
- "link.type": "logical_parent",
589
- "atrim.relationship": "spawned_by",
590
- description: "Logical parent (isolated to prevent context leakage)"
591
- }
592
- }
593
- ];
594
- };
595
- var createLogicalParentAttributes = (parentSpan, useAttributes, category, useSpanLinks, customAttributes) => {
596
- if (!useAttributes) {
597
- return customAttributes;
598
- }
599
- return {
600
- // Logical parent tracking (works in ALL tools)
601
- "atrim.logical_parent.span_id": parentSpan.spanId,
602
- "atrim.logical_parent.trace_id": parentSpan.traceId,
603
- "atrim.logical_parent.name": parentSpan._tag === "Span" ? parentSpan.name : "external",
604
- // Categorization and metadata
605
- "atrim.fiberset.isolated": true,
606
- "atrim.span.category": category,
607
- "atrim.has_logical_parent": true,
608
- "atrim.isolation.method": useSpanLinks ? "hybrid" : "attributes_only",
609
- // User-provided attributes
610
- ...customAttributes
611
- };
612
- };
613
- var runIsolated = (set, effect, name, options) => {
614
- const {
615
- createRoot = true,
616
- captureLogicalParent = true,
617
- useSpanLinks = true,
618
- useAttributes = true,
619
- propagateInterruption,
620
- attributes = {},
621
- category = "background_task"
622
- } = options ?? {};
623
- if (!createRoot && !captureLogicalParent) {
624
- return FiberSet$1.run(set, effect, { propagateInterruption });
625
- }
626
- return Effect.gen(function* () {
627
- const maybeParent = yield* Effect.serviceOption(Tracer.ParentSpan);
628
- if (maybeParent._tag === "None" || !captureLogicalParent) {
629
- const isolated2 = effect.pipe(
630
- Effect.withSpan(name, {
631
- root: createRoot,
632
- attributes: {
633
- "atrim.fiberset.isolated": createRoot,
634
- "atrim.span.category": category,
635
- "atrim.has_logical_parent": false,
636
- ...attributes
637
- }
638
- })
639
- );
640
- return yield* FiberSet$1.run(set, isolated2, { propagateInterruption });
641
- }
642
- const parent = maybeParent.value;
643
- const links = createLogicalParentLink(parent, useSpanLinks);
644
- const spanAttributes = createLogicalParentAttributes(
645
- parent,
646
- useAttributes,
647
- category,
648
- useSpanLinks,
649
- attributes
650
- );
651
- const isolated = effect.pipe(
652
- Effect.withSpan(name, {
653
- root: createRoot,
654
- links: links.length > 0 ? links : void 0,
655
- attributes: spanAttributes
656
- })
657
- );
658
- return yield* FiberSet$1.run(set, isolated, { propagateInterruption });
659
- });
660
- };
661
- var runWithSpan = (set, name, effect, options) => {
662
- return runIsolated(set, effect, name, {
663
- createRoot: true,
664
- captureLogicalParent: true,
665
- useSpanLinks: true,
666
- useAttributes: true,
667
- ...options
668
- });
669
- };
670
- var annotateSpawnedTasks = (tasks) => {
671
- return Effect.annotateCurrentSpan({
672
- "atrim.fiberset.spawned_count": tasks.length,
673
- "atrim.fiberset.task_names": tasks.map((t) => t.name).join(","),
674
- "atrim.has_background_tasks": true,
675
- "atrim.spawned_tasks": JSON.stringify(
676
- tasks.map((t) => ({
677
- name: t.name,
678
- ...t.spanId && { span_id: t.spanId },
679
- ...t.category && { category: t.category }
680
- }))
681
- )
682
- });
683
- };
684
- var FiberSet = {
685
- // Re-export all original FiberSet functions
686
- make: FiberSet$1.make,
687
- add: FiberSet$1.add,
688
- unsafeAdd: FiberSet$1.unsafeAdd,
689
- run: FiberSet$1.run,
690
- clear: FiberSet$1.clear,
691
- join: FiberSet$1.join,
692
- awaitEmpty: FiberSet$1.awaitEmpty,
693
- size: FiberSet$1.size,
694
- runtime: FiberSet$1.runtime,
695
- runtimePromise: FiberSet$1.runtimePromise,
696
- makeRuntime: FiberSet$1.makeRuntime,
697
- makeRuntimePromise: FiberSet$1.makeRuntimePromise,
698
- isFiberSet: FiberSet$1.isFiberSet,
699
- // Add our isolation helpers
700
- runIsolated,
701
- runWithSpan
702
- };
703
-
704
- export { EffectInstrumentationLive, FiberSet, annotateBatch, annotateCache, annotateDataSize, annotateError, annotateHttpRequest, annotateLLM, annotatePriority, annotateQuery, annotateSpawnedTasks, annotateUser, createEffectInstrumentation, runIsolated, runWithSpan };
705
- //# sourceMappingURL=index.js.map
706
- //# sourceMappingURL=index.js.map