@statly/observe 1.0.0 → 1.2.0
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/README.md +142 -1
- package/dist/chunk-7AITSJLP.mjs +1422 -0
- package/dist/chunk-J5AHUFP2.mjs +135 -0
- package/dist/{chunk-UNDSALI5.mjs → chunk-SJ7C46AP.mjs} +190 -122
- package/dist/index.d.mts +80 -43
- package/dist/index.d.ts +80 -43
- package/dist/index.js +1883 -207
- package/dist/index.mjs +62 -1
- package/dist/integrations/express.js +259 -35
- package/dist/integrations/express.mjs +3 -1
- package/dist/integrations/fastify.js +271 -47
- package/dist/integrations/fastify.mjs +3 -1
- package/dist/integrations/nextjs.js +347 -104
- package/dist/integrations/nextjs.mjs +3 -1
- package/dist/logger/index.d.mts +671 -0
- package/dist/logger/index.d.ts +671 -0
- package/dist/logger/index.js +1483 -0
- package/dist/logger/index.mjs +56 -0
- package/dist/telemetry-CXHOTW3Y.mjs +8 -0
- package/package.json +7 -2
package/dist/index.mjs
CHANGED
|
@@ -5,6 +5,7 @@ import {
|
|
|
5
5
|
captureException,
|
|
6
6
|
captureMessage,
|
|
7
7
|
captureNextJsError,
|
|
8
|
+
captureSpan,
|
|
8
9
|
close,
|
|
9
10
|
createRequestCapture,
|
|
10
11
|
expressErrorHandler,
|
|
@@ -15,33 +16,93 @@ import {
|
|
|
15
16
|
setTag,
|
|
16
17
|
setTags,
|
|
17
18
|
setUser,
|
|
19
|
+
startSpan,
|
|
18
20
|
statlyFastifyPlugin,
|
|
19
21
|
statlyPlugin,
|
|
22
|
+
trace as trace2,
|
|
20
23
|
withStatly,
|
|
21
24
|
withStatlyGetServerSideProps,
|
|
22
25
|
withStatlyGetStaticProps,
|
|
23
26
|
withStatlyPagesApi,
|
|
24
27
|
withStatlyServerAction
|
|
25
|
-
} from "./chunk-
|
|
28
|
+
} from "./chunk-SJ7C46AP.mjs";
|
|
29
|
+
import {
|
|
30
|
+
AIFeatures,
|
|
31
|
+
ConsoleDestination,
|
|
32
|
+
DEFAULT_LEVELS,
|
|
33
|
+
EXTENDED_LEVELS,
|
|
34
|
+
FileDestination,
|
|
35
|
+
LOG_LEVELS,
|
|
36
|
+
Logger,
|
|
37
|
+
ObserveDestination,
|
|
38
|
+
REDACTED,
|
|
39
|
+
SCRUB_PATTERNS,
|
|
40
|
+
SENSITIVE_KEYS,
|
|
41
|
+
Scrubber,
|
|
42
|
+
audit,
|
|
43
|
+
debug,
|
|
44
|
+
error,
|
|
45
|
+
fatal,
|
|
46
|
+
formatJson,
|
|
47
|
+
formatJsonPretty,
|
|
48
|
+
formatPretty,
|
|
49
|
+
getConsoleMethod,
|
|
50
|
+
getDefaultLogger,
|
|
51
|
+
info,
|
|
52
|
+
isSensitiveKey,
|
|
53
|
+
setDefaultLogger,
|
|
54
|
+
trace,
|
|
55
|
+
warn
|
|
56
|
+
} from "./chunk-7AITSJLP.mjs";
|
|
57
|
+
import "./chunk-J5AHUFP2.mjs";
|
|
26
58
|
export {
|
|
59
|
+
AIFeatures,
|
|
60
|
+
ConsoleDestination,
|
|
61
|
+
DEFAULT_LEVELS,
|
|
62
|
+
EXTENDED_LEVELS,
|
|
63
|
+
FileDestination,
|
|
64
|
+
LOG_LEVELS,
|
|
65
|
+
Logger,
|
|
66
|
+
ObserveDestination,
|
|
67
|
+
REDACTED,
|
|
68
|
+
SCRUB_PATTERNS,
|
|
69
|
+
SENSITIVE_KEYS,
|
|
70
|
+
Scrubber,
|
|
27
71
|
Statly,
|
|
28
72
|
StatlyClient,
|
|
29
73
|
addBreadcrumb,
|
|
30
74
|
captureException,
|
|
31
75
|
captureMessage,
|
|
32
76
|
captureNextJsError,
|
|
77
|
+
captureSpan,
|
|
33
78
|
close,
|
|
34
79
|
createRequestCapture,
|
|
35
80
|
expressErrorHandler,
|
|
36
81
|
flush,
|
|
82
|
+
formatJson,
|
|
83
|
+
formatJsonPretty,
|
|
84
|
+
formatPretty,
|
|
37
85
|
getClient,
|
|
86
|
+
getConsoleMethod,
|
|
87
|
+
getDefaultLogger,
|
|
38
88
|
init,
|
|
89
|
+
isSensitiveKey,
|
|
90
|
+
audit as logAudit,
|
|
91
|
+
debug as logDebug,
|
|
92
|
+
error as logError,
|
|
93
|
+
fatal as logFatal,
|
|
94
|
+
info as logInfo,
|
|
95
|
+
trace as logTrace,
|
|
96
|
+
warn as logWarn,
|
|
39
97
|
requestHandler,
|
|
98
|
+
setDefaultLogger,
|
|
40
99
|
setTag,
|
|
41
100
|
setTags,
|
|
42
101
|
setUser,
|
|
102
|
+
startSpan,
|
|
43
103
|
statlyFastifyPlugin,
|
|
44
104
|
statlyPlugin,
|
|
105
|
+
trace2 as trace,
|
|
45
106
|
withStatly,
|
|
46
107
|
withStatlyGetServerSideProps,
|
|
47
108
|
withStatlyGetStaticProps,
|
|
@@ -3,6 +3,9 @@ var __defProp = Object.defineProperty;
|
|
|
3
3
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
4
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
5
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __esm = (fn, res) => function __init() {
|
|
7
|
+
return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
|
|
8
|
+
};
|
|
6
9
|
var __export = (target, all) => {
|
|
7
10
|
for (var name in all)
|
|
8
11
|
__defProp(target, name, { get: all[name], enumerable: true });
|
|
@@ -17,6 +20,155 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
17
20
|
};
|
|
18
21
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
22
|
|
|
23
|
+
// src/span.ts
|
|
24
|
+
var Span, TraceContext;
|
|
25
|
+
var init_span = __esm({
|
|
26
|
+
"src/span.ts"() {
|
|
27
|
+
"use strict";
|
|
28
|
+
Span = class {
|
|
29
|
+
constructor(name, context, tags) {
|
|
30
|
+
this._status = "ok" /* OK */;
|
|
31
|
+
this._tags = {};
|
|
32
|
+
this._metadata = {};
|
|
33
|
+
this._finished = false;
|
|
34
|
+
this.name = name;
|
|
35
|
+
this.context = context;
|
|
36
|
+
this.startTime = Date.now();
|
|
37
|
+
if (tags) this._tags = { ...tags };
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Finish the span and calculate duration
|
|
41
|
+
*/
|
|
42
|
+
finish(endTime) {
|
|
43
|
+
if (this._finished) return;
|
|
44
|
+
this._endTime = endTime || Date.now();
|
|
45
|
+
this._durationMs = this._endTime - this.startTime;
|
|
46
|
+
this._finished = true;
|
|
47
|
+
}
|
|
48
|
+
setTag(key, value) {
|
|
49
|
+
this._tags[key] = value;
|
|
50
|
+
return this;
|
|
51
|
+
}
|
|
52
|
+
setMetadata(key, value) {
|
|
53
|
+
this._metadata[key] = value;
|
|
54
|
+
return this;
|
|
55
|
+
}
|
|
56
|
+
setStatus(status) {
|
|
57
|
+
this._status = status;
|
|
58
|
+
return this;
|
|
59
|
+
}
|
|
60
|
+
get status() {
|
|
61
|
+
return this._status;
|
|
62
|
+
}
|
|
63
|
+
get tags() {
|
|
64
|
+
return { ...this._tags };
|
|
65
|
+
}
|
|
66
|
+
get durationMs() {
|
|
67
|
+
return this._durationMs;
|
|
68
|
+
}
|
|
69
|
+
toDict() {
|
|
70
|
+
return {
|
|
71
|
+
name: this.name,
|
|
72
|
+
traceId: this.context.traceId,
|
|
73
|
+
spanId: this.context.spanId,
|
|
74
|
+
parentId: this.context.parentId,
|
|
75
|
+
startTime: this.startTime,
|
|
76
|
+
endTime: this._endTime,
|
|
77
|
+
durationMs: this._durationMs,
|
|
78
|
+
status: this._status,
|
|
79
|
+
tags: this._tags,
|
|
80
|
+
metadata: this._metadata
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
};
|
|
84
|
+
TraceContext = class {
|
|
85
|
+
static getActiveSpan() {
|
|
86
|
+
return this.currentSpan;
|
|
87
|
+
}
|
|
88
|
+
static setActiveSpan(span) {
|
|
89
|
+
this.currentSpan = span;
|
|
90
|
+
}
|
|
91
|
+
};
|
|
92
|
+
TraceContext.currentSpan = null;
|
|
93
|
+
}
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
// src/telemetry.ts
|
|
97
|
+
var telemetry_exports = {};
|
|
98
|
+
__export(telemetry_exports, {
|
|
99
|
+
TelemetryProvider: () => TelemetryProvider,
|
|
100
|
+
trace: () => trace
|
|
101
|
+
});
|
|
102
|
+
async function trace(name, operation, tags) {
|
|
103
|
+
const provider = TelemetryProvider.getInstance();
|
|
104
|
+
const span = provider.startSpan(name, tags);
|
|
105
|
+
try {
|
|
106
|
+
const result = await operation(span);
|
|
107
|
+
return result;
|
|
108
|
+
} catch (error2) {
|
|
109
|
+
span.setStatus("error" /* ERROR */);
|
|
110
|
+
span.setTag("error", "true");
|
|
111
|
+
if (error2 instanceof Error) {
|
|
112
|
+
span.setTag("exception.type", error2.name);
|
|
113
|
+
span.setTag("exception.message", error2.message);
|
|
114
|
+
}
|
|
115
|
+
throw error2;
|
|
116
|
+
} finally {
|
|
117
|
+
provider.finishSpan(span);
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
var TelemetryProvider;
|
|
121
|
+
var init_telemetry = __esm({
|
|
122
|
+
"src/telemetry.ts"() {
|
|
123
|
+
"use strict";
|
|
124
|
+
init_span();
|
|
125
|
+
TelemetryProvider = class _TelemetryProvider {
|
|
126
|
+
constructor() {
|
|
127
|
+
this.client = null;
|
|
128
|
+
}
|
|
129
|
+
static getInstance() {
|
|
130
|
+
if (!_TelemetryProvider.instance) {
|
|
131
|
+
_TelemetryProvider.instance = new _TelemetryProvider();
|
|
132
|
+
}
|
|
133
|
+
return _TelemetryProvider.instance;
|
|
134
|
+
}
|
|
135
|
+
setClient(client2) {
|
|
136
|
+
this.client = client2;
|
|
137
|
+
}
|
|
138
|
+
/**
|
|
139
|
+
* Start a new span
|
|
140
|
+
*/
|
|
141
|
+
startSpan(name, tags) {
|
|
142
|
+
const parent = TraceContext.getActiveSpan();
|
|
143
|
+
const traceId = parent ? parent.context.traceId : this.generateId();
|
|
144
|
+
const parentId = parent ? parent.context.spanId : null;
|
|
145
|
+
const span = new Span(name, {
|
|
146
|
+
traceId,
|
|
147
|
+
spanId: this.generateId(),
|
|
148
|
+
parentId
|
|
149
|
+
}, tags);
|
|
150
|
+
TraceContext.setActiveSpan(span);
|
|
151
|
+
return span;
|
|
152
|
+
}
|
|
153
|
+
/**
|
|
154
|
+
* Finish and report a span
|
|
155
|
+
*/
|
|
156
|
+
finishSpan(span) {
|
|
157
|
+
span.finish();
|
|
158
|
+
if (TraceContext.getActiveSpan() === span) {
|
|
159
|
+
TraceContext.setActiveSpan(null);
|
|
160
|
+
}
|
|
161
|
+
if (this.client) {
|
|
162
|
+
this.client.captureSpan(span);
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
generateId() {
|
|
166
|
+
return Math.random().toString(16).substring(2, 18);
|
|
167
|
+
}
|
|
168
|
+
};
|
|
169
|
+
}
|
|
170
|
+
});
|
|
171
|
+
|
|
20
172
|
// src/integrations/express.ts
|
|
21
173
|
var express_exports = {};
|
|
22
174
|
__export(express_exports, {
|
|
@@ -85,10 +237,10 @@ var Transport = class {
|
|
|
85
237
|
this.queue = [];
|
|
86
238
|
try {
|
|
87
239
|
await this.sendBatch(events);
|
|
88
|
-
} catch (
|
|
240
|
+
} catch (error2) {
|
|
89
241
|
this.queue = [...events, ...this.queue].slice(0, this.maxQueueSize);
|
|
90
242
|
if (this.debug) {
|
|
91
|
-
console.error("[Statly] Failed to send events:",
|
|
243
|
+
console.error("[Statly] Failed to send events:", error2);
|
|
92
244
|
}
|
|
93
245
|
} finally {
|
|
94
246
|
this.isSending = false;
|
|
@@ -128,13 +280,13 @@ var Transport = class {
|
|
|
128
280
|
console.log(`[Statly] Sent ${events.length} event(s)`);
|
|
129
281
|
}
|
|
130
282
|
return { success: true, status: response.status };
|
|
131
|
-
} catch (
|
|
283
|
+
} catch (error2) {
|
|
132
284
|
if (this.debug) {
|
|
133
|
-
console.error("[Statly] Network error:",
|
|
285
|
+
console.error("[Statly] Network error:", error2);
|
|
134
286
|
}
|
|
135
287
|
return {
|
|
136
288
|
success: false,
|
|
137
|
-
error:
|
|
289
|
+
error: error2 instanceof Error ? error2.message : "Network error"
|
|
138
290
|
};
|
|
139
291
|
}
|
|
140
292
|
}
|
|
@@ -201,16 +353,16 @@ var GlobalHandlers = class {
|
|
|
201
353
|
if (!this.errorCallback) {
|
|
202
354
|
return;
|
|
203
355
|
}
|
|
204
|
-
let
|
|
356
|
+
let error2;
|
|
205
357
|
if (event.reason instanceof Error) {
|
|
206
|
-
|
|
358
|
+
error2 = event.reason;
|
|
207
359
|
} else if (typeof event.reason === "string") {
|
|
208
|
-
|
|
360
|
+
error2 = new Error(event.reason);
|
|
209
361
|
} else {
|
|
210
|
-
|
|
211
|
-
|
|
362
|
+
error2 = new Error("Unhandled Promise Rejection");
|
|
363
|
+
error2.reason = event.reason;
|
|
212
364
|
}
|
|
213
|
-
this.errorCallback(
|
|
365
|
+
this.errorCallback(error2, {
|
|
214
366
|
mechanism: { type: "onunhandledrejection", handled: false }
|
|
215
367
|
});
|
|
216
368
|
};
|
|
@@ -253,13 +405,13 @@ var GlobalHandlers = class {
|
|
|
253
405
|
}
|
|
254
406
|
installOnError() {
|
|
255
407
|
this.originalOnError = window.onerror;
|
|
256
|
-
window.onerror = (message, source, lineno, colno,
|
|
408
|
+
window.onerror = (message, source, lineno, colno, error2) => {
|
|
257
409
|
if (this.originalOnError) {
|
|
258
|
-
this.originalOnError.call(window, message, source, lineno, colno,
|
|
410
|
+
this.originalOnError.call(window, message, source, lineno, colno, error2);
|
|
259
411
|
}
|
|
260
412
|
if (this.errorCallback) {
|
|
261
|
-
const errorObj =
|
|
262
|
-
if (!
|
|
413
|
+
const errorObj = error2 || new Error(String(message));
|
|
414
|
+
if (!error2 && source) {
|
|
263
415
|
errorObj.filename = source;
|
|
264
416
|
errorObj.lineno = lineno;
|
|
265
417
|
errorObj.colno = colno;
|
|
@@ -369,6 +521,7 @@ var ConsoleIntegration = class {
|
|
|
369
521
|
};
|
|
370
522
|
|
|
371
523
|
// src/client.ts
|
|
524
|
+
init_telemetry();
|
|
372
525
|
var SDK_NAME = "@statly/observe-sdk";
|
|
373
526
|
var SDK_VERSION = "0.1.0";
|
|
374
527
|
var StatlyClient = class {
|
|
@@ -383,6 +536,7 @@ var StatlyClient = class {
|
|
|
383
536
|
this.breadcrumbs = new BreadcrumbManager(this.options.maxBreadcrumbs);
|
|
384
537
|
this.globalHandlers = new GlobalHandlers();
|
|
385
538
|
this.consoleIntegration = new ConsoleIntegration();
|
|
539
|
+
TelemetryProvider.getInstance().setClient(this);
|
|
386
540
|
}
|
|
387
541
|
mergeOptions(options) {
|
|
388
542
|
return {
|
|
@@ -422,8 +576,8 @@ var StatlyClient = class {
|
|
|
422
576
|
}
|
|
423
577
|
this.initialized = true;
|
|
424
578
|
if (this.options.autoCapture) {
|
|
425
|
-
this.globalHandlers.install((
|
|
426
|
-
this.captureError(
|
|
579
|
+
this.globalHandlers.install((error2, context) => {
|
|
580
|
+
this.captureError(error2, context);
|
|
427
581
|
});
|
|
428
582
|
}
|
|
429
583
|
if (this.options.captureConsole) {
|
|
@@ -446,15 +600,15 @@ var StatlyClient = class {
|
|
|
446
600
|
/**
|
|
447
601
|
* Capture an exception/error
|
|
448
602
|
*/
|
|
449
|
-
captureException(
|
|
603
|
+
captureException(error2, context) {
|
|
450
604
|
let errorObj;
|
|
451
|
-
if (
|
|
452
|
-
errorObj =
|
|
453
|
-
} else if (typeof
|
|
454
|
-
errorObj = new Error(
|
|
605
|
+
if (error2 instanceof Error) {
|
|
606
|
+
errorObj = error2;
|
|
607
|
+
} else if (typeof error2 === "string") {
|
|
608
|
+
errorObj = new Error(error2);
|
|
455
609
|
} else {
|
|
456
610
|
errorObj = new Error("Unknown error");
|
|
457
|
-
errorObj.originalError =
|
|
611
|
+
errorObj.originalError = error2;
|
|
458
612
|
}
|
|
459
613
|
return this.captureError(errorObj, context);
|
|
460
614
|
}
|
|
@@ -468,21 +622,45 @@ var StatlyClient = class {
|
|
|
468
622
|
});
|
|
469
623
|
return this.sendEvent(event);
|
|
470
624
|
}
|
|
625
|
+
/**
|
|
626
|
+
* Capture a completed span
|
|
627
|
+
*/
|
|
628
|
+
captureSpan(span) {
|
|
629
|
+
const event = this.buildEvent({
|
|
630
|
+
message: `Span: ${span.name}`,
|
|
631
|
+
level: "span",
|
|
632
|
+
span: span.toDict()
|
|
633
|
+
});
|
|
634
|
+
return this.sendEvent(event);
|
|
635
|
+
}
|
|
636
|
+
/**
|
|
637
|
+
* Start a new tracing span
|
|
638
|
+
*/
|
|
639
|
+
startSpan(name, tags) {
|
|
640
|
+
return TelemetryProvider.getInstance().startSpan(name, tags);
|
|
641
|
+
}
|
|
642
|
+
/**
|
|
643
|
+
* Execute a function within a trace span
|
|
644
|
+
*/
|
|
645
|
+
async trace(name, operation, tags) {
|
|
646
|
+
const { trace: traceFn } = await Promise.resolve().then(() => (init_telemetry(), telemetry_exports));
|
|
647
|
+
return traceFn(name, operation, tags);
|
|
648
|
+
}
|
|
471
649
|
/**
|
|
472
650
|
* Internal method to capture an error
|
|
473
651
|
*/
|
|
474
|
-
captureError(
|
|
652
|
+
captureError(error2, context) {
|
|
475
653
|
if (Math.random() > this.options.sampleRate) {
|
|
476
654
|
return "";
|
|
477
655
|
}
|
|
478
656
|
const event = this.buildEvent({
|
|
479
|
-
message:
|
|
657
|
+
message: error2.message,
|
|
480
658
|
level: "error",
|
|
481
|
-
stack:
|
|
659
|
+
stack: error2.stack,
|
|
482
660
|
exception: {
|
|
483
|
-
type:
|
|
484
|
-
value:
|
|
485
|
-
stacktrace: this.parseStackTrace(
|
|
661
|
+
type: error2.name,
|
|
662
|
+
value: error2.message,
|
|
663
|
+
stacktrace: this.parseStackTrace(error2.stack)
|
|
486
664
|
},
|
|
487
665
|
extra: context
|
|
488
666
|
});
|
|
@@ -676,6 +854,35 @@ var StatlyClient = class {
|
|
|
676
854
|
}
|
|
677
855
|
};
|
|
678
856
|
|
|
857
|
+
// src/logger/formatters/console.ts
|
|
858
|
+
var COLORS = {
|
|
859
|
+
reset: "\x1B[0m",
|
|
860
|
+
bold: "\x1B[1m",
|
|
861
|
+
dim: "\x1B[2m",
|
|
862
|
+
// Foreground colors
|
|
863
|
+
black: "\x1B[30m",
|
|
864
|
+
red: "\x1B[31m",
|
|
865
|
+
green: "\x1B[32m",
|
|
866
|
+
yellow: "\x1B[33m",
|
|
867
|
+
blue: "\x1B[34m",
|
|
868
|
+
magenta: "\x1B[35m",
|
|
869
|
+
cyan: "\x1B[36m",
|
|
870
|
+
white: "\x1B[37m",
|
|
871
|
+
gray: "\x1B[90m",
|
|
872
|
+
// Background colors
|
|
873
|
+
bgRed: "\x1B[41m",
|
|
874
|
+
bgYellow: "\x1B[43m"
|
|
875
|
+
};
|
|
876
|
+
var LEVEL_COLORS = {
|
|
877
|
+
trace: COLORS.gray,
|
|
878
|
+
debug: COLORS.cyan,
|
|
879
|
+
info: COLORS.green,
|
|
880
|
+
warn: COLORS.yellow,
|
|
881
|
+
error: COLORS.red,
|
|
882
|
+
fatal: `${COLORS.bgRed}${COLORS.white}`,
|
|
883
|
+
audit: COLORS.magenta
|
|
884
|
+
};
|
|
885
|
+
|
|
679
886
|
// src/index.ts
|
|
680
887
|
var client = null;
|
|
681
888
|
function loadDsnFromEnv() {
|
|
@@ -710,12 +917,12 @@ function init(options) {
|
|
|
710
917
|
client = new StatlyClient(finalOptions);
|
|
711
918
|
client.init();
|
|
712
919
|
}
|
|
713
|
-
function captureException(
|
|
920
|
+
function captureException(error2, context) {
|
|
714
921
|
if (!client) {
|
|
715
922
|
console.warn("[Statly] SDK not initialized. Call Statly.init() first.");
|
|
716
923
|
return "";
|
|
717
924
|
}
|
|
718
|
-
return client.captureException(
|
|
925
|
+
return client.captureException(error2, context);
|
|
719
926
|
}
|
|
720
927
|
function captureMessage(message, level = "info") {
|
|
721
928
|
if (!client) {
|
|
@@ -768,6 +975,20 @@ async function close() {
|
|
|
768
975
|
function getClient() {
|
|
769
976
|
return client;
|
|
770
977
|
}
|
|
978
|
+
async function trace3(name, operation, tags) {
|
|
979
|
+
if (!client) {
|
|
980
|
+
return operation(null);
|
|
981
|
+
}
|
|
982
|
+
return client.trace(name, operation, tags);
|
|
983
|
+
}
|
|
984
|
+
function startSpan(name, tags) {
|
|
985
|
+
if (!client) return null;
|
|
986
|
+
return client.startSpan(name, tags);
|
|
987
|
+
}
|
|
988
|
+
function captureSpan(span) {
|
|
989
|
+
if (!client) return "";
|
|
990
|
+
return client.captureSpan(span);
|
|
991
|
+
}
|
|
771
992
|
var Statly = {
|
|
772
993
|
init,
|
|
773
994
|
captureException,
|
|
@@ -778,7 +999,10 @@ var Statly = {
|
|
|
778
999
|
addBreadcrumb,
|
|
779
1000
|
flush,
|
|
780
1001
|
close,
|
|
781
|
-
getClient
|
|
1002
|
+
getClient,
|
|
1003
|
+
trace: trace3,
|
|
1004
|
+
startSpan,
|
|
1005
|
+
captureSpan
|
|
782
1006
|
};
|
|
783
1007
|
|
|
784
1008
|
// src/integrations/express.ts
|
|
@@ -820,8 +1044,8 @@ function requestHandler() {
|
|
|
820
1044
|
}
|
|
821
1045
|
function expressErrorHandler(options = {}) {
|
|
822
1046
|
return (err, req, res, next) => {
|
|
823
|
-
const
|
|
824
|
-
if (options.shouldHandleError && !options.shouldHandleError(
|
|
1047
|
+
const error2 = err instanceof Error ? err : new Error(String(err));
|
|
1048
|
+
if (options.shouldHandleError && !options.shouldHandleError(error2)) {
|
|
825
1049
|
return next(err);
|
|
826
1050
|
}
|
|
827
1051
|
const context = {
|
|
@@ -845,7 +1069,7 @@ function expressErrorHandler(options = {}) {
|
|
|
845
1069
|
if (req.statlyContext?.transactionName) {
|
|
846
1070
|
Statly.setTag("transaction", req.statlyContext.transactionName);
|
|
847
1071
|
}
|
|
848
|
-
Statly.captureException(
|
|
1072
|
+
Statly.captureException(error2, context);
|
|
849
1073
|
next(err);
|
|
850
1074
|
};
|
|
851
1075
|
}
|