@xylabs/telemetry 4.9.12 → 4.9.13
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 +8 -5
- package/dist/neutral/index.mjs.map +1 -1
- package/dist/types/span.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/span.ts +28 -6
package/dist/neutral/index.mjs
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
// src/span.ts
|
|
2
2
|
import {
|
|
3
3
|
context,
|
|
4
|
-
ROOT_CONTEXT,
|
|
5
4
|
trace
|
|
6
5
|
} from "@opentelemetry/api";
|
|
7
6
|
function span(name, fn, tracer) {
|
|
@@ -20,8 +19,10 @@ function span(name, fn, tracer) {
|
|
|
20
19
|
}
|
|
21
20
|
function spanRoot(name, fn, tracer) {
|
|
22
21
|
if (tracer) {
|
|
23
|
-
const
|
|
24
|
-
|
|
22
|
+
const activeContext = context.active();
|
|
23
|
+
const noSpanContext = trace.deleteSpan(activeContext);
|
|
24
|
+
const span2 = tracer.startSpan(name, {}, noSpanContext);
|
|
25
|
+
return context.with(trace.setSpan(activeContext, span2), () => {
|
|
25
26
|
try {
|
|
26
27
|
return fn();
|
|
27
28
|
} finally {
|
|
@@ -48,8 +49,10 @@ async function spanAsync(name, fn, tracer) {
|
|
|
48
49
|
}
|
|
49
50
|
async function spanRootAsync(name, fn, tracer) {
|
|
50
51
|
if (tracer) {
|
|
51
|
-
const
|
|
52
|
-
|
|
52
|
+
const activeContext = context.active();
|
|
53
|
+
const noSpanContext = trace.deleteSpan(activeContext);
|
|
54
|
+
const span2 = tracer.startSpan(name, {}, noSpanContext);
|
|
55
|
+
return await context.with(trace.setSpan(activeContext, span2), async () => {
|
|
53
56
|
try {
|
|
54
57
|
return await fn();
|
|
55
58
|
} finally {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/span.ts"],"sourcesContent":["import {\n context
|
|
1
|
+
{"version":3,"sources":["../../src/span.ts"],"sourcesContent":["import {\n context,\n trace, type Tracer,\n} 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\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 = trace.deleteSpan(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 = trace.deleteSpan(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":";AAAA;AAAA,EACE;AAAA,EACA;AAAA,OACK;AAEA,SAAS,KAAQ,MAAc,IAAa,QAAoB;AACrE,MAAI,QAAQ;AACV,UAAMA,QAAO,OAAO,UAAU,IAAI;AAClC,WAAO,QAAQ,KAAK,MAAM,QAAQ,QAAQ,OAAO,GAAGA,KA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;AAAA,MACX;AAAA,IACF,CAAC;AAAA,EACH,OAAO;AACL,WAAO,MAAM,GAAG;AAAA,EAClB;AACF;","names":["span"]}
|
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,EAEE,KAAK,MAAM,EACnB,MAAM,oBAAoB,CAAA;AAE3B,wBAAgB,IAAI,CAAC,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,CAAC,EAAE,MAAM,CAAC,EAAE,MAAM,GAAG,CAAC,CAarE;AAED,wBAAgB,QAAQ,CAAC,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,CAAC,EAAE,MAAM,CAAC,EAAE,MAAM,GAAG,CAAC,
|
|
1
|
+
{"version":3,"file":"span.d.ts","sourceRoot":"","sources":["../../src/span.ts"],"names":[],"mappings":"AAAA,OAAO,EAEE,KAAK,MAAM,EACnB,MAAM,oBAAoB,CAAA;AAE3B,wBAAgB,IAAI,CAAC,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,CAAC,EAAE,MAAM,CAAC,EAAE,MAAM,GAAG,CAAC,CAarE;AAED,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,5 +1,5 @@
|
|
|
1
1
|
import {
|
|
2
|
-
context,
|
|
2
|
+
context,
|
|
3
3
|
trace, type Tracer,
|
|
4
4
|
} from '@opentelemetry/api'
|
|
5
5
|
|
|
@@ -20,8 +20,17 @@ export function span<T>(name: string, fn: () => T, tracer?: Tracer): T {
|
|
|
20
20
|
|
|
21
21
|
export function spanRoot<T>(name: string, fn: () => T, tracer?: Tracer): T {
|
|
22
22
|
if (tracer) {
|
|
23
|
-
|
|
24
|
-
|
|
23
|
+
// Get current active context for configuration
|
|
24
|
+
const activeContext = context.active()
|
|
25
|
+
|
|
26
|
+
// Create a new context with no active span
|
|
27
|
+
const noSpanContext = trace.deleteSpan(activeContext)
|
|
28
|
+
|
|
29
|
+
// Create a new span in the context without an active span
|
|
30
|
+
const span = tracer.startSpan(name, {}, noSpanContext)
|
|
31
|
+
|
|
32
|
+
// Use the active context but replace its span with our new root span
|
|
33
|
+
return context.with(trace.setSpan(activeContext, span), () => {
|
|
25
34
|
try {
|
|
26
35
|
return fn()
|
|
27
36
|
} finally {
|
|
@@ -52,10 +61,23 @@ export async function spanAsync<T>(
|
|
|
52
61
|
}
|
|
53
62
|
}
|
|
54
63
|
|
|
55
|
-
export async function spanRootAsync<T>(
|
|
64
|
+
export async function spanRootAsync<T>(
|
|
65
|
+
name: string,
|
|
66
|
+
fn: () => Promise<T>,
|
|
67
|
+
tracer?: Tracer,
|
|
68
|
+
): Promise<T> {
|
|
56
69
|
if (tracer) {
|
|
57
|
-
|
|
58
|
-
|
|
70
|
+
// Get current active context for configuration
|
|
71
|
+
const activeContext = context.active()
|
|
72
|
+
|
|
73
|
+
// Create a new context with no active span
|
|
74
|
+
const noSpanContext = trace.deleteSpan(activeContext)
|
|
75
|
+
|
|
76
|
+
// Create a new span in the context without an active span
|
|
77
|
+
const span = tracer.startSpan(name, {}, noSpanContext)
|
|
78
|
+
|
|
79
|
+
// Use the active context but replace its span with our new root span
|
|
80
|
+
return await context.with(trace.setSpan(activeContext, span), async () => {
|
|
59
81
|
try {
|
|
60
82
|
return await fn()
|
|
61
83
|
} finally {
|