@glasstrace/sdk 0.13.4 → 0.13.6
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/index.cjs +55 -21
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +2 -1
- package/dist/index.d.ts +2 -1
- package/dist/index.js +55 -21
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -17498,6 +17498,7 @@ var GlasstraceExporter = class {
|
|
|
17498
17498
|
environment;
|
|
17499
17499
|
endpointUrl;
|
|
17500
17500
|
createDelegateFn;
|
|
17501
|
+
verbose;
|
|
17501
17502
|
delegate = null;
|
|
17502
17503
|
delegateKey = null;
|
|
17503
17504
|
pendingBatches = [];
|
|
@@ -17510,6 +17511,7 @@ var GlasstraceExporter = class {
|
|
|
17510
17511
|
this.environment = options.environment;
|
|
17511
17512
|
this.endpointUrl = options.endpointUrl;
|
|
17512
17513
|
this.createDelegateFn = options.createDelegate;
|
|
17514
|
+
this.verbose = options.verbose ?? false;
|
|
17513
17515
|
}
|
|
17514
17516
|
export(spans, resultCallback) {
|
|
17515
17517
|
const currentKey = this.getApiKey();
|
|
@@ -17615,7 +17617,17 @@ var GlasstraceExporter = class {
|
|
|
17615
17617
|
if (statusCode !== void 0) {
|
|
17616
17618
|
extra[ATTR.HTTP_STATUS_CODE] = statusCode;
|
|
17617
17619
|
}
|
|
17618
|
-
|
|
17620
|
+
const isErrorByStatus = span.status?.code === SpanStatusCode.ERROR;
|
|
17621
|
+
const isErrorByEvent = hasExceptionEvent(span);
|
|
17622
|
+
const isErrorByAttrs = typeof attrs["exception.type"] === "string" || typeof attrs["exception.message"] === "string";
|
|
17623
|
+
const statusNotExplicitlyOK = span.status?.code !== SpanStatusCode.OK;
|
|
17624
|
+
if (this.verbose && method) {
|
|
17625
|
+
sdkLog(
|
|
17626
|
+
"info",
|
|
17627
|
+
`[glasstrace] enrichSpan "${name}": status.code=${span.status?.code}, http.status_code=${statusCode}, isErrorByStatus=${isErrorByStatus}, isErrorByEvent=${isErrorByEvent}, isErrorByAttrs=${isErrorByAttrs}`
|
|
17628
|
+
);
|
|
17629
|
+
}
|
|
17630
|
+
if (method && statusNotExplicitlyOK && (isErrorByStatus || isErrorByEvent || isErrorByAttrs)) {
|
|
17619
17631
|
if (statusCode === void 0 || statusCode === 0 || statusCode === 200) {
|
|
17620
17632
|
const httpErrorType = attrs["error.type"];
|
|
17621
17633
|
if (typeof httpErrorType === "string") {
|
|
@@ -17628,6 +17640,12 @@ var GlasstraceExporter = class {
|
|
|
17628
17640
|
} else {
|
|
17629
17641
|
extra[ATTR.HTTP_STATUS_CODE] = 500;
|
|
17630
17642
|
}
|
|
17643
|
+
if (this.verbose) {
|
|
17644
|
+
sdkLog(
|
|
17645
|
+
"info",
|
|
17646
|
+
`[glasstrace] enrichSpan "${name}": inferred status_code=${extra[ATTR.HTTP_STATUS_CODE]} (was ${statusCode}), error.type=${attrs["error.type"]}`
|
|
17647
|
+
);
|
|
17648
|
+
}
|
|
17631
17649
|
}
|
|
17632
17650
|
}
|
|
17633
17651
|
if (span.startTime && span.endTime) {
|
|
@@ -17638,14 +17656,28 @@ var GlasstraceExporter = class {
|
|
|
17638
17656
|
extra[ATTR.HTTP_DURATION_MS] = durationMs;
|
|
17639
17657
|
}
|
|
17640
17658
|
}
|
|
17659
|
+
const eventDetails = statusNotExplicitlyOK ? getExceptionEventDetails(span) : { type: void 0, message: void 0 };
|
|
17641
17660
|
const errorMessage = attrs["exception.message"];
|
|
17642
17661
|
if (typeof errorMessage === "string") {
|
|
17643
17662
|
extra[ATTR.ERROR_MESSAGE] = errorMessage;
|
|
17663
|
+
} else if (eventDetails.message) {
|
|
17664
|
+
extra[ATTR.ERROR_MESSAGE] = eventDetails.message;
|
|
17644
17665
|
}
|
|
17645
17666
|
const errorType = attrs["exception.type"];
|
|
17646
17667
|
if (typeof errorType === "string") {
|
|
17647
17668
|
extra[ATTR.ERROR_CODE] = errorType;
|
|
17648
17669
|
extra[ATTR.ERROR_CATEGORY] = deriveErrorCategory(errorType);
|
|
17670
|
+
} else if (eventDetails.type) {
|
|
17671
|
+
extra[ATTR.ERROR_CODE] = eventDetails.type;
|
|
17672
|
+
extra[ATTR.ERROR_CATEGORY] = deriveErrorCategory(eventDetails.type);
|
|
17673
|
+
}
|
|
17674
|
+
if (this.verbose && (extra[ATTR.ERROR_MESSAGE] || extra[ATTR.ERROR_CODE])) {
|
|
17675
|
+
const msgSource = typeof errorMessage === "string" ? "attrs" : eventDetails.message ? "event" : "none";
|
|
17676
|
+
const typeSource = typeof errorType === "string" ? "attrs" : eventDetails.type ? "event" : "none";
|
|
17677
|
+
sdkLog(
|
|
17678
|
+
"info",
|
|
17679
|
+
`[glasstrace] enrichSpan "${name}": error.message source=${msgSource}, error.code source=${typeSource}`
|
|
17680
|
+
);
|
|
17649
17681
|
}
|
|
17650
17682
|
const errorField = attrs["error.field"];
|
|
17651
17683
|
if (typeof errorField === "string") {
|
|
@@ -17768,6 +17800,21 @@ function createEnrichedSpan(span, extra) {
|
|
|
17768
17800
|
}
|
|
17769
17801
|
});
|
|
17770
17802
|
}
|
|
17803
|
+
function hasExceptionEvent(span) {
|
|
17804
|
+
return span.events?.some((e) => e.name === "exception") ?? false;
|
|
17805
|
+
}
|
|
17806
|
+
function getExceptionEventDetails(span) {
|
|
17807
|
+
const event = span.events?.find((e) => e.name === "exception");
|
|
17808
|
+
if (!event?.attributes) {
|
|
17809
|
+
return { type: void 0, message: void 0 };
|
|
17810
|
+
}
|
|
17811
|
+
const type = event.attributes["exception.type"];
|
|
17812
|
+
const message = event.attributes["exception.message"];
|
|
17813
|
+
return {
|
|
17814
|
+
type: typeof type === "string" ? type : void 0,
|
|
17815
|
+
message: typeof message === "string" ? message : void 0
|
|
17816
|
+
};
|
|
17817
|
+
}
|
|
17771
17818
|
function deriveOrmProvider(instrumentationName) {
|
|
17772
17819
|
const lower = instrumentationName.toLowerCase();
|
|
17773
17820
|
if (lower.includes("prisma")) {
|
|
@@ -20692,7 +20739,8 @@ async function configureOtel(config2, sessionManager) {
|
|
|
20692
20739
|
getConfig: () => getActiveConfig(),
|
|
20693
20740
|
environment: config2.environment,
|
|
20694
20741
|
endpointUrl: exporterUrl,
|
|
20695
|
-
createDelegate: createOtlpExporter
|
|
20742
|
+
createDelegate: createOtlpExporter,
|
|
20743
|
+
verbose: config2.verbose
|
|
20696
20744
|
});
|
|
20697
20745
|
_activeExporter = glasstraceExporter;
|
|
20698
20746
|
const vercelOtel = await tryImport("@vercel/otel");
|
|
@@ -20744,25 +20792,11 @@ async function configureOtel(config2, sessionManager) {
|
|
|
20744
20792
|
|
|
20745
20793
|
// src/context-manager.ts
|
|
20746
20794
|
init_cjs_shims();
|
|
20795
|
+
var import_node_async_hooks = require("async_hooks");
|
|
20747
20796
|
init_esm();
|
|
20748
|
-
var AsyncLocalStorageCtor = null;
|
|
20749
|
-
try {
|
|
20750
|
-
const importFn = Function("id", "return import(id)");
|
|
20751
|
-
importFn("node:async_hooks").then(
|
|
20752
|
-
(mod) => {
|
|
20753
|
-
AsyncLocalStorageCtor = mod.AsyncLocalStorage;
|
|
20754
|
-
},
|
|
20755
|
-
() => {
|
|
20756
|
-
}
|
|
20757
|
-
);
|
|
20758
|
-
} catch {
|
|
20759
|
-
}
|
|
20760
20797
|
function installContextManager() {
|
|
20761
|
-
if (!AsyncLocalStorageCtor) {
|
|
20762
|
-
return false;
|
|
20763
|
-
}
|
|
20764
20798
|
try {
|
|
20765
|
-
const als = new
|
|
20799
|
+
const als = new import_node_async_hooks.AsyncLocalStorage();
|
|
20766
20800
|
const contextManager = {
|
|
20767
20801
|
active: () => als.getStore() ?? ROOT_CONTEXT,
|
|
20768
20802
|
with: (context2, fn, thisArg, ...args) => als.run(context2, () => fn.apply(thisArg, args)),
|
|
@@ -21064,8 +21098,8 @@ async function backgroundInit(config2, anonKeyForInit, generation) {
|
|
|
21064
21098
|
if (config2.verbose) {
|
|
21065
21099
|
console.info("[glasstrace] Background init firing.");
|
|
21066
21100
|
}
|
|
21067
|
-
const healthReport = collectHealthReport("0.13.
|
|
21068
|
-
const initResult = await performInit(config2, anonKeyForInit, "0.13.
|
|
21101
|
+
const healthReport = collectHealthReport("0.13.6");
|
|
21102
|
+
const initResult = await performInit(config2, anonKeyForInit, "0.13.6", healthReport);
|
|
21069
21103
|
if (generation !== registrationGeneration) return;
|
|
21070
21104
|
if (initResult?.claimResult) {
|
|
21071
21105
|
setResolvedApiKey(initResult.claimResult.newApiKey);
|
|
@@ -21073,7 +21107,7 @@ async function backgroundInit(config2, anonKeyForInit, generation) {
|
|
|
21073
21107
|
}
|
|
21074
21108
|
maybeInstallConsoleCapture();
|
|
21075
21109
|
if (didLastInitSucceed()) {
|
|
21076
|
-
startHeartbeat(config2, anonKeyForInit, "0.13.
|
|
21110
|
+
startHeartbeat(config2, anonKeyForInit, "0.13.6", generation, (newApiKey) => {
|
|
21077
21111
|
setResolvedApiKey(newApiKey);
|
|
21078
21112
|
notifyApiKeyResolved();
|
|
21079
21113
|
});
|