@glasstrace/sdk 0.12.4 → 0.12.5
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 +38 -4
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +2 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +38 -4
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.cts
CHANGED
|
@@ -361,6 +361,7 @@ interface GlasstraceExporterOptions {
|
|
|
361
361
|
environment: string | undefined;
|
|
362
362
|
endpointUrl: string;
|
|
363
363
|
createDelegate: ((url: string, headers: Record<string, string>) => SpanExporter) | null;
|
|
364
|
+
verbose?: boolean;
|
|
364
365
|
}
|
|
365
366
|
/**
|
|
366
367
|
* A SpanExporter that enriches spans with glasstrace.* attributes at export
|
|
@@ -381,6 +382,7 @@ declare class GlasstraceExporter implements SpanExporter {
|
|
|
381
382
|
private readonly environment;
|
|
382
383
|
private readonly endpointUrl;
|
|
383
384
|
private readonly createDelegateFn;
|
|
385
|
+
private readonly verbose;
|
|
384
386
|
private delegate;
|
|
385
387
|
private delegateKey;
|
|
386
388
|
private pendingBatches;
|
package/dist/index.d.ts
CHANGED
|
@@ -361,6 +361,7 @@ interface GlasstraceExporterOptions {
|
|
|
361
361
|
environment: string | undefined;
|
|
362
362
|
endpointUrl: string;
|
|
363
363
|
createDelegate: ((url: string, headers: Record<string, string>) => SpanExporter) | null;
|
|
364
|
+
verbose?: boolean;
|
|
364
365
|
}
|
|
365
366
|
/**
|
|
366
367
|
* A SpanExporter that enriches spans with glasstrace.* attributes at export
|
|
@@ -381,6 +382,7 @@ declare class GlasstraceExporter implements SpanExporter {
|
|
|
381
382
|
private readonly environment;
|
|
382
383
|
private readonly endpointUrl;
|
|
383
384
|
private readonly createDelegateFn;
|
|
385
|
+
private readonly verbose;
|
|
384
386
|
private delegate;
|
|
385
387
|
private delegateKey;
|
|
386
388
|
private pendingBatches;
|
package/dist/index.js
CHANGED
|
@@ -577,6 +577,7 @@ var GlasstraceExporter = class {
|
|
|
577
577
|
environment;
|
|
578
578
|
endpointUrl;
|
|
579
579
|
createDelegateFn;
|
|
580
|
+
verbose;
|
|
580
581
|
delegate = null;
|
|
581
582
|
delegateKey = null;
|
|
582
583
|
pendingBatches = [];
|
|
@@ -589,6 +590,7 @@ var GlasstraceExporter = class {
|
|
|
589
590
|
this.environment = options.environment;
|
|
590
591
|
this.endpointUrl = options.endpointUrl;
|
|
591
592
|
this.createDelegateFn = options.createDelegate;
|
|
593
|
+
this.verbose = options.verbose ?? false;
|
|
592
594
|
}
|
|
593
595
|
export(spans, resultCallback) {
|
|
594
596
|
const currentKey = this.getApiKey();
|
|
@@ -597,11 +599,16 @@ var GlasstraceExporter = class {
|
|
|
597
599
|
return;
|
|
598
600
|
}
|
|
599
601
|
const enrichedSpans = spans.map((span) => this.enrichSpan(span));
|
|
602
|
+
if (this.verbose) {
|
|
603
|
+
sdkLog("info", `[glasstrace:diag] Export batch: ${enrichedSpans.length} spans`);
|
|
604
|
+
}
|
|
600
605
|
const exporter = this.ensureDelegate();
|
|
601
606
|
if (exporter) {
|
|
602
607
|
exporter.export(enrichedSpans, (result) => {
|
|
603
608
|
if (result.code !== 0) {
|
|
604
609
|
sdkLog("warn", `[glasstrace] Span export failed: ${result.error?.message ?? "unknown error"}`);
|
|
610
|
+
} else if (this.verbose) {
|
|
611
|
+
sdkLog("info", `[glasstrace:diag] Export success: ${enrichedSpans.length} spans delivered`);
|
|
605
612
|
}
|
|
606
613
|
resultCallback(result);
|
|
607
614
|
});
|
|
@@ -694,6 +701,21 @@ var GlasstraceExporter = class {
|
|
|
694
701
|
if (statusCode !== void 0) {
|
|
695
702
|
extra[ATTR.HTTP_STATUS_CODE] = statusCode;
|
|
696
703
|
}
|
|
704
|
+
if (method && span.status?.code === SpanStatusCode.ERROR) {
|
|
705
|
+
if (statusCode === void 0 || statusCode === 0 || statusCode === 200) {
|
|
706
|
+
const httpErrorType = attrs["error.type"];
|
|
707
|
+
if (typeof httpErrorType === "string") {
|
|
708
|
+
const parsed = parseInt(httpErrorType, 10);
|
|
709
|
+
if (!isNaN(parsed) && parsed >= 400 && parsed <= 599) {
|
|
710
|
+
extra[ATTR.HTTP_STATUS_CODE] = parsed;
|
|
711
|
+
} else {
|
|
712
|
+
extra[ATTR.HTTP_STATUS_CODE] = 500;
|
|
713
|
+
}
|
|
714
|
+
} else {
|
|
715
|
+
extra[ATTR.HTTP_STATUS_CODE] = 500;
|
|
716
|
+
}
|
|
717
|
+
}
|
|
718
|
+
}
|
|
697
719
|
if (span.startTime && span.endTime) {
|
|
698
720
|
const [startSec, startNano] = span.startTime;
|
|
699
721
|
const [endSec, endNano] = span.endTime;
|
|
@@ -773,11 +795,17 @@ var GlasstraceExporter = class {
|
|
|
773
795
|
bufferSpans(spans, resultCallback) {
|
|
774
796
|
this.pendingBatches.push({ spans, resultCallback });
|
|
775
797
|
this.pendingSpanCount += spans.length;
|
|
798
|
+
if (this.verbose) {
|
|
799
|
+
sdkLog("info", `[glasstrace:diag] Buffering ${spans.length} spans (key pending, total: ${this.pendingSpanCount})`);
|
|
800
|
+
}
|
|
776
801
|
while (this.pendingSpanCount > MAX_PENDING_SPANS && this.pendingBatches.length > 1) {
|
|
777
802
|
const evicted = this.pendingBatches.shift();
|
|
778
803
|
this.pendingSpanCount -= evicted.spans.length;
|
|
779
804
|
recordSpansDropped(evicted.spans.length);
|
|
780
805
|
evicted.resultCallback({ code: 0 });
|
|
806
|
+
if (this.verbose) {
|
|
807
|
+
sdkLog("info", `[glasstrace:diag] Buffer overflow: evicted ${evicted.spans.length} spans (total pending: ${this.pendingSpanCount})`);
|
|
808
|
+
}
|
|
781
809
|
if (!this.overflowLogged) {
|
|
782
810
|
this.overflowLogged = true;
|
|
783
811
|
console.warn(
|
|
@@ -816,6 +844,8 @@ var GlasstraceExporter = class {
|
|
|
816
844
|
exporter.export(enriched, (result) => {
|
|
817
845
|
if (result.code !== 0) {
|
|
818
846
|
sdkLog("warn", `[glasstrace] Span export failed: ${result.error?.message ?? "unknown error"}`);
|
|
847
|
+
} else if (this.verbose) {
|
|
848
|
+
sdkLog("info", `[glasstrace:diag] Flush export success: ${enriched.length} spans delivered`);
|
|
819
849
|
}
|
|
820
850
|
batch.resultCallback(result);
|
|
821
851
|
});
|
|
@@ -3581,7 +3611,8 @@ async function configureOtel(config, sessionManager) {
|
|
|
3581
3611
|
getConfig: () => getActiveConfig(),
|
|
3582
3612
|
environment: config.environment,
|
|
3583
3613
|
endpointUrl: exporterUrl,
|
|
3584
|
-
createDelegate: createOtlpExporter
|
|
3614
|
+
createDelegate: createOtlpExporter,
|
|
3615
|
+
verbose: config.verbose
|
|
3585
3616
|
});
|
|
3586
3617
|
_activeExporter = glasstraceExporter;
|
|
3587
3618
|
const vercelOtel = await tryImport("@vercel/otel");
|
|
@@ -3624,6 +3655,9 @@ async function configureOtel(config, sessionManager) {
|
|
|
3624
3655
|
const processor = new BatchSpanProcessor(glasstraceExporter, {
|
|
3625
3656
|
scheduledDelayMillis: 1e3
|
|
3626
3657
|
});
|
|
3658
|
+
if (config.verbose) {
|
|
3659
|
+
sdkLog("info", "[glasstrace:diag] BatchSpanProcessor configured: scheduledDelayMillis=1000");
|
|
3660
|
+
}
|
|
3627
3661
|
const provider = new BasicTracerProvider({
|
|
3628
3662
|
spanProcessors: [processor]
|
|
3629
3663
|
});
|
|
@@ -3887,8 +3921,8 @@ async function backgroundInit(config, anonKeyForInit, generation) {
|
|
|
3887
3921
|
if (config.verbose) {
|
|
3888
3922
|
console.info("[glasstrace] Background init firing.");
|
|
3889
3923
|
}
|
|
3890
|
-
const healthReport = collectHealthReport("0.12.
|
|
3891
|
-
const initResult = await performInit(config, anonKeyForInit, "0.12.
|
|
3924
|
+
const healthReport = collectHealthReport("0.12.5");
|
|
3925
|
+
const initResult = await performInit(config, anonKeyForInit, "0.12.5", healthReport);
|
|
3892
3926
|
if (generation !== registrationGeneration) return;
|
|
3893
3927
|
if (initResult?.claimResult) {
|
|
3894
3928
|
setResolvedApiKey(initResult.claimResult.newApiKey);
|
|
@@ -3896,7 +3930,7 @@ async function backgroundInit(config, anonKeyForInit, generation) {
|
|
|
3896
3930
|
}
|
|
3897
3931
|
maybeInstallConsoleCapture();
|
|
3898
3932
|
if (didLastInitSucceed()) {
|
|
3899
|
-
startHeartbeat(config, anonKeyForInit, "0.12.
|
|
3933
|
+
startHeartbeat(config, anonKeyForInit, "0.12.5", generation, (newApiKey) => {
|
|
3900
3934
|
setResolvedApiKey(newApiKey);
|
|
3901
3935
|
notifyApiKeyResolved();
|
|
3902
3936
|
});
|