@glasstrace/sdk 1.8.0 → 1.9.1
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/async-context/index.cjs +15010 -0
- package/dist/async-context/index.cjs.map +1 -0
- package/dist/async-context/index.d.cts +174 -0
- package/dist/async-context/index.d.ts +174 -0
- package/dist/async-context/index.js +13 -0
- package/dist/{capture-error-Dzz7_-v4.d.ts → capture-error-BeuEXXJO.d.cts} +2 -2
- package/dist/{capture-error-C95zvSvF.d.cts → capture-error-D02pzB7q.d.ts} +2 -2
- package/dist/{chunk-JJL2M64Z.js → chunk-2F2MGFLO.js} +19 -10
- package/dist/chunk-2F2MGFLO.js.map +1 -0
- package/dist/chunk-CL3OVHPO.js +23 -0
- package/dist/chunk-CL3OVHPO.js.map +1 -0
- package/dist/{chunk-WL6BXEJ5.js → chunk-DKV53A2C.js} +2 -2
- package/dist/{chunk-3PJP5Y3U.js → chunk-GWIEUBFR.js} +3 -3
- package/dist/{chunk-H57MQGNU.js → chunk-H6WJ63X2.js} +2 -2
- package/dist/{chunk-NN5YCETI.js → chunk-HD6JIFKN.js} +2 -2
- package/dist/{chunk-P45NZR4J.js → chunk-JHUNLPSS.js} +35 -1
- package/dist/{chunk-P45NZR4J.js.map → chunk-JHUNLPSS.js.map} +1 -1
- package/dist/{chunk-UQKI476D.js → chunk-M6EWJCAT.js} +2 -2
- package/dist/chunk-QEXRCXSY.js +124 -0
- package/dist/chunk-QEXRCXSY.js.map +1 -0
- package/dist/chunk-QOHKZOKB.js +139 -0
- package/dist/chunk-QOHKZOKB.js.map +1 -0
- package/dist/{chunk-M2TLX6NM.js → chunk-QXITSNYM.js} +3 -3
- package/dist/cli/init.cjs +4 -4
- package/dist/cli/init.cjs.map +1 -1
- package/dist/cli/init.js +7 -7
- package/dist/cli/mcp-add.cjs +1 -1
- package/dist/cli/mcp-add.cjs.map +1 -1
- package/dist/cli/mcp-add.js +3 -3
- package/dist/cli/uninit.js +3 -3
- package/dist/cli/upgrade-instructions.cjs +1 -1
- package/dist/cli/upgrade-instructions.js +3 -3
- package/dist/cli/validate.cjs.map +1 -1
- package/dist/cli/validate.js +2 -2
- package/dist/{edge-entry-AWO70gje.d.ts → correlation-id-B_K8adD6.d.ts} +1 -1
- package/dist/{edge-entry-DaeG7D7S.d.cts → correlation-id-NAapJ5jn.d.cts} +1 -1
- package/dist/edge-entry.cjs +309 -26
- package/dist/edge-entry.cjs.map +1 -1
- package/dist/edge-entry.d.cts +5 -2
- package/dist/edge-entry.d.ts +5 -2
- package/dist/edge-entry.js +12 -3
- package/dist/index.cjs +55 -5
- package/dist/index.cjs.map +1 -1
- package/dist/{index.d-Dq33YwFT.d.cts → index.d-CkTf_boH.d.cts} +1 -1
- package/dist/{index.d-Dq33YwFT.d.ts → index.d-CkTf_boH.d.ts} +1 -1
- package/dist/index.d.cts +7 -4
- package/dist/index.d.ts +7 -4
- package/dist/index.js +6 -5
- package/dist/index.js.map +1 -1
- package/dist/middleware/index.cjs +15023 -0
- package/dist/middleware/index.cjs.map +1 -0
- package/dist/middleware/index.d.cts +191 -0
- package/dist/middleware/index.d.ts +191 -0
- package/dist/middleware/index.js +13 -0
- package/dist/middleware/index.js.map +1 -0
- package/dist/node-entry.cjs +55 -5
- package/dist/node-entry.cjs.map +1 -1
- package/dist/node-entry.d.cts +3 -3
- package/dist/node-entry.d.ts +3 -3
- package/dist/node-entry.js +8 -7
- package/dist/node-subpath.cjs.map +1 -1
- package/dist/node-subpath.d.cts +1 -1
- package/dist/node-subpath.d.ts +1 -1
- package/dist/node-subpath.js +3 -3
- package/dist/{source-map-uploader-XFUEVV7I.js → source-map-uploader-MMJ2WCL4.js} +3 -3
- package/dist/source-map-uploader-MMJ2WCL4.js.map +1 -0
- package/package.json +13 -1
- package/dist/chunk-JJL2M64Z.js.map +0 -1
- /package/dist/{source-map-uploader-XFUEVV7I.js.map → async-context/index.js.map} +0 -0
- /package/dist/{chunk-WL6BXEJ5.js.map → chunk-DKV53A2C.js.map} +0 -0
- /package/dist/{chunk-3PJP5Y3U.js.map → chunk-GWIEUBFR.js.map} +0 -0
- /package/dist/{chunk-H57MQGNU.js.map → chunk-H6WJ63X2.js.map} +0 -0
- /package/dist/{chunk-NN5YCETI.js.map → chunk-HD6JIFKN.js.map} +0 -0
- /package/dist/{chunk-UQKI476D.js.map → chunk-M6EWJCAT.js.map} +0 -0
- /package/dist/{chunk-M2TLX6NM.js.map → chunk-QXITSNYM.js.map} +0 -0
package/dist/cli/validate.js
CHANGED
|
@@ -2,8 +2,8 @@ import {
|
|
|
2
2
|
identityFingerprint,
|
|
3
3
|
readMcpMarker,
|
|
4
4
|
resolveEffectiveMcpCredential
|
|
5
|
-
} from "../chunk-
|
|
6
|
-
import "../chunk-
|
|
5
|
+
} from "../chunk-DKV53A2C.js";
|
|
6
|
+
import "../chunk-JHUNLPSS.js";
|
|
7
7
|
import "../chunk-NSBPE2FW.js";
|
|
8
8
|
|
|
9
9
|
// src/cli/validate.ts
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { f as SdkDiagnosticCode, g as SessionId, C as CaptureConfig } from './index.d-CkTf_boH.js';
|
|
2
2
|
import { ReadableSpan } from './export/ReadableSpan';
|
|
3
3
|
import { Span } from './Span';
|
|
4
4
|
import { SpanProcessor } from './SpanProcessor';
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { f as SdkDiagnosticCode, g as SessionId, C as CaptureConfig } from './index.d-CkTf_boH.cjs';
|
|
2
2
|
import { ReadableSpan } from './export/ReadableSpan';
|
|
3
3
|
import { Span } from './Span';
|
|
4
4
|
import { SpanProcessor } from './SpanProcessor';
|
package/dist/edge-entry.cjs
CHANGED
|
@@ -22,7 +22,9 @@ var edge_entry_exports = {};
|
|
|
22
22
|
__export(edge_entry_exports, {
|
|
23
23
|
GlasstraceSpanProcessor: () => GlasstraceSpanProcessor,
|
|
24
24
|
SdkError: () => SdkError,
|
|
25
|
-
captureCorrelationId: () => captureCorrelationId
|
|
25
|
+
captureCorrelationId: () => captureCorrelationId,
|
|
26
|
+
tracedRequestMiddleware: () => tracedRequestMiddleware,
|
|
27
|
+
withAsyncCausality: () => withAsyncCausality
|
|
26
28
|
});
|
|
27
29
|
module.exports = __toCommonJS(edge_entry_exports);
|
|
28
30
|
|
|
@@ -305,14 +307,14 @@ var BaseContext = class _BaseContext {
|
|
|
305
307
|
self2._currentContext = parentContext ? new Map(parentContext) : /* @__PURE__ */ new Map();
|
|
306
308
|
self2.getValue = (key) => self2._currentContext.get(key);
|
|
307
309
|
self2.setValue = (key, value) => {
|
|
308
|
-
const
|
|
309
|
-
|
|
310
|
-
return
|
|
310
|
+
const context2 = new _BaseContext(self2._currentContext);
|
|
311
|
+
context2._currentContext.set(key, value);
|
|
312
|
+
return context2;
|
|
311
313
|
};
|
|
312
314
|
self2.deleteValue = (key) => {
|
|
313
|
-
const
|
|
314
|
-
|
|
315
|
-
return
|
|
315
|
+
const context2 = new _BaseContext(self2._currentContext);
|
|
316
|
+
context2._currentContext.delete(key);
|
|
317
|
+
return context2;
|
|
316
318
|
};
|
|
317
319
|
}
|
|
318
320
|
};
|
|
@@ -373,8 +375,8 @@ var ContextAPI = class _ContextAPI {
|
|
|
373
375
|
* @param thisArg optional receiver to be used for calling fn
|
|
374
376
|
* @param args optional arguments forwarded to fn
|
|
375
377
|
*/
|
|
376
|
-
with(
|
|
377
|
-
return this._getContextManager().with(
|
|
378
|
+
with(context2, fn, thisArg, ...args) {
|
|
379
|
+
return this._getContextManager().with(context2, fn, thisArg, ...args);
|
|
378
380
|
}
|
|
379
381
|
/**
|
|
380
382
|
* Bind a context to a target function or event emitter
|
|
@@ -382,8 +384,8 @@ var ContextAPI = class _ContextAPI {
|
|
|
382
384
|
* @param context context to bind to the event emitter or function. Defaults to the currently active context
|
|
383
385
|
* @param target function or event emitter to bind
|
|
384
386
|
*/
|
|
385
|
-
bind(
|
|
386
|
-
return this._getContextManager().bind(
|
|
387
|
+
bind(context2, target) {
|
|
388
|
+
return this._getContextManager().bind(context2, target);
|
|
387
389
|
}
|
|
388
390
|
_getContextManager() {
|
|
389
391
|
return getGlobal(API_NAME2) || NOOP_CONTEXT_MANAGER;
|
|
@@ -460,24 +462,24 @@ var NonRecordingSpan = class {
|
|
|
460
462
|
|
|
461
463
|
// ../../node_modules/@opentelemetry/api/build/esm/trace/context-utils.js
|
|
462
464
|
var SPAN_KEY = createContextKey("OpenTelemetry Context Key SPAN");
|
|
463
|
-
function getSpan(
|
|
464
|
-
return
|
|
465
|
+
function getSpan(context2) {
|
|
466
|
+
return context2.getValue(SPAN_KEY) || void 0;
|
|
465
467
|
}
|
|
466
468
|
function getActiveSpan() {
|
|
467
469
|
return getSpan(ContextAPI.getInstance().active());
|
|
468
470
|
}
|
|
469
|
-
function setSpan(
|
|
470
|
-
return
|
|
471
|
+
function setSpan(context2, span) {
|
|
472
|
+
return context2.setValue(SPAN_KEY, span);
|
|
471
473
|
}
|
|
472
|
-
function deleteSpan(
|
|
473
|
-
return
|
|
474
|
+
function deleteSpan(context2) {
|
|
475
|
+
return context2.deleteValue(SPAN_KEY);
|
|
474
476
|
}
|
|
475
|
-
function setSpanContext(
|
|
476
|
-
return setSpan(
|
|
477
|
+
function setSpanContext(context2, spanContext) {
|
|
478
|
+
return setSpan(context2, new NonRecordingSpan(spanContext));
|
|
477
479
|
}
|
|
478
|
-
function getSpanContext(
|
|
480
|
+
function getSpanContext(context2) {
|
|
479
481
|
var _a2;
|
|
480
|
-
return (_a2 = getSpan(
|
|
482
|
+
return (_a2 = getSpan(context2)) === null || _a2 === void 0 ? void 0 : _a2.spanContext();
|
|
481
483
|
}
|
|
482
484
|
|
|
483
485
|
// ../../node_modules/@opentelemetry/api/build/esm/trace/spancontext-utils.js
|
|
@@ -612,12 +614,12 @@ function wrapSpanContext(spanContext) {
|
|
|
612
614
|
var contextApi = ContextAPI.getInstance();
|
|
613
615
|
var NoopTracer = class {
|
|
614
616
|
// startSpan starts a noop span.
|
|
615
|
-
startSpan(name, options,
|
|
617
|
+
startSpan(name, options, context2 = contextApi.active()) {
|
|
616
618
|
const root = Boolean(options === null || options === void 0 ? void 0 : options.root);
|
|
617
619
|
if (root) {
|
|
618
620
|
return new NonRecordingSpan();
|
|
619
621
|
}
|
|
620
|
-
const parentFromContext =
|
|
622
|
+
const parentFromContext = context2 && getSpanContext(context2);
|
|
621
623
|
if (isSpanContext(parentFromContext) && isSpanContextValid(parentFromContext)) {
|
|
622
624
|
return new NonRecordingSpan(parentFromContext);
|
|
623
625
|
} else {
|
|
@@ -659,8 +661,8 @@ var ProxyTracer = class {
|
|
|
659
661
|
this.version = version2;
|
|
660
662
|
this.options = options;
|
|
661
663
|
}
|
|
662
|
-
startSpan(name, options,
|
|
663
|
-
return this._getTracer().startSpan(name, options,
|
|
664
|
+
startSpan(name, options, context2) {
|
|
665
|
+
return this._getTracer().startSpan(name, options, context2);
|
|
664
666
|
}
|
|
665
667
|
startActiveSpan(_name, _options, _context, _fn) {
|
|
666
668
|
const tracer = this._getTracer();
|
|
@@ -716,6 +718,17 @@ var ProxyTracerProvider = class {
|
|
|
716
718
|
}
|
|
717
719
|
};
|
|
718
720
|
|
|
721
|
+
// ../../node_modules/@opentelemetry/api/build/esm/trace/status.js
|
|
722
|
+
var SpanStatusCode;
|
|
723
|
+
(function(SpanStatusCode2) {
|
|
724
|
+
SpanStatusCode2[SpanStatusCode2["UNSET"] = 0] = "UNSET";
|
|
725
|
+
SpanStatusCode2[SpanStatusCode2["OK"] = 1] = "OK";
|
|
726
|
+
SpanStatusCode2[SpanStatusCode2["ERROR"] = 2] = "ERROR";
|
|
727
|
+
})(SpanStatusCode || (SpanStatusCode = {}));
|
|
728
|
+
|
|
729
|
+
// ../../node_modules/@opentelemetry/api/build/esm/context-api.js
|
|
730
|
+
var context = ContextAPI.getInstance();
|
|
731
|
+
|
|
719
732
|
// ../../node_modules/@opentelemetry/api/build/esm/api/trace.js
|
|
720
733
|
var API_NAME3 = "trace";
|
|
721
734
|
var TraceAPI = class _TraceAPI {
|
|
@@ -14653,6 +14666,40 @@ var GLASSTRACE_ATTRIBUTE_NAMES = {
|
|
|
14653
14666
|
ELEMENT_FINGERPRINT: "glasstrace.element.fingerprint",
|
|
14654
14667
|
ELEMENT_CONFIDENCE: "glasstrace.element.confidence",
|
|
14655
14668
|
TAB_ID: "glasstrace.tab.id",
|
|
14669
|
+
// Causal evidence (SDK-046 / DISC-1537 + DISC-1539).
|
|
14670
|
+
//
|
|
14671
|
+
// The SDK emits `glasstrace.causal.*` attributes on spans that
|
|
14672
|
+
// carry instrumentation-time evidence about a span's relationship
|
|
14673
|
+
// to its owning request trace. Two families are defined here:
|
|
14674
|
+
//
|
|
14675
|
+
// - `MIDDLEWARE_FOR_REQUEST` — middleware-ownership marker. Set
|
|
14676
|
+
// on a middleware-only span by `tracedRequestMiddleware()` from
|
|
14677
|
+
// `@glasstrace/sdk/middleware`. Carries the originating
|
|
14678
|
+
// request's normalized path so the product-side trace-summary
|
|
14679
|
+
// transform can link the middleware span to the owning HTTP
|
|
14680
|
+
// request trace even when the middleware runs in an edge
|
|
14681
|
+
// runtime that does not propagate AsyncLocalStorage parents.
|
|
14682
|
+
//
|
|
14683
|
+
// - `POST_RESPONSE_ASYNC` — post-response async marker. Set on a
|
|
14684
|
+
// span emitted from inside `withAsyncCausality()` from
|
|
14685
|
+
// `@glasstrace/sdk/async-context`. Carries the originating
|
|
14686
|
+
// request's trace ID (32-character hex) captured at the call
|
|
14687
|
+
// site so async work scheduled via Next.js `after()`, queues,
|
|
14688
|
+
// or webhooks can be linked back to its originating request.
|
|
14689
|
+
// Companion booleans `CAUSAL_AFFECTS_HTTP_STATUS` /
|
|
14690
|
+
// `CAUSAL_AFFECTS_HTTP_DURATION` document whether the async
|
|
14691
|
+
// work participates in the root request's outcome (default
|
|
14692
|
+
// `false` — non-outcome async work).
|
|
14693
|
+
//
|
|
14694
|
+
// Wire keys live under the `glasstrace.causal.*` namespace so they
|
|
14695
|
+
// are namespace-distinct from `glasstrace.error.*`,
|
|
14696
|
+
// `glasstrace.http.*`, `glasstrace.trpc.*`, and the side-effect
|
|
14697
|
+
// family below. Adding these constants is a `@glasstrace/protocol`
|
|
14698
|
+
// minor bump; existing entries are untouched.
|
|
14699
|
+
CAUSAL_MIDDLEWARE_FOR_REQUEST: "glasstrace.causal.middleware_for_request",
|
|
14700
|
+
CAUSAL_POST_RESPONSE_ASYNC: "glasstrace.causal.post_response_async",
|
|
14701
|
+
CAUSAL_AFFECTS_HTTP_STATUS: "glasstrace.causal.affects_http_status",
|
|
14702
|
+
CAUSAL_AFFECTS_HTTP_DURATION: "glasstrace.causal.affects_http_duration",
|
|
14656
14703
|
// Side-effect evidence (SDK-049 / SCHEMA-036).
|
|
14657
14704
|
// Top-level operation attributes attached to the active span when a
|
|
14658
14705
|
// side-effect is recorded via `recordSideEffect()`. The wire-string
|
|
@@ -14932,10 +14979,246 @@ function firstToken(value) {
|
|
|
14932
14979
|
}
|
|
14933
14980
|
return void 0;
|
|
14934
14981
|
}
|
|
14982
|
+
|
|
14983
|
+
// src/optional-lifecycle.ts
|
|
14984
|
+
var EMIT_BRIDGE = /* @__PURE__ */ Symbol.for("glasstrace.lifecycle.emit-bridge");
|
|
14985
|
+
function tryEmitLifecycleEvent(event, payload) {
|
|
14986
|
+
try {
|
|
14987
|
+
const slot = globalThis[EMIT_BRIDGE];
|
|
14988
|
+
if (!slot) return;
|
|
14989
|
+
slot.emit(event, payload);
|
|
14990
|
+
} catch {
|
|
14991
|
+
}
|
|
14992
|
+
}
|
|
14993
|
+
|
|
14994
|
+
// src/middleware/index.ts
|
|
14995
|
+
var ATTR2 = GLASSTRACE_ATTRIBUTE_NAMES;
|
|
14996
|
+
var TRACER_NAME = "@glasstrace/sdk/middleware";
|
|
14997
|
+
var _skippedUninstalledEmitted = false;
|
|
14998
|
+
function extractRequestPath(req) {
|
|
14999
|
+
if (req === null || typeof req !== "object") return void 0;
|
|
15000
|
+
try {
|
|
15001
|
+
const nextUrl = req.nextUrl;
|
|
15002
|
+
if (nextUrl !== null && typeof nextUrl === "object") {
|
|
15003
|
+
const pathname = nextUrl.pathname;
|
|
15004
|
+
if (typeof pathname === "string" && pathname.length > 0) {
|
|
15005
|
+
return pathname;
|
|
15006
|
+
}
|
|
15007
|
+
}
|
|
15008
|
+
const url2 = req.url;
|
|
15009
|
+
if (typeof url2 === "string" && url2.length > 0) {
|
|
15010
|
+
try {
|
|
15011
|
+
return new URL(url2).pathname;
|
|
15012
|
+
} catch {
|
|
15013
|
+
try {
|
|
15014
|
+
return new URL(url2, "http://localhost").pathname;
|
|
15015
|
+
} catch {
|
|
15016
|
+
return void 0;
|
|
15017
|
+
}
|
|
15018
|
+
}
|
|
15019
|
+
}
|
|
15020
|
+
} catch {
|
|
15021
|
+
}
|
|
15022
|
+
return void 0;
|
|
15023
|
+
}
|
|
15024
|
+
var INVALID_TRACE_ID = "00000000000000000000000000000000";
|
|
15025
|
+
function isNoopSpan(span) {
|
|
15026
|
+
try {
|
|
15027
|
+
return span.spanContext().traceId === INVALID_TRACE_ID;
|
|
15028
|
+
} catch {
|
|
15029
|
+
return false;
|
|
15030
|
+
}
|
|
15031
|
+
}
|
|
15032
|
+
function tracedRequestMiddleware(options, handler) {
|
|
15033
|
+
if (typeof options.name !== "string" || options.name.length === 0) {
|
|
15034
|
+
throw new TypeError(
|
|
15035
|
+
"tracedRequestMiddleware: options.name must be a non-empty string"
|
|
15036
|
+
);
|
|
15037
|
+
}
|
|
15038
|
+
const wrapped = ((req, ...rest) => {
|
|
15039
|
+
const tracer = trace.getTracer(TRACER_NAME);
|
|
15040
|
+
let callbackInvoked = false;
|
|
15041
|
+
try {
|
|
15042
|
+
return tracer.startActiveSpan(options.name, (span) => {
|
|
15043
|
+
callbackInvoked = true;
|
|
15044
|
+
if (isNoopSpan(span)) {
|
|
15045
|
+
if (!_skippedUninstalledEmitted) {
|
|
15046
|
+
_skippedUninstalledEmitted = true;
|
|
15047
|
+
tryEmitLifecycleEvent("middleware:skipped_uninstalled", {});
|
|
15048
|
+
}
|
|
15049
|
+
endSpanSafely(span);
|
|
15050
|
+
return handler(req, ...rest);
|
|
15051
|
+
}
|
|
15052
|
+
try {
|
|
15053
|
+
if (options.attributes) {
|
|
15054
|
+
span.setAttributes(options.attributes);
|
|
15055
|
+
}
|
|
15056
|
+
const path = extractRequestPath(req);
|
|
15057
|
+
if (path !== void 0) {
|
|
15058
|
+
span.setAttribute(ATTR2.CAUSAL_MIDDLEWARE_FOR_REQUEST, path);
|
|
15059
|
+
}
|
|
15060
|
+
} catch {
|
|
15061
|
+
}
|
|
15062
|
+
let result;
|
|
15063
|
+
try {
|
|
15064
|
+
result = handler(req, ...rest);
|
|
15065
|
+
} catch (error48) {
|
|
15066
|
+
recordSpanError(span, error48);
|
|
15067
|
+
endSpanSafely(span);
|
|
15068
|
+
throw error48;
|
|
15069
|
+
}
|
|
15070
|
+
if (result !== null && typeof result === "object" && typeof result.then === "function") {
|
|
15071
|
+
return result.then(
|
|
15072
|
+
(value) => {
|
|
15073
|
+
endSpanSafely(span);
|
|
15074
|
+
return value;
|
|
15075
|
+
},
|
|
15076
|
+
(error48) => {
|
|
15077
|
+
recordSpanError(span, error48);
|
|
15078
|
+
endSpanSafely(span);
|
|
15079
|
+
throw error48;
|
|
15080
|
+
}
|
|
15081
|
+
);
|
|
15082
|
+
}
|
|
15083
|
+
endSpanSafely(span);
|
|
15084
|
+
return result;
|
|
15085
|
+
});
|
|
15086
|
+
} catch (err) {
|
|
15087
|
+
if (callbackInvoked) {
|
|
15088
|
+
throw err;
|
|
15089
|
+
}
|
|
15090
|
+
return handler(req, ...rest);
|
|
15091
|
+
}
|
|
15092
|
+
});
|
|
15093
|
+
return wrapped;
|
|
15094
|
+
}
|
|
15095
|
+
function recordSpanError(span, error48) {
|
|
15096
|
+
const normalized = error48 instanceof Error ? error48 : typeof error48 === "string" ? error48 : new Error(String(error48));
|
|
15097
|
+
const statusMessage = normalized instanceof Error ? normalized.message : normalized;
|
|
15098
|
+
try {
|
|
15099
|
+
span.recordException(normalized);
|
|
15100
|
+
} catch {
|
|
15101
|
+
}
|
|
15102
|
+
try {
|
|
15103
|
+
span.setStatus({ code: SpanStatusCode.ERROR, message: statusMessage });
|
|
15104
|
+
} catch {
|
|
15105
|
+
}
|
|
15106
|
+
}
|
|
15107
|
+
function endSpanSafely(span) {
|
|
15108
|
+
try {
|
|
15109
|
+
span.end();
|
|
15110
|
+
} catch {
|
|
15111
|
+
}
|
|
15112
|
+
}
|
|
15113
|
+
|
|
15114
|
+
// src/async-context/index.ts
|
|
15115
|
+
var ATTR3 = GLASSTRACE_ATTRIBUTE_NAMES;
|
|
15116
|
+
var TRACER_NAME2 = "@glasstrace/sdk/async-context";
|
|
15117
|
+
var INVALID_TRACE_ID2 = "00000000000000000000000000000000";
|
|
15118
|
+
var _skippedUninstalledEmitted2 = false;
|
|
15119
|
+
var _noOriginatingContextEmitted = false;
|
|
15120
|
+
function withAsyncCausality(options, fn) {
|
|
15121
|
+
if (typeof options.name !== "string" || options.name.length === 0) {
|
|
15122
|
+
throw new TypeError(
|
|
15123
|
+
"withAsyncCausality: options.name must be a non-empty string"
|
|
15124
|
+
);
|
|
15125
|
+
}
|
|
15126
|
+
if (typeof fn !== "function") {
|
|
15127
|
+
throw new TypeError("withAsyncCausality: fn must be a function");
|
|
15128
|
+
}
|
|
15129
|
+
const capturedContext = (() => {
|
|
15130
|
+
try {
|
|
15131
|
+
const active = trace.getActiveSpan();
|
|
15132
|
+
if (!active) return void 0;
|
|
15133
|
+
const ctx = active.spanContext();
|
|
15134
|
+
if (ctx.traceId === INVALID_TRACE_ID2) return void 0;
|
|
15135
|
+
return ctx;
|
|
15136
|
+
} catch {
|
|
15137
|
+
return void 0;
|
|
15138
|
+
}
|
|
15139
|
+
})();
|
|
15140
|
+
return async () => {
|
|
15141
|
+
const tracer = trace.getTracer(TRACER_NAME2);
|
|
15142
|
+
let span;
|
|
15143
|
+
try {
|
|
15144
|
+
span = tracer.startSpan(options.name, {
|
|
15145
|
+
root: true,
|
|
15146
|
+
links: capturedContext !== void 0 ? [{ context: capturedContext }] : void 0
|
|
15147
|
+
});
|
|
15148
|
+
} catch {
|
|
15149
|
+
return Promise.resolve(fn());
|
|
15150
|
+
}
|
|
15151
|
+
if (isNoopSpan2(span)) {
|
|
15152
|
+
if (!_skippedUninstalledEmitted2) {
|
|
15153
|
+
_skippedUninstalledEmitted2 = true;
|
|
15154
|
+
tryEmitLifecycleEvent("async:skipped_uninstalled", {});
|
|
15155
|
+
}
|
|
15156
|
+
endSpanSafely2(span);
|
|
15157
|
+
return Promise.resolve(fn());
|
|
15158
|
+
}
|
|
15159
|
+
if (capturedContext === void 0 && !_noOriginatingContextEmitted) {
|
|
15160
|
+
_noOriginatingContextEmitted = true;
|
|
15161
|
+
tryEmitLifecycleEvent("async:no_originating_context", {});
|
|
15162
|
+
}
|
|
15163
|
+
try {
|
|
15164
|
+
if (options.attributes) {
|
|
15165
|
+
span.setAttributes(options.attributes);
|
|
15166
|
+
}
|
|
15167
|
+
if (capturedContext !== void 0) {
|
|
15168
|
+
span.setAttribute(
|
|
15169
|
+
ATTR3.CAUSAL_POST_RESPONSE_ASYNC,
|
|
15170
|
+
capturedContext.traceId
|
|
15171
|
+
);
|
|
15172
|
+
span.setAttribute(ATTR3.CAUSAL_AFFECTS_HTTP_STATUS, false);
|
|
15173
|
+
span.setAttribute(ATTR3.CAUSAL_AFFECTS_HTTP_DURATION, false);
|
|
15174
|
+
}
|
|
15175
|
+
} catch {
|
|
15176
|
+
}
|
|
15177
|
+
try {
|
|
15178
|
+
const value = await context.with(
|
|
15179
|
+
trace.setSpan(context.active(), span),
|
|
15180
|
+
fn
|
|
15181
|
+
);
|
|
15182
|
+
return value;
|
|
15183
|
+
} catch (error48) {
|
|
15184
|
+
recordSpanError2(span, error48);
|
|
15185
|
+
throw error48;
|
|
15186
|
+
} finally {
|
|
15187
|
+
endSpanSafely2(span);
|
|
15188
|
+
}
|
|
15189
|
+
};
|
|
15190
|
+
}
|
|
15191
|
+
function isNoopSpan2(span) {
|
|
15192
|
+
try {
|
|
15193
|
+
return span.spanContext().traceId === INVALID_TRACE_ID2;
|
|
15194
|
+
} catch {
|
|
15195
|
+
return false;
|
|
15196
|
+
}
|
|
15197
|
+
}
|
|
15198
|
+
function recordSpanError2(span, error48) {
|
|
15199
|
+
const normalized = error48 instanceof Error ? error48 : typeof error48 === "string" ? error48 : new Error(String(error48));
|
|
15200
|
+
const statusMessage = normalized instanceof Error ? normalized.message : normalized;
|
|
15201
|
+
try {
|
|
15202
|
+
span.recordException(normalized);
|
|
15203
|
+
} catch {
|
|
15204
|
+
}
|
|
15205
|
+
try {
|
|
15206
|
+
span.setStatus({ code: SpanStatusCode.ERROR, message: statusMessage });
|
|
15207
|
+
} catch {
|
|
15208
|
+
}
|
|
15209
|
+
}
|
|
15210
|
+
function endSpanSafely2(span) {
|
|
15211
|
+
try {
|
|
15212
|
+
span.end();
|
|
15213
|
+
} catch {
|
|
15214
|
+
}
|
|
15215
|
+
}
|
|
14935
15216
|
// Annotate the CommonJS export names for ESM import in node:
|
|
14936
15217
|
0 && (module.exports = {
|
|
14937
15218
|
GlasstraceSpanProcessor,
|
|
14938
15219
|
SdkError,
|
|
14939
|
-
captureCorrelationId
|
|
15220
|
+
captureCorrelationId,
|
|
15221
|
+
tracedRequestMiddleware,
|
|
15222
|
+
withAsyncCausality
|
|
14940
15223
|
});
|
|
14941
15224
|
//# sourceMappingURL=edge-entry.cjs.map
|