@xylabs/telemetry 4.9.13 → 4.9.14
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/dist/neutral/index.mjs +6 -6
- package/dist/neutral/index.mjs.map +1 -1
- package/dist/types/span.d.ts +1 -1
- package/dist/types/span.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/span.ts +10 -5
package/dist/neutral/index.mjs
CHANGED
|
@@ -1,8 +1,5 @@
|
|
|
1
1
|
// src/span.ts
|
|
2
|
-
import {
|
|
3
|
-
context,
|
|
4
|
-
trace
|
|
5
|
-
} from "@opentelemetry/api";
|
|
2
|
+
import { context, trace } from "@opentelemetry/api";
|
|
6
3
|
function span(name, fn, tracer) {
|
|
7
4
|
if (tracer) {
|
|
8
5
|
const span2 = tracer.startSpan(name);
|
|
@@ -17,10 +14,13 @@ function span(name, fn, tracer) {
|
|
|
17
14
|
return fn();
|
|
18
15
|
}
|
|
19
16
|
}
|
|
17
|
+
function clearContext(context2) {
|
|
18
|
+
return trace.getSpan(context2) ? clearContext(trace.deleteSpan(context2)) : context2;
|
|
19
|
+
}
|
|
20
20
|
function spanRoot(name, fn, tracer) {
|
|
21
21
|
if (tracer) {
|
|
22
22
|
const activeContext = context.active();
|
|
23
|
-
const noSpanContext =
|
|
23
|
+
const noSpanContext = clearContext(activeContext);
|
|
24
24
|
const span2 = tracer.startSpan(name, {}, noSpanContext);
|
|
25
25
|
return context.with(trace.setSpan(activeContext, span2), () => {
|
|
26
26
|
try {
|
|
@@ -50,7 +50,7 @@ async function spanAsync(name, fn, tracer) {
|
|
|
50
50
|
async function spanRootAsync(name, fn, tracer) {
|
|
51
51
|
if (tracer) {
|
|
52
52
|
const activeContext = context.active();
|
|
53
|
-
const noSpanContext =
|
|
53
|
+
const noSpanContext = clearContext(activeContext);
|
|
54
54
|
const span2 = tracer.startSpan(name, {}, noSpanContext);
|
|
55
55
|
return await context.with(trace.setSpan(activeContext, span2), async () => {
|
|
56
56
|
try {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/span.ts"],"sourcesContent":["import {\n
|
|
1
|
+
{"version":3,"sources":["../../src/span.ts"],"sourcesContent":["import type {\n Context,\n Tracer,\n} from '@opentelemetry/api'\nimport { context, trace } from '@opentelemetry/api'\n\nexport function span<T>(name: string, fn: () => T, tracer?: Tracer): T {\n if (tracer) {\n const span = tracer.startSpan(name)\n return context.with(trace.setSpan(context.active(), span), () => {\n try {\n return fn()\n } finally {\n span.end()\n }\n })\n } else {\n return fn()\n }\n}\n\nfunction clearContext(context: Context): Context {\n return trace.getSpan(context) ? clearContext(trace.deleteSpan(context)) : context\n}\n\nexport function spanRoot<T>(name: string, fn: () => T, tracer?: Tracer): T {\n if (tracer) {\n // Get current active context for configuration\n const activeContext = context.active()\n\n // Create a new context with no active span\n const noSpanContext = clearContext(activeContext)\n\n // Create a new span in the context without an active span\n const span = tracer.startSpan(name, {}, noSpanContext)\n\n // Use the active context but replace its span with our new root span\n return context.with(trace.setSpan(activeContext, span), () => {\n try {\n return fn()\n } finally {\n span.end()\n }\n })\n } else {\n return fn()\n }\n}\n\nexport async function spanAsync<T>(\n name: string,\n fn: () => Promise<T>,\n tracer?: Tracer,\n): Promise<T> {\n if (tracer) {\n const span = tracer.startSpan(name)\n return await context.with(trace.setSpan(context.active(), span), async () => {\n try {\n return await fn()\n } finally {\n span.end()\n }\n })\n } else {\n return await fn()\n }\n}\n\nexport async function spanRootAsync<T>(\n name: string,\n fn: () => Promise<T>,\n tracer?: Tracer,\n): Promise<T> {\n if (tracer) {\n // Get current active context for configuration\n const activeContext = context.active()\n\n // Create a new context with no active span\n const noSpanContext = clearContext(activeContext)\n\n // Create a new span in the context without an active span\n const span = tracer.startSpan(name, {}, noSpanContext)\n\n // Use the active context but replace its span with our new root span\n return await context.with(trace.setSpan(activeContext, span), async () => {\n try {\n return await fn()\n } finally {\n span.end()\n }\n })\n } else {\n return await fn()\n }\n}\n"],"mappings":";AAI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Q;AAEV,UAAM,gBAAgB,QAAQ,OAAO;AAGrC,UAAM,gBAAgB,aAAa,aAAa;AAGhD,UAAMA,QAAO,OAAO,UAAU,MAAM,CAAC,GAAG,aAAa;AAGrD,WAAO,MAAM,QAAQ,KAAK,MAAM,QAAQ,eAAeA,KAAI,GAAG,YAAY;AACxE,UAAI;AACF,eAAO,MAAM,GAAG;AAAA,MAClB,UAAE;AACA,QAAAA,MAAK,IAAI;AAAA,MACX;AAAA,IACF,CAAC;AAAA,EACH,OAAO;AACL,WAAO,MAAM,GAAG;AAAA,EAClB;AACF;","names":["span","context"]}
|
package/dist/types/span.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import type { Tracer } from '@opentelemetry/api';
|
|
2
2
|
export declare function span<T>(name: string, fn: () => T, tracer?: Tracer): T;
|
|
3
3
|
export declare function spanRoot<T>(name: string, fn: () => T, tracer?: Tracer): T;
|
|
4
4
|
export declare function spanAsync<T>(name: string, fn: () => Promise<T>, tracer?: Tracer): Promise<T>;
|
package/dist/types/span.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"span.d.ts","sourceRoot":"","sources":["../../src/span.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"span.d.ts","sourceRoot":"","sources":["../../src/span.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAEV,MAAM,EACP,MAAM,oBAAoB,CAAA;AAG3B,wBAAgB,IAAI,CAAC,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,CAAC,EAAE,MAAM,CAAC,EAAE,MAAM,GAAG,CAAC,CAarE;AAMD,wBAAgB,QAAQ,CAAC,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,CAAC,EAAE,MAAM,CAAC,EAAE,MAAM,GAAG,CAAC,CAsBzE;AAED,wBAAsB,SAAS,CAAC,CAAC,EAC/B,IAAI,EAAE,MAAM,EACZ,EAAE,EAAE,MAAM,OAAO,CAAC,CAAC,CAAC,EACpB,MAAM,CAAC,EAAE,MAAM,GACd,OAAO,CAAC,CAAC,CAAC,CAaZ;AAED,wBAAsB,aAAa,CAAC,CAAC,EACnC,IAAI,EAAE,MAAM,EACZ,EAAE,EAAE,MAAM,OAAO,CAAC,CAAC,CAAC,EACpB,MAAM,CAAC,EAAE,MAAM,GACd,OAAO,CAAC,CAAC,CAAC,CAsBZ"}
|
package/package.json
CHANGED
package/src/span.ts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
import type {
|
|
2
|
+
Context,
|
|
3
|
+
Tracer,
|
|
4
4
|
} from '@opentelemetry/api'
|
|
5
|
+
import { context, trace } from '@opentelemetry/api'
|
|
5
6
|
|
|
6
7
|
export function span<T>(name: string, fn: () => T, tracer?: Tracer): T {
|
|
7
8
|
if (tracer) {
|
|
@@ -18,13 +19,17 @@ export function span<T>(name: string, fn: () => T, tracer?: Tracer): T {
|
|
|
18
19
|
}
|
|
19
20
|
}
|
|
20
21
|
|
|
22
|
+
function clearContext(context: Context): Context {
|
|
23
|
+
return trace.getSpan(context) ? clearContext(trace.deleteSpan(context)) : context
|
|
24
|
+
}
|
|
25
|
+
|
|
21
26
|
export function spanRoot<T>(name: string, fn: () => T, tracer?: Tracer): T {
|
|
22
27
|
if (tracer) {
|
|
23
28
|
// Get current active context for configuration
|
|
24
29
|
const activeContext = context.active()
|
|
25
30
|
|
|
26
31
|
// Create a new context with no active span
|
|
27
|
-
const noSpanContext =
|
|
32
|
+
const noSpanContext = clearContext(activeContext)
|
|
28
33
|
|
|
29
34
|
// Create a new span in the context without an active span
|
|
30
35
|
const span = tracer.startSpan(name, {}, noSpanContext)
|
|
@@ -71,7 +76,7 @@ export async function spanRootAsync<T>(
|
|
|
71
76
|
const activeContext = context.active()
|
|
72
77
|
|
|
73
78
|
// Create a new context with no active span
|
|
74
|
-
const noSpanContext =
|
|
79
|
+
const noSpanContext = clearContext(activeContext)
|
|
75
80
|
|
|
76
81
|
// Create a new span in the context without an active span
|
|
77
82
|
const span = tracer.startSpan(name, {}, noSpanContext)
|