@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.
@@ -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
  }
@@ -241,10 +241,10 @@ var Transport = class {
241
241
  this.queue = [];
242
242
  try {
243
243
  await this.sendBatch(events);
244
- } catch (error) {
244
+ } catch (error2) {
245
245
  this.queue = [...events, ...this.queue].slice(0, this.maxQueueSize);
246
246
  if (this.debug) {
247
- console.error("[Statly] Failed to send events:", error);
247
+ console.error("[Statly] Failed to send events:", error2);
248
248
  }
249
249
  } finally {
250
250
  this.isSending = false;
@@ -284,13 +284,13 @@ var Transport = class {
284
284
  console.log(`[Statly] Sent ${events.length} event(s)`);
285
285
  }
286
286
  return { success: true, status: response.status };
287
- } catch (error) {
287
+ } catch (error2) {
288
288
  if (this.debug) {
289
- console.error("[Statly] Network error:", error);
289
+ console.error("[Statly] Network error:", error2);
290
290
  }
291
291
  return {
292
292
  success: false,
293
- error: error instanceof Error ? error.message : "Network error"
293
+ error: error2 instanceof Error ? error2.message : "Network error"
294
294
  };
295
295
  }
296
296
  }
@@ -357,16 +357,16 @@ var GlobalHandlers = class {
357
357
  if (!this.errorCallback) {
358
358
  return;
359
359
  }
360
- let error;
360
+ let error2;
361
361
  if (event.reason instanceof Error) {
362
- error = event.reason;
362
+ error2 = event.reason;
363
363
  } else if (typeof event.reason === "string") {
364
- error = new Error(event.reason);
364
+ error2 = new Error(event.reason);
365
365
  } else {
366
- error = new Error("Unhandled Promise Rejection");
367
- error.reason = event.reason;
366
+ error2 = new Error("Unhandled Promise Rejection");
367
+ error2.reason = event.reason;
368
368
  }
369
- this.errorCallback(error, {
369
+ this.errorCallback(error2, {
370
370
  mechanism: { type: "onunhandledrejection", handled: false }
371
371
  });
372
372
  };
@@ -409,13 +409,13 @@ var GlobalHandlers = class {
409
409
  }
410
410
  installOnError() {
411
411
  this.originalOnError = window.onerror;
412
- window.onerror = (message, source, lineno, colno, error) => {
412
+ window.onerror = (message, source, lineno, colno, error2) => {
413
413
  if (this.originalOnError) {
414
- this.originalOnError.call(window, message, source, lineno, colno, error);
414
+ this.originalOnError.call(window, message, source, lineno, colno, error2);
415
415
  }
416
416
  if (this.errorCallback) {
417
- const errorObj = error || new Error(String(message));
418
- if (!error && source) {
417
+ const errorObj = error2 || new Error(String(message));
418
+ if (!error2 && source) {
419
419
  errorObj.filename = source;
420
420
  errorObj.lineno = lineno;
421
421
  errorObj.colno = colno;
@@ -580,8 +580,8 @@ var StatlyClient = class {
580
580
  }
581
581
  this.initialized = true;
582
582
  if (this.options.autoCapture) {
583
- this.globalHandlers.install((error, context) => {
584
- this.captureError(error, context);
583
+ this.globalHandlers.install((error2, context) => {
584
+ this.captureError(error2, context);
585
585
  });
586
586
  }
587
587
  if (this.options.captureConsole) {
@@ -604,15 +604,15 @@ var StatlyClient = class {
604
604
  /**
605
605
  * Capture an exception/error
606
606
  */
607
- captureException(error, context) {
607
+ captureException(error2, context) {
608
608
  let errorObj;
609
- if (error instanceof Error) {
610
- errorObj = error;
611
- } else if (typeof error === "string") {
612
- errorObj = new Error(error);
609
+ if (error2 instanceof Error) {
610
+ errorObj = error2;
611
+ } else if (typeof error2 === "string") {
612
+ errorObj = new Error(error2);
613
613
  } else {
614
614
  errorObj = new Error("Unknown error");
615
- errorObj.originalError = error;
615
+ errorObj.originalError = error2;
616
616
  }
617
617
  return this.captureError(errorObj, context);
618
618
  }
@@ -653,18 +653,18 @@ var StatlyClient = class {
653
653
  /**
654
654
  * Internal method to capture an error
655
655
  */
656
- captureError(error, context) {
656
+ captureError(error2, context) {
657
657
  if (Math.random() > this.options.sampleRate) {
658
658
  return "";
659
659
  }
660
660
  const event = this.buildEvent({
661
- message: error.message,
661
+ message: error2.message,
662
662
  level: "error",
663
- stack: error.stack,
663
+ stack: error2.stack,
664
664
  exception: {
665
- type: error.name,
666
- value: error.message,
667
- stacktrace: this.parseStackTrace(error.stack)
665
+ type: error2.name,
666
+ value: error2.message,
667
+ stacktrace: this.parseStackTrace(error2.stack)
668
668
  },
669
669
  extra: context
670
670
  });
@@ -858,6 +858,35 @@ var StatlyClient = class {
858
858
  }
859
859
  };
860
860
 
861
+ // src/logger/formatters/console.ts
862
+ var COLORS = {
863
+ reset: "\x1B[0m",
864
+ bold: "\x1B[1m",
865
+ dim: "\x1B[2m",
866
+ // Foreground colors
867
+ black: "\x1B[30m",
868
+ red: "\x1B[31m",
869
+ green: "\x1B[32m",
870
+ yellow: "\x1B[33m",
871
+ blue: "\x1B[34m",
872
+ magenta: "\x1B[35m",
873
+ cyan: "\x1B[36m",
874
+ white: "\x1B[37m",
875
+ gray: "\x1B[90m",
876
+ // Background colors
877
+ bgRed: "\x1B[41m",
878
+ bgYellow: "\x1B[43m"
879
+ };
880
+ var LEVEL_COLORS = {
881
+ trace: COLORS.gray,
882
+ debug: COLORS.cyan,
883
+ info: COLORS.green,
884
+ warn: COLORS.yellow,
885
+ error: COLORS.red,
886
+ fatal: `${COLORS.bgRed}${COLORS.white}`,
887
+ audit: COLORS.magenta
888
+ };
889
+
861
890
  // src/index.ts
862
891
  var client = null;
863
892
  function loadDsnFromEnv() {
@@ -892,12 +921,12 @@ function init(options) {
892
921
  client = new StatlyClient(finalOptions);
893
922
  client.init();
894
923
  }
895
- function captureException(error, context) {
924
+ function captureException(error2, context) {
896
925
  if (!client) {
897
926
  console.warn("[Statly] SDK not initialized. Call Statly.init() first.");
898
927
  return "";
899
928
  }
900
- return client.captureException(error, context);
929
+ return client.captureException(error2, context);
901
930
  }
902
931
  function captureMessage(message, level = "info") {
903
932
  if (!client) {
@@ -950,7 +979,7 @@ async function close() {
950
979
  function getClient() {
951
980
  return client;
952
981
  }
953
- async function trace2(name, operation, tags) {
982
+ async function trace3(name, operation, tags) {
954
983
  if (!client) {
955
984
  return operation(null);
956
985
  }
@@ -975,7 +1004,7 @@ var Statly = {
975
1004
  flush,
976
1005
  close,
977
1006
  getClient,
978
- trace: trace2,
1007
+ trace: trace3,
979
1008
  startSpan,
980
1009
  captureSpan
981
1010
  };
@@ -999,7 +1028,7 @@ function withStatlyPagesApi(handler) {
999
1028
  try {
1000
1029
  const result = await handler(req, res);
1001
1030
  return result;
1002
- } catch (error) {
1031
+ } catch (error2) {
1003
1032
  const context = {
1004
1033
  request: {
1005
1034
  method: req.method,
@@ -1008,8 +1037,8 @@ function withStatlyPagesApi(handler) {
1008
1037
  query: req.query
1009
1038
  }
1010
1039
  };
1011
- Statly.captureException(error, context);
1012
- throw error;
1040
+ Statly.captureException(error2, context);
1041
+ throw error2;
1013
1042
  }
1014
1043
  });
1015
1044
  };
@@ -1035,7 +1064,7 @@ function withStatly(handler) {
1035
1064
  span.setTag("http.status_code", result.status.toString());
1036
1065
  }
1037
1066
  return result;
1038
- } catch (error) {
1067
+ } catch (error2) {
1039
1068
  const headers = {};
1040
1069
  request.headers.forEach((value, key) => {
1041
1070
  headers[key] = value;
@@ -1054,17 +1083,17 @@ function withStatly(handler) {
1054
1083
  } catch {
1055
1084
  }
1056
1085
  }
1057
- Statly.captureException(error, errorContext);
1058
- throw error;
1086
+ Statly.captureException(error2, errorContext);
1087
+ throw error2;
1059
1088
  }
1060
1089
  });
1061
1090
  };
1062
1091
  return wrappedHandler;
1063
1092
  }
1064
- function captureNextJsError(error, context) {
1065
- return Statly.captureException(error, {
1093
+ function captureNextJsError(error2, context) {
1094
+ return Statly.captureException(error2, {
1066
1095
  ...context,
1067
- digest: error.digest,
1096
+ digest: error2.digest,
1068
1097
  source: "nextjs-error-boundary"
1069
1098
  });
1070
1099
  }
@@ -1072,12 +1101,12 @@ function withStatlyGetServerSideProps(handler) {
1072
1101
  return async (context) => {
1073
1102
  try {
1074
1103
  return await handler(context);
1075
- } catch (error) {
1076
- Statly.captureException(error, {
1104
+ } catch (error2) {
1105
+ Statly.captureException(error2, {
1077
1106
  source: "getServerSideProps",
1078
1107
  url: context.req?.url || context.resolvedUrl
1079
1108
  });
1080
- throw error;
1109
+ throw error2;
1081
1110
  }
1082
1111
  };
1083
1112
  }
@@ -1085,12 +1114,12 @@ function withStatlyGetStaticProps(handler) {
1085
1114
  return async (context) => {
1086
1115
  try {
1087
1116
  return await handler(context);
1088
- } catch (error) {
1089
- Statly.captureException(error, {
1117
+ } catch (error2) {
1118
+ Statly.captureException(error2, {
1090
1119
  source: "getStaticProps",
1091
1120
  params: context.params
1092
1121
  });
1093
- throw error;
1122
+ throw error2;
1094
1123
  }
1095
1124
  };
1096
1125
  }
@@ -1106,12 +1135,12 @@ function withStatlyServerAction(action, actionName) {
1106
1135
  });
1107
1136
  try {
1108
1137
  return await action(...args);
1109
- } catch (error) {
1110
- Statly.captureException(error, {
1138
+ } catch (error2) {
1139
+ Statly.captureException(error2, {
1111
1140
  source: "server-action",
1112
1141
  actionName
1113
1142
  });
1114
- throw error;
1143
+ throw error2;
1115
1144
  }
1116
1145
  });
1117
1146
  };
@@ -5,7 +5,8 @@ import {
5
5
  withStatlyGetStaticProps,
6
6
  withStatlyPagesApi,
7
7
  withStatlyServerAction
8
- } from "../chunk-HYFH22G6.mjs";
8
+ } from "../chunk-SJ7C46AP.mjs";
9
+ import "../chunk-7AITSJLP.mjs";
9
10
  import "../chunk-J5AHUFP2.mjs";
10
11
  export {
11
12
  captureNextJsError,