@statly/observe 1.1.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 +104 -0
- package/dist/chunk-7AITSJLP.mjs +1422 -0
- package/dist/{chunk-HYFH22G6.mjs → chunk-SJ7C46AP.mjs} +70 -70
- package/dist/index.d.mts +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1531 -75
- package/dist/index.mjs +57 -3
- package/dist/integrations/express.js +70 -41
- package/dist/integrations/express.mjs +2 -1
- package/dist/integrations/fastify.js +82 -53
- package/dist/integrations/fastify.mjs +2 -1
- package/dist/integrations/nextjs.js +85 -56
- package/dist/integrations/nextjs.mjs +2 -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/package.json +7 -2
|
@@ -62,10 +62,10 @@ var Transport = class {
|
|
|
62
62
|
this.queue = [];
|
|
63
63
|
try {
|
|
64
64
|
await this.sendBatch(events);
|
|
65
|
-
} catch (
|
|
65
|
+
} catch (error2) {
|
|
66
66
|
this.queue = [...events, ...this.queue].slice(0, this.maxQueueSize);
|
|
67
67
|
if (this.debug) {
|
|
68
|
-
console.error("[Statly] Failed to send events:",
|
|
68
|
+
console.error("[Statly] Failed to send events:", error2);
|
|
69
69
|
}
|
|
70
70
|
} finally {
|
|
71
71
|
this.isSending = false;
|
|
@@ -105,13 +105,13 @@ var Transport = class {
|
|
|
105
105
|
console.log(`[Statly] Sent ${events.length} event(s)`);
|
|
106
106
|
}
|
|
107
107
|
return { success: true, status: response.status };
|
|
108
|
-
} catch (
|
|
108
|
+
} catch (error2) {
|
|
109
109
|
if (this.debug) {
|
|
110
|
-
console.error("[Statly] Network error:",
|
|
110
|
+
console.error("[Statly] Network error:", error2);
|
|
111
111
|
}
|
|
112
112
|
return {
|
|
113
113
|
success: false,
|
|
114
|
-
error:
|
|
114
|
+
error: error2 instanceof Error ? error2.message : "Network error"
|
|
115
115
|
};
|
|
116
116
|
}
|
|
117
117
|
}
|
|
@@ -178,16 +178,16 @@ var GlobalHandlers = class {
|
|
|
178
178
|
if (!this.errorCallback) {
|
|
179
179
|
return;
|
|
180
180
|
}
|
|
181
|
-
let
|
|
181
|
+
let error2;
|
|
182
182
|
if (event.reason instanceof Error) {
|
|
183
|
-
|
|
183
|
+
error2 = event.reason;
|
|
184
184
|
} else if (typeof event.reason === "string") {
|
|
185
|
-
|
|
185
|
+
error2 = new Error(event.reason);
|
|
186
186
|
} else {
|
|
187
|
-
|
|
188
|
-
|
|
187
|
+
error2 = new Error("Unhandled Promise Rejection");
|
|
188
|
+
error2.reason = event.reason;
|
|
189
189
|
}
|
|
190
|
-
this.errorCallback(
|
|
190
|
+
this.errorCallback(error2, {
|
|
191
191
|
mechanism: { type: "onunhandledrejection", handled: false }
|
|
192
192
|
});
|
|
193
193
|
};
|
|
@@ -230,13 +230,13 @@ var GlobalHandlers = class {
|
|
|
230
230
|
}
|
|
231
231
|
installOnError() {
|
|
232
232
|
this.originalOnError = window.onerror;
|
|
233
|
-
window.onerror = (message, source, lineno, colno,
|
|
233
|
+
window.onerror = (message, source, lineno, colno, error2) => {
|
|
234
234
|
if (this.originalOnError) {
|
|
235
|
-
this.originalOnError.call(window, message, source, lineno, colno,
|
|
235
|
+
this.originalOnError.call(window, message, source, lineno, colno, error2);
|
|
236
236
|
}
|
|
237
237
|
if (this.errorCallback) {
|
|
238
|
-
const errorObj =
|
|
239
|
-
if (!
|
|
238
|
+
const errorObj = error2 || new Error(String(message));
|
|
239
|
+
if (!error2 && source) {
|
|
240
240
|
errorObj.filename = source;
|
|
241
241
|
errorObj.lineno = lineno;
|
|
242
242
|
errorObj.colno = colno;
|
|
@@ -400,8 +400,8 @@ var StatlyClient = class {
|
|
|
400
400
|
}
|
|
401
401
|
this.initialized = true;
|
|
402
402
|
if (this.options.autoCapture) {
|
|
403
|
-
this.globalHandlers.install((
|
|
404
|
-
this.captureError(
|
|
403
|
+
this.globalHandlers.install((error2, context) => {
|
|
404
|
+
this.captureError(error2, context);
|
|
405
405
|
});
|
|
406
406
|
}
|
|
407
407
|
if (this.options.captureConsole) {
|
|
@@ -424,15 +424,15 @@ var StatlyClient = class {
|
|
|
424
424
|
/**
|
|
425
425
|
* Capture an exception/error
|
|
426
426
|
*/
|
|
427
|
-
captureException(
|
|
427
|
+
captureException(error2, context) {
|
|
428
428
|
let errorObj;
|
|
429
|
-
if (
|
|
430
|
-
errorObj =
|
|
431
|
-
} else if (typeof
|
|
432
|
-
errorObj = new Error(
|
|
429
|
+
if (error2 instanceof Error) {
|
|
430
|
+
errorObj = error2;
|
|
431
|
+
} else if (typeof error2 === "string") {
|
|
432
|
+
errorObj = new Error(error2);
|
|
433
433
|
} else {
|
|
434
434
|
errorObj = new Error("Unknown error");
|
|
435
|
-
errorObj.originalError =
|
|
435
|
+
errorObj.originalError = error2;
|
|
436
436
|
}
|
|
437
437
|
return this.captureError(errorObj, context);
|
|
438
438
|
}
|
|
@@ -473,18 +473,18 @@ var StatlyClient = class {
|
|
|
473
473
|
/**
|
|
474
474
|
* Internal method to capture an error
|
|
475
475
|
*/
|
|
476
|
-
captureError(
|
|
476
|
+
captureError(error2, context) {
|
|
477
477
|
if (Math.random() > this.options.sampleRate) {
|
|
478
478
|
return "";
|
|
479
479
|
}
|
|
480
480
|
const event = this.buildEvent({
|
|
481
|
-
message:
|
|
481
|
+
message: error2.message,
|
|
482
482
|
level: "error",
|
|
483
|
-
stack:
|
|
483
|
+
stack: error2.stack,
|
|
484
484
|
exception: {
|
|
485
|
-
type:
|
|
486
|
-
value:
|
|
487
|
-
stacktrace: this.parseStackTrace(
|
|
485
|
+
type: error2.name,
|
|
486
|
+
value: error2.message,
|
|
487
|
+
stacktrace: this.parseStackTrace(error2.stack)
|
|
488
488
|
},
|
|
489
489
|
extra: context
|
|
490
490
|
});
|
|
@@ -697,7 +697,7 @@ function withStatlyPagesApi(handler) {
|
|
|
697
697
|
try {
|
|
698
698
|
const result = await handler(req, res);
|
|
699
699
|
return result;
|
|
700
|
-
} catch (
|
|
700
|
+
} catch (error2) {
|
|
701
701
|
const context = {
|
|
702
702
|
request: {
|
|
703
703
|
method: req.method,
|
|
@@ -706,8 +706,8 @@ function withStatlyPagesApi(handler) {
|
|
|
706
706
|
query: req.query
|
|
707
707
|
}
|
|
708
708
|
};
|
|
709
|
-
Statly.captureException(
|
|
710
|
-
throw
|
|
709
|
+
Statly.captureException(error2, context);
|
|
710
|
+
throw error2;
|
|
711
711
|
}
|
|
712
712
|
});
|
|
713
713
|
};
|
|
@@ -733,7 +733,7 @@ function withStatly(handler) {
|
|
|
733
733
|
span.setTag("http.status_code", result.status.toString());
|
|
734
734
|
}
|
|
735
735
|
return result;
|
|
736
|
-
} catch (
|
|
736
|
+
} catch (error2) {
|
|
737
737
|
const headers = {};
|
|
738
738
|
request.headers.forEach((value, key) => {
|
|
739
739
|
headers[key] = value;
|
|
@@ -752,17 +752,17 @@ function withStatly(handler) {
|
|
|
752
752
|
} catch {
|
|
753
753
|
}
|
|
754
754
|
}
|
|
755
|
-
Statly.captureException(
|
|
756
|
-
throw
|
|
755
|
+
Statly.captureException(error2, errorContext);
|
|
756
|
+
throw error2;
|
|
757
757
|
}
|
|
758
758
|
});
|
|
759
759
|
};
|
|
760
760
|
return wrappedHandler;
|
|
761
761
|
}
|
|
762
|
-
function captureNextJsError(
|
|
763
|
-
return Statly.captureException(
|
|
762
|
+
function captureNextJsError(error2, context) {
|
|
763
|
+
return Statly.captureException(error2, {
|
|
764
764
|
...context,
|
|
765
|
-
digest:
|
|
765
|
+
digest: error2.digest,
|
|
766
766
|
source: "nextjs-error-boundary"
|
|
767
767
|
});
|
|
768
768
|
}
|
|
@@ -770,12 +770,12 @@ function withStatlyGetServerSideProps(handler) {
|
|
|
770
770
|
return async (context) => {
|
|
771
771
|
try {
|
|
772
772
|
return await handler(context);
|
|
773
|
-
} catch (
|
|
774
|
-
Statly.captureException(
|
|
773
|
+
} catch (error2) {
|
|
774
|
+
Statly.captureException(error2, {
|
|
775
775
|
source: "getServerSideProps",
|
|
776
776
|
url: context.req?.url || context.resolvedUrl
|
|
777
777
|
});
|
|
778
|
-
throw
|
|
778
|
+
throw error2;
|
|
779
779
|
}
|
|
780
780
|
};
|
|
781
781
|
}
|
|
@@ -783,12 +783,12 @@ function withStatlyGetStaticProps(handler) {
|
|
|
783
783
|
return async (context) => {
|
|
784
784
|
try {
|
|
785
785
|
return await handler(context);
|
|
786
|
-
} catch (
|
|
787
|
-
Statly.captureException(
|
|
786
|
+
} catch (error2) {
|
|
787
|
+
Statly.captureException(error2, {
|
|
788
788
|
source: "getStaticProps",
|
|
789
789
|
params: context.params
|
|
790
790
|
});
|
|
791
|
-
throw
|
|
791
|
+
throw error2;
|
|
792
792
|
}
|
|
793
793
|
};
|
|
794
794
|
}
|
|
@@ -804,12 +804,12 @@ function withStatlyServerAction(action, actionName) {
|
|
|
804
804
|
});
|
|
805
805
|
try {
|
|
806
806
|
return await action(...args);
|
|
807
|
-
} catch (
|
|
808
|
-
Statly.captureException(
|
|
807
|
+
} catch (error2) {
|
|
808
|
+
Statly.captureException(error2, {
|
|
809
809
|
source: "server-action",
|
|
810
810
|
actionName
|
|
811
811
|
});
|
|
812
|
-
throw
|
|
812
|
+
throw error2;
|
|
813
813
|
}
|
|
814
814
|
});
|
|
815
815
|
};
|
|
@@ -864,16 +864,16 @@ function statlyFastifyPlugin(fastify, options, done) {
|
|
|
864
864
|
});
|
|
865
865
|
hookDone();
|
|
866
866
|
});
|
|
867
|
-
fastify.setErrorHandler((
|
|
868
|
-
const statusCode =
|
|
867
|
+
fastify.setErrorHandler((error2, request, reply) => {
|
|
868
|
+
const statusCode = error2.statusCode || 500;
|
|
869
869
|
if (skipStatusCodes.includes(statusCode)) {
|
|
870
|
-
throw
|
|
870
|
+
throw error2;
|
|
871
871
|
}
|
|
872
|
-
if (!captureValidationErrors &&
|
|
873
|
-
throw
|
|
872
|
+
if (!captureValidationErrors && error2.validation) {
|
|
873
|
+
throw error2;
|
|
874
874
|
}
|
|
875
|
-
if (shouldCapture && !shouldCapture(
|
|
876
|
-
throw
|
|
875
|
+
if (shouldCapture && !shouldCapture(error2)) {
|
|
876
|
+
throw error2;
|
|
877
877
|
}
|
|
878
878
|
const context = {
|
|
879
879
|
request: {
|
|
@@ -886,27 +886,27 @@ function statlyFastifyPlugin(fastify, options, done) {
|
|
|
886
886
|
params: request.params
|
|
887
887
|
},
|
|
888
888
|
error: {
|
|
889
|
-
statusCode:
|
|
890
|
-
code:
|
|
889
|
+
statusCode: error2.statusCode,
|
|
890
|
+
code: error2.code
|
|
891
891
|
}
|
|
892
892
|
};
|
|
893
893
|
if (request.ip) {
|
|
894
894
|
context.ip = request.ip;
|
|
895
895
|
}
|
|
896
|
-
if (
|
|
897
|
-
context.validation =
|
|
896
|
+
if (error2.validation) {
|
|
897
|
+
context.validation = error2.validation;
|
|
898
898
|
}
|
|
899
899
|
Statly.setTag("http.method", request.method);
|
|
900
900
|
Statly.setTag("http.url", request.routerPath || request.url);
|
|
901
901
|
Statly.setTag("http.status_code", String(statusCode));
|
|
902
|
-
Statly.captureException(
|
|
903
|
-
throw
|
|
902
|
+
Statly.captureException(error2, context);
|
|
903
|
+
throw error2;
|
|
904
904
|
});
|
|
905
905
|
done();
|
|
906
906
|
}
|
|
907
907
|
var statlyPlugin = statlyFastifyPlugin;
|
|
908
908
|
function createRequestCapture(request) {
|
|
909
|
-
return (
|
|
909
|
+
return (error2, additionalContext) => {
|
|
910
910
|
const context = {
|
|
911
911
|
request: {
|
|
912
912
|
id: request.id,
|
|
@@ -916,7 +916,7 @@ function createRequestCapture(request) {
|
|
|
916
916
|
},
|
|
917
917
|
...additionalContext
|
|
918
918
|
};
|
|
919
|
-
return Statly.captureException(
|
|
919
|
+
return Statly.captureException(error2, context);
|
|
920
920
|
};
|
|
921
921
|
}
|
|
922
922
|
function sanitizeHeaders2(headers) {
|
|
@@ -966,12 +966,12 @@ function init(options) {
|
|
|
966
966
|
client = new StatlyClient(finalOptions);
|
|
967
967
|
client.init();
|
|
968
968
|
}
|
|
969
|
-
function captureException(
|
|
969
|
+
function captureException(error2, context) {
|
|
970
970
|
if (!client) {
|
|
971
971
|
console.warn("[Statly] SDK not initialized. Call Statly.init() first.");
|
|
972
972
|
return "";
|
|
973
973
|
}
|
|
974
|
-
return client.captureException(
|
|
974
|
+
return client.captureException(error2, context);
|
|
975
975
|
}
|
|
976
976
|
function captureMessage(message, level = "info") {
|
|
977
977
|
if (!client) {
|
|
@@ -1024,7 +1024,7 @@ async function close() {
|
|
|
1024
1024
|
function getClient() {
|
|
1025
1025
|
return client;
|
|
1026
1026
|
}
|
|
1027
|
-
async function
|
|
1027
|
+
async function trace2(name, operation, tags) {
|
|
1028
1028
|
if (!client) {
|
|
1029
1029
|
return operation(null);
|
|
1030
1030
|
}
|
|
@@ -1049,7 +1049,7 @@ var Statly = {
|
|
|
1049
1049
|
flush,
|
|
1050
1050
|
close,
|
|
1051
1051
|
getClient,
|
|
1052
|
-
trace,
|
|
1052
|
+
trace: trace2,
|
|
1053
1053
|
startSpan,
|
|
1054
1054
|
captureSpan
|
|
1055
1055
|
};
|
|
@@ -1093,8 +1093,8 @@ function requestHandler() {
|
|
|
1093
1093
|
}
|
|
1094
1094
|
function expressErrorHandler(options = {}) {
|
|
1095
1095
|
return (err, req, res, next) => {
|
|
1096
|
-
const
|
|
1097
|
-
if (options.shouldHandleError && !options.shouldHandleError(
|
|
1096
|
+
const error2 = err instanceof Error ? err : new Error(String(err));
|
|
1097
|
+
if (options.shouldHandleError && !options.shouldHandleError(error2)) {
|
|
1098
1098
|
return next(err);
|
|
1099
1099
|
}
|
|
1100
1100
|
const context = {
|
|
@@ -1118,7 +1118,7 @@ function expressErrorHandler(options = {}) {
|
|
|
1118
1118
|
if (req.statlyContext?.transactionName) {
|
|
1119
1119
|
Statly.setTag("transaction", req.statlyContext.transactionName);
|
|
1120
1120
|
}
|
|
1121
|
-
Statly.captureException(
|
|
1121
|
+
Statly.captureException(error2, context);
|
|
1122
1122
|
next(err);
|
|
1123
1123
|
};
|
|
1124
1124
|
}
|
|
@@ -1175,7 +1175,7 @@ export {
|
|
|
1175
1175
|
flush,
|
|
1176
1176
|
close,
|
|
1177
1177
|
getClient,
|
|
1178
|
-
trace,
|
|
1178
|
+
trace2 as trace,
|
|
1179
1179
|
startSpan,
|
|
1180
1180
|
captureSpan,
|
|
1181
1181
|
Statly
|
package/dist/index.d.mts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
export { expressErrorHandler, requestHandler } from './integrations/express.mjs';
|
|
2
2
|
export { captureNextJsError, withStatly, withStatlyGetServerSideProps, withStatlyGetStaticProps, withStatlyPagesApi, withStatlyServerAction } from './integrations/nextjs.mjs';
|
|
3
3
|
export { createRequestCapture, statlyFastifyPlugin, statlyPlugin } from './integrations/fastify.mjs';
|
|
4
|
+
export { AIFeatures, ConsoleDestination, ConsoleDestinationConfig, DEFAULT_LEVELS, Destination, EXTENDED_LEVELS, ErrorExplanation, FileDestination, FileDestinationConfig, FileRotationConfig, FixSuggestion, LOG_LEVELS, LevelSet, LogEntry, LogLevel, Logger, LoggerConfig, ObserveDestination, ObserveDestinationConfig, REDACTED, SCRUB_PATTERNS, SENSITIVE_KEYS, ScrubPattern, Scrubber, ScrubbingConfig, formatJson, formatJsonPretty, formatPretty, getConsoleMethod, getDefaultLogger, isSensitiveKey, audit as logAudit, debug as logDebug, error as logError, fatal as logFatal, info as logInfo, trace as logTrace, warn as logWarn, setDefaultLogger } from './logger/index.mjs';
|
|
4
5
|
|
|
5
6
|
/**
|
|
6
7
|
* Span module for Statly Observe SDK
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
export { expressErrorHandler, requestHandler } from './integrations/express.js';
|
|
2
2
|
export { captureNextJsError, withStatly, withStatlyGetServerSideProps, withStatlyGetStaticProps, withStatlyPagesApi, withStatlyServerAction } from './integrations/nextjs.js';
|
|
3
3
|
export { createRequestCapture, statlyFastifyPlugin, statlyPlugin } from './integrations/fastify.js';
|
|
4
|
+
export { AIFeatures, ConsoleDestination, ConsoleDestinationConfig, DEFAULT_LEVELS, Destination, EXTENDED_LEVELS, ErrorExplanation, FileDestination, FileDestinationConfig, FileRotationConfig, FixSuggestion, LOG_LEVELS, LevelSet, LogEntry, LogLevel, Logger, LoggerConfig, ObserveDestination, ObserveDestinationConfig, REDACTED, SCRUB_PATTERNS, SENSITIVE_KEYS, ScrubPattern, Scrubber, ScrubbingConfig, formatJson, formatJsonPretty, formatPretty, getConsoleMethod, getDefaultLogger, isSensitiveKey, audit as logAudit, debug as logDebug, error as logError, fatal as logFatal, info as logInfo, trace as logTrace, warn as logWarn, setDefaultLogger } from './logger/index.js';
|
|
4
5
|
|
|
5
6
|
/**
|
|
6
7
|
* Span module for Statly Observe SDK
|