@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/dist/index.mjs CHANGED
@@ -19,15 +19,55 @@ import {
19
19
  startSpan,
20
20
  statlyFastifyPlugin,
21
21
  statlyPlugin,
22
- trace,
22
+ trace as trace2,
23
23
  withStatly,
24
24
  withStatlyGetServerSideProps,
25
25
  withStatlyGetStaticProps,
26
26
  withStatlyPagesApi,
27
27
  withStatlyServerAction
28
- } from "./chunk-HYFH22G6.mjs";
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";
29
57
  import "./chunk-J5AHUFP2.mjs";
30
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,
31
71
  Statly,
32
72
  StatlyClient,
33
73
  addBreadcrumb,
@@ -39,16 +79,30 @@ export {
39
79
  createRequestCapture,
40
80
  expressErrorHandler,
41
81
  flush,
82
+ formatJson,
83
+ formatJsonPretty,
84
+ formatPretty,
42
85
  getClient,
86
+ getConsoleMethod,
87
+ getDefaultLogger,
43
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,
44
97
  requestHandler,
98
+ setDefaultLogger,
45
99
  setTag,
46
100
  setTags,
47
101
  setUser,
48
102
  startSpan,
49
103
  statlyFastifyPlugin,
50
104
  statlyPlugin,
51
- trace,
105
+ trace2 as trace,
52
106
  withStatly,
53
107
  withStatlyGetServerSideProps,
54
108
  withStatlyGetStaticProps,
@@ -105,14 +105,14 @@ async function trace(name, operation, tags) {
105
105
  try {
106
106
  const result = await operation(span);
107
107
  return result;
108
- } catch (error) {
108
+ } catch (error2) {
109
109
  span.setStatus("error" /* ERROR */);
110
110
  span.setTag("error", "true");
111
- if (error instanceof Error) {
112
- span.setTag("exception.type", error.name);
113
- span.setTag("exception.message", error.message);
111
+ if (error2 instanceof Error) {
112
+ span.setTag("exception.type", error2.name);
113
+ span.setTag("exception.message", error2.message);
114
114
  }
115
- throw error;
115
+ throw error2;
116
116
  } finally {
117
117
  provider.finishSpan(span);
118
118
  }
@@ -237,10 +237,10 @@ var Transport = class {
237
237
  this.queue = [];
238
238
  try {
239
239
  await this.sendBatch(events);
240
- } catch (error) {
240
+ } catch (error2) {
241
241
  this.queue = [...events, ...this.queue].slice(0, this.maxQueueSize);
242
242
  if (this.debug) {
243
- console.error("[Statly] Failed to send events:", error);
243
+ console.error("[Statly] Failed to send events:", error2);
244
244
  }
245
245
  } finally {
246
246
  this.isSending = false;
@@ -280,13 +280,13 @@ var Transport = class {
280
280
  console.log(`[Statly] Sent ${events.length} event(s)`);
281
281
  }
282
282
  return { success: true, status: response.status };
283
- } catch (error) {
283
+ } catch (error2) {
284
284
  if (this.debug) {
285
- console.error("[Statly] Network error:", error);
285
+ console.error("[Statly] Network error:", error2);
286
286
  }
287
287
  return {
288
288
  success: false,
289
- error: error instanceof Error ? error.message : "Network error"
289
+ error: error2 instanceof Error ? error2.message : "Network error"
290
290
  };
291
291
  }
292
292
  }
@@ -353,16 +353,16 @@ var GlobalHandlers = class {
353
353
  if (!this.errorCallback) {
354
354
  return;
355
355
  }
356
- let error;
356
+ let error2;
357
357
  if (event.reason instanceof Error) {
358
- error = event.reason;
358
+ error2 = event.reason;
359
359
  } else if (typeof event.reason === "string") {
360
- error = new Error(event.reason);
360
+ error2 = new Error(event.reason);
361
361
  } else {
362
- error = new Error("Unhandled Promise Rejection");
363
- error.reason = event.reason;
362
+ error2 = new Error("Unhandled Promise Rejection");
363
+ error2.reason = event.reason;
364
364
  }
365
- this.errorCallback(error, {
365
+ this.errorCallback(error2, {
366
366
  mechanism: { type: "onunhandledrejection", handled: false }
367
367
  });
368
368
  };
@@ -405,13 +405,13 @@ var GlobalHandlers = class {
405
405
  }
406
406
  installOnError() {
407
407
  this.originalOnError = window.onerror;
408
- window.onerror = (message, source, lineno, colno, error) => {
408
+ window.onerror = (message, source, lineno, colno, error2) => {
409
409
  if (this.originalOnError) {
410
- this.originalOnError.call(window, message, source, lineno, colno, error);
410
+ this.originalOnError.call(window, message, source, lineno, colno, error2);
411
411
  }
412
412
  if (this.errorCallback) {
413
- const errorObj = error || new Error(String(message));
414
- if (!error && source) {
413
+ const errorObj = error2 || new Error(String(message));
414
+ if (!error2 && source) {
415
415
  errorObj.filename = source;
416
416
  errorObj.lineno = lineno;
417
417
  errorObj.colno = colno;
@@ -576,8 +576,8 @@ var StatlyClient = class {
576
576
  }
577
577
  this.initialized = true;
578
578
  if (this.options.autoCapture) {
579
- this.globalHandlers.install((error, context) => {
580
- this.captureError(error, context);
579
+ this.globalHandlers.install((error2, context) => {
580
+ this.captureError(error2, context);
581
581
  });
582
582
  }
583
583
  if (this.options.captureConsole) {
@@ -600,15 +600,15 @@ var StatlyClient = class {
600
600
  /**
601
601
  * Capture an exception/error
602
602
  */
603
- captureException(error, context) {
603
+ captureException(error2, context) {
604
604
  let errorObj;
605
- if (error instanceof Error) {
606
- errorObj = error;
607
- } else if (typeof error === "string") {
608
- errorObj = new Error(error);
605
+ if (error2 instanceof Error) {
606
+ errorObj = error2;
607
+ } else if (typeof error2 === "string") {
608
+ errorObj = new Error(error2);
609
609
  } else {
610
610
  errorObj = new Error("Unknown error");
611
- errorObj.originalError = error;
611
+ errorObj.originalError = error2;
612
612
  }
613
613
  return this.captureError(errorObj, context);
614
614
  }
@@ -649,18 +649,18 @@ var StatlyClient = class {
649
649
  /**
650
650
  * Internal method to capture an error
651
651
  */
652
- captureError(error, context) {
652
+ captureError(error2, context) {
653
653
  if (Math.random() > this.options.sampleRate) {
654
654
  return "";
655
655
  }
656
656
  const event = this.buildEvent({
657
- message: error.message,
657
+ message: error2.message,
658
658
  level: "error",
659
- stack: error.stack,
659
+ stack: error2.stack,
660
660
  exception: {
661
- type: error.name,
662
- value: error.message,
663
- stacktrace: this.parseStackTrace(error.stack)
661
+ type: error2.name,
662
+ value: error2.message,
663
+ stacktrace: this.parseStackTrace(error2.stack)
664
664
  },
665
665
  extra: context
666
666
  });
@@ -854,6 +854,35 @@ var StatlyClient = class {
854
854
  }
855
855
  };
856
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
+
857
886
  // src/index.ts
858
887
  var client = null;
859
888
  function loadDsnFromEnv() {
@@ -888,12 +917,12 @@ function init(options) {
888
917
  client = new StatlyClient(finalOptions);
889
918
  client.init();
890
919
  }
891
- function captureException(error, context) {
920
+ function captureException(error2, context) {
892
921
  if (!client) {
893
922
  console.warn("[Statly] SDK not initialized. Call Statly.init() first.");
894
923
  return "";
895
924
  }
896
- return client.captureException(error, context);
925
+ return client.captureException(error2, context);
897
926
  }
898
927
  function captureMessage(message, level = "info") {
899
928
  if (!client) {
@@ -946,7 +975,7 @@ async function close() {
946
975
  function getClient() {
947
976
  return client;
948
977
  }
949
- async function trace2(name, operation, tags) {
978
+ async function trace3(name, operation, tags) {
950
979
  if (!client) {
951
980
  return operation(null);
952
981
  }
@@ -971,7 +1000,7 @@ var Statly = {
971
1000
  flush,
972
1001
  close,
973
1002
  getClient,
974
- trace: trace2,
1003
+ trace: trace3,
975
1004
  startSpan,
976
1005
  captureSpan
977
1006
  };
@@ -1015,8 +1044,8 @@ function requestHandler() {
1015
1044
  }
1016
1045
  function expressErrorHandler(options = {}) {
1017
1046
  return (err, req, res, next) => {
1018
- const error = err instanceof Error ? err : new Error(String(err));
1019
- if (options.shouldHandleError && !options.shouldHandleError(error)) {
1047
+ const error2 = err instanceof Error ? err : new Error(String(err));
1048
+ if (options.shouldHandleError && !options.shouldHandleError(error2)) {
1020
1049
  return next(err);
1021
1050
  }
1022
1051
  const context = {
@@ -1040,7 +1069,7 @@ function expressErrorHandler(options = {}) {
1040
1069
  if (req.statlyContext?.transactionName) {
1041
1070
  Statly.setTag("transaction", req.statlyContext.transactionName);
1042
1071
  }
1043
- Statly.captureException(error, context);
1072
+ Statly.captureException(error2, context);
1044
1073
  next(err);
1045
1074
  };
1046
1075
  }
@@ -1,7 +1,8 @@
1
1
  import {
2
2
  expressErrorHandler,
3
3
  requestHandler
4
- } from "../chunk-HYFH22G6.mjs";
4
+ } from "../chunk-SJ7C46AP.mjs";
5
+ import "../chunk-7AITSJLP.mjs";
5
6
  import "../chunk-J5AHUFP2.mjs";
6
7
  export {
7
8
  expressErrorHandler,
@@ -105,14 +105,14 @@ async function trace(name, operation, tags) {
105
105
  try {
106
106
  const result = await operation(span);
107
107
  return result;
108
- } catch (error) {
108
+ } catch (error2) {
109
109
  span.setStatus("error" /* ERROR */);
110
110
  span.setTag("error", "true");
111
- if (error instanceof Error) {
112
- span.setTag("exception.type", error.name);
113
- span.setTag("exception.message", error.message);
111
+ if (error2 instanceof Error) {
112
+ span.setTag("exception.type", error2.name);
113
+ span.setTag("exception.message", error2.message);
114
114
  }
115
- throw error;
115
+ throw error2;
116
116
  } finally {
117
117
  provider.finishSpan(span);
118
118
  }
@@ -238,10 +238,10 @@ var Transport = class {
238
238
  this.queue = [];
239
239
  try {
240
240
  await this.sendBatch(events);
241
- } catch (error) {
241
+ } catch (error2) {
242
242
  this.queue = [...events, ...this.queue].slice(0, this.maxQueueSize);
243
243
  if (this.debug) {
244
- console.error("[Statly] Failed to send events:", error);
244
+ console.error("[Statly] Failed to send events:", error2);
245
245
  }
246
246
  } finally {
247
247
  this.isSending = false;
@@ -281,13 +281,13 @@ var Transport = class {
281
281
  console.log(`[Statly] Sent ${events.length} event(s)`);
282
282
  }
283
283
  return { success: true, status: response.status };
284
- } catch (error) {
284
+ } catch (error2) {
285
285
  if (this.debug) {
286
- console.error("[Statly] Network error:", error);
286
+ console.error("[Statly] Network error:", error2);
287
287
  }
288
288
  return {
289
289
  success: false,
290
- error: error instanceof Error ? error.message : "Network error"
290
+ error: error2 instanceof Error ? error2.message : "Network error"
291
291
  };
292
292
  }
293
293
  }
@@ -354,16 +354,16 @@ var GlobalHandlers = class {
354
354
  if (!this.errorCallback) {
355
355
  return;
356
356
  }
357
- let error;
357
+ let error2;
358
358
  if (event.reason instanceof Error) {
359
- error = event.reason;
359
+ error2 = event.reason;
360
360
  } else if (typeof event.reason === "string") {
361
- error = new Error(event.reason);
361
+ error2 = new Error(event.reason);
362
362
  } else {
363
- error = new Error("Unhandled Promise Rejection");
364
- error.reason = event.reason;
363
+ error2 = new Error("Unhandled Promise Rejection");
364
+ error2.reason = event.reason;
365
365
  }
366
- this.errorCallback(error, {
366
+ this.errorCallback(error2, {
367
367
  mechanism: { type: "onunhandledrejection", handled: false }
368
368
  });
369
369
  };
@@ -406,13 +406,13 @@ var GlobalHandlers = class {
406
406
  }
407
407
  installOnError() {
408
408
  this.originalOnError = window.onerror;
409
- window.onerror = (message, source, lineno, colno, error) => {
409
+ window.onerror = (message, source, lineno, colno, error2) => {
410
410
  if (this.originalOnError) {
411
- this.originalOnError.call(window, message, source, lineno, colno, error);
411
+ this.originalOnError.call(window, message, source, lineno, colno, error2);
412
412
  }
413
413
  if (this.errorCallback) {
414
- const errorObj = error || new Error(String(message));
415
- if (!error && source) {
414
+ const errorObj = error2 || new Error(String(message));
415
+ if (!error2 && source) {
416
416
  errorObj.filename = source;
417
417
  errorObj.lineno = lineno;
418
418
  errorObj.colno = colno;
@@ -577,8 +577,8 @@ var StatlyClient = class {
577
577
  }
578
578
  this.initialized = true;
579
579
  if (this.options.autoCapture) {
580
- this.globalHandlers.install((error, context) => {
581
- this.captureError(error, context);
580
+ this.globalHandlers.install((error2, context) => {
581
+ this.captureError(error2, context);
582
582
  });
583
583
  }
584
584
  if (this.options.captureConsole) {
@@ -601,15 +601,15 @@ var StatlyClient = class {
601
601
  /**
602
602
  * Capture an exception/error
603
603
  */
604
- captureException(error, context) {
604
+ captureException(error2, context) {
605
605
  let errorObj;
606
- if (error instanceof Error) {
607
- errorObj = error;
608
- } else if (typeof error === "string") {
609
- errorObj = new Error(error);
606
+ if (error2 instanceof Error) {
607
+ errorObj = error2;
608
+ } else if (typeof error2 === "string") {
609
+ errorObj = new Error(error2);
610
610
  } else {
611
611
  errorObj = new Error("Unknown error");
612
- errorObj.originalError = error;
612
+ errorObj.originalError = error2;
613
613
  }
614
614
  return this.captureError(errorObj, context);
615
615
  }
@@ -650,18 +650,18 @@ var StatlyClient = class {
650
650
  /**
651
651
  * Internal method to capture an error
652
652
  */
653
- captureError(error, context) {
653
+ captureError(error2, context) {
654
654
  if (Math.random() > this.options.sampleRate) {
655
655
  return "";
656
656
  }
657
657
  const event = this.buildEvent({
658
- message: error.message,
658
+ message: error2.message,
659
659
  level: "error",
660
- stack: error.stack,
660
+ stack: error2.stack,
661
661
  exception: {
662
- type: error.name,
663
- value: error.message,
664
- stacktrace: this.parseStackTrace(error.stack)
662
+ type: error2.name,
663
+ value: error2.message,
664
+ stacktrace: this.parseStackTrace(error2.stack)
665
665
  },
666
666
  extra: context
667
667
  });
@@ -855,6 +855,35 @@ var StatlyClient = class {
855
855
  }
856
856
  };
857
857
 
858
+ // src/logger/formatters/console.ts
859
+ var COLORS = {
860
+ reset: "\x1B[0m",
861
+ bold: "\x1B[1m",
862
+ dim: "\x1B[2m",
863
+ // Foreground colors
864
+ black: "\x1B[30m",
865
+ red: "\x1B[31m",
866
+ green: "\x1B[32m",
867
+ yellow: "\x1B[33m",
868
+ blue: "\x1B[34m",
869
+ magenta: "\x1B[35m",
870
+ cyan: "\x1B[36m",
871
+ white: "\x1B[37m",
872
+ gray: "\x1B[90m",
873
+ // Background colors
874
+ bgRed: "\x1B[41m",
875
+ bgYellow: "\x1B[43m"
876
+ };
877
+ var LEVEL_COLORS = {
878
+ trace: COLORS.gray,
879
+ debug: COLORS.cyan,
880
+ info: COLORS.green,
881
+ warn: COLORS.yellow,
882
+ error: COLORS.red,
883
+ fatal: `${COLORS.bgRed}${COLORS.white}`,
884
+ audit: COLORS.magenta
885
+ };
886
+
858
887
  // src/index.ts
859
888
  var client = null;
860
889
  function loadDsnFromEnv() {
@@ -889,12 +918,12 @@ function init(options) {
889
918
  client = new StatlyClient(finalOptions);
890
919
  client.init();
891
920
  }
892
- function captureException(error, context) {
921
+ function captureException(error2, context) {
893
922
  if (!client) {
894
923
  console.warn("[Statly] SDK not initialized. Call Statly.init() first.");
895
924
  return "";
896
925
  }
897
- return client.captureException(error, context);
926
+ return client.captureException(error2, context);
898
927
  }
899
928
  function captureMessage(message, level = "info") {
900
929
  if (!client) {
@@ -947,7 +976,7 @@ async function close() {
947
976
  function getClient() {
948
977
  return client;
949
978
  }
950
- async function trace2(name, operation, tags) {
979
+ async function trace3(name, operation, tags) {
951
980
  if (!client) {
952
981
  return operation(null);
953
982
  }
@@ -972,7 +1001,7 @@ var Statly = {
972
1001
  flush,
973
1002
  close,
974
1003
  getClient,
975
- trace: trace2,
1004
+ trace: trace3,
976
1005
  startSpan,
977
1006
  captureSpan
978
1007
  };
@@ -1014,16 +1043,16 @@ function statlyFastifyPlugin(fastify, options, done) {
1014
1043
  });
1015
1044
  hookDone();
1016
1045
  });
1017
- fastify.setErrorHandler((error, request, reply) => {
1018
- const statusCode = error.statusCode || 500;
1046
+ fastify.setErrorHandler((error2, request, reply) => {
1047
+ const statusCode = error2.statusCode || 500;
1019
1048
  if (skipStatusCodes.includes(statusCode)) {
1020
- throw error;
1049
+ throw error2;
1021
1050
  }
1022
- if (!captureValidationErrors && error.validation) {
1023
- throw error;
1051
+ if (!captureValidationErrors && error2.validation) {
1052
+ throw error2;
1024
1053
  }
1025
- if (shouldCapture && !shouldCapture(error)) {
1026
- throw error;
1054
+ if (shouldCapture && !shouldCapture(error2)) {
1055
+ throw error2;
1027
1056
  }
1028
1057
  const context = {
1029
1058
  request: {
@@ -1036,27 +1065,27 @@ function statlyFastifyPlugin(fastify, options, done) {
1036
1065
  params: request.params
1037
1066
  },
1038
1067
  error: {
1039
- statusCode: error.statusCode,
1040
- code: error.code
1068
+ statusCode: error2.statusCode,
1069
+ code: error2.code
1041
1070
  }
1042
1071
  };
1043
1072
  if (request.ip) {
1044
1073
  context.ip = request.ip;
1045
1074
  }
1046
- if (error.validation) {
1047
- context.validation = error.validation;
1075
+ if (error2.validation) {
1076
+ context.validation = error2.validation;
1048
1077
  }
1049
1078
  Statly.setTag("http.method", request.method);
1050
1079
  Statly.setTag("http.url", request.routerPath || request.url);
1051
1080
  Statly.setTag("http.status_code", String(statusCode));
1052
- Statly.captureException(error, context);
1053
- throw error;
1081
+ Statly.captureException(error2, context);
1082
+ throw error2;
1054
1083
  });
1055
1084
  done();
1056
1085
  }
1057
1086
  var statlyPlugin = statlyFastifyPlugin;
1058
1087
  function createRequestCapture(request) {
1059
- return (error, additionalContext) => {
1088
+ return (error2, additionalContext) => {
1060
1089
  const context = {
1061
1090
  request: {
1062
1091
  id: request.id,
@@ -1066,7 +1095,7 @@ function createRequestCapture(request) {
1066
1095
  },
1067
1096
  ...additionalContext
1068
1097
  };
1069
- return Statly.captureException(error, context);
1098
+ return Statly.captureException(error2, context);
1070
1099
  };
1071
1100
  }
1072
1101
  function sanitizeHeaders(headers) {
@@ -2,7 +2,8 @@ import {
2
2
  createRequestCapture,
3
3
  statlyFastifyPlugin,
4
4
  statlyPlugin
5
- } from "../chunk-HYFH22G6.mjs";
5
+ } from "../chunk-SJ7C46AP.mjs";
6
+ import "../chunk-7AITSJLP.mjs";
6
7
  import "../chunk-J5AHUFP2.mjs";
7
8
  export {
8
9
  createRequestCapture,