@pristine-ts/sentry 0.0.189 → 0.0.190

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.
@@ -48,7 +48,20 @@ const stream_1 = require("stream");
48
48
  const logging_1 = require("@pristine-ts/logging");
49
49
  const common_1 = require("@pristine-ts/common");
50
50
  const sentry_module_1 = require("../sentry.module");
51
+ /**
52
+ * The SentryLogger captures the logs and sends it to Sentry.
53
+ * It is registered with the tag Logger so that it can be injected along with all the other Loggers.
54
+ * It is module scoped to the Sentry module so that it is only registered if the Sentry module is imported in the app module.
55
+ */
51
56
  let SentryLogger = class SentryLogger {
57
+ /**
58
+ * The SentryLogger captures the logs and sends it to Sentry.
59
+ * @param sentryDsn The sentry dsn.
60
+ * @param tagRelease The release to tag the captured logs with.
61
+ * @param sentrySampleRate The sample rate at which logs should be captured. Only a certain percentage of the logs will be sent to Sentry to avoid sending to many logs.
62
+ * Should be between 0 and 1. If no value or a value outside this range is provided, the default value of 0.1 will be used.
63
+ * @param sentryActivated Whether or not logs should be captured and sent to Sentry.
64
+ */
52
65
  constructor(sentryDsn, tagRelease, sentrySampleRate, sentryActivated) {
53
66
  this.sentryDsn = sentryDsn;
54
67
  this.tagRelease = tagRelease;
@@ -56,10 +69,16 @@ let SentryLogger = class SentryLogger {
56
69
  this.sentryActivated = sentryActivated;
57
70
  this.initialize();
58
71
  }
72
+ /**
73
+ * Terminates the readable stream.
74
+ */
59
75
  terminate() {
60
76
  var _a;
61
77
  (_a = this.readableStream) === null || _a === void 0 ? void 0 : _a.destroy();
62
78
  }
79
+ /**
80
+ * Initializes the Sentry logger.
81
+ */
63
82
  initialize() {
64
83
  var _a;
65
84
  if (this.isActive() === false) {
@@ -80,6 +99,10 @@ let SentryLogger = class SentryLogger {
80
99
  yield this.capture(chunk);
81
100
  }));
82
101
  }
102
+ /**
103
+ * Determines whether or not it should send the logs to Sentry based on the sample rate.
104
+ * @private
105
+ */
83
106
  shouldSendToSentry() {
84
107
  var _a;
85
108
  // We capture by default only 10% of all the events.
@@ -93,10 +116,17 @@ let SentryLogger = class SentryLogger {
93
116
  // If the random number generated is smaller or equal to the sample rate, then we want to send to Sentry.
94
117
  return randomNumber <= sampleRate;
95
118
  }
119
+ /**
120
+ * Whether or not the Sentry logger is activated.
121
+ */
96
122
  isActive() {
97
123
  var _a;
98
124
  return (_a = this.sentryActivated) !== null && _a !== void 0 ? _a : true;
99
125
  }
126
+ /**
127
+ * Captures and sends the log to sentry.
128
+ * @param log The log to capture.
129
+ */
100
130
  capture(log) {
101
131
  return __awaiter(this, void 0, void 0, function* () {
102
132
  if (this.isActive() === false) {
@@ -136,6 +166,7 @@ let SentryLogger = class SentryLogger {
136
166
  }
137
167
  };
138
168
  SentryLogger = __decorate([
169
+ common_1.tag(common_1.ServiceDefinitionTagEnum.Logger),
139
170
  common_1.moduleScoped(sentry_module_1.SentryModule.keyname),
140
171
  tsyringe_1.injectable(),
141
172
  __param(0, tsyringe_1.inject("%pristine.sentry.sentryDsn%")),
@@ -1 +1 @@
1
- {"version":3,"file":"sentry.logger.js","sourceRoot":"","sources":["../../../../src/loggers/sentry.logger.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,uCAA4C;AAC5C,qDAAuC;AACvC,uCAAwD;AACxD,mCAA0C;AAC1C,kDAA6E;AAC7E,gDAAiD;AACjD,oDAA8C;AAI9C,IAAa,YAAY,GAAzB,MAAa,YAAY;IAGrB,YAAoE,SAAiB,EAChB,UAAmB,EACb,gBAAyB,EAC1B,eAAyB;QAH/B,cAAS,GAAT,SAAS,CAAQ;QAChB,eAAU,GAAV,UAAU,CAAS;QACb,qBAAgB,GAAhB,gBAAgB,CAAS;QAC1B,oBAAe,GAAf,eAAe,CAAU;QAC/F,IAAI,CAAC,UAAU,EAAE,CAAC;IACtB,CAAC;IAEM,SAAS;;QACZ,MAAA,IAAI,CAAC,cAAc,0CAAE,OAAO,EAAE,CA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AAC,KAAK,CAAC,KAAK,CAAC,CAAC;aACxB;YACD,OAAO;QACX,CAAC;KAAA;CACJ,CAAA;AA5HY,YAAY;IAHxB,YAAG,CAAC,iCAAwB,CAAC,MAAM,CAAC;IACpC,qBAAY,CAAC,4BAAY,CAAC,OAAO,CAAC;IAClC,qBAAU,EAAE;IAgBI,WAAA,iBAAM,CAAC,6BAA6B,CAAC,CAAA;IACrC,WAAA,iBAAM,CAAC,8BAA8B,CAAC,CAAA;IACtC,WAAA,iBAAM,CAAC,oCAAoC,CAAC,CAAA;IAC5C,WAAA,iBAAM,CAAC,mCAAmC,CAAC,CAAA;;GAlB/C,YAAY,CA4HxB;AA5HY,oCAAY"}
@@ -20,6 +20,9 @@ __exportStar(require("./sentry.module.keyname"), exports);
20
20
  exports.SentryModule = {
21
21
  keyname: sentry_module_keyname_1.SentryModuleKeyname,
22
22
  configurationDefinitions: [
23
+ /**
24
+ * The Sentry dsn.
25
+ */
23
26
  {
24
27
  parameterName: sentry_module_keyname_1.SentryModuleKeyname + ".sentryDsn",
25
28
  isRequired: true,
@@ -27,6 +30,9 @@ exports.SentryModule = {
27
30
  new configuration_1.EnvironmentVariableResolver("PRISTINE_SENTRY_DSN"),
28
31
  ]
29
32
  },
33
+ /**
34
+ * The release to tag the captured logs with.
35
+ */
30
36
  {
31
37
  parameterName: sentry_module_keyname_1.SentryModuleKeyname + ".tagRelease",
32
38
  isRequired: true,
@@ -34,6 +40,10 @@ exports.SentryModule = {
34
40
  new configuration_1.EnvironmentVariableResolver("PRISTINE_SENTRY_TAG_RELEASE"),
35
41
  ]
36
42
  },
43
+ /**
44
+ * The sample rate at which logs should be captured. Only a certain percentage of the logs will be sent to Sentry to avoid sending to many logs.
45
+ * Should be between 0 and 1. If no value or a value outside this range is provided, the default value of 0.1 will be used.
46
+ */
37
47
  {
38
48
  parameterName: sentry_module_keyname_1.SentryModuleKeyname + ".sentrySampleRate",
39
49
  isRequired: false,
@@ -42,6 +52,9 @@ exports.SentryModule = {
42
52
  new configuration_1.NumberResolver(new configuration_1.EnvironmentVariableResolver("PRISTINE_SENTRY_SAMPLE_RATE")),
43
53
  ]
44
54
  },
55
+ /**
56
+ * Whether or not logs should be captured and sent to Sentry.
57
+ */
45
58
  {
46
59
  parameterName: sentry_module_keyname_1.SentryModuleKeyname + ".sentryActivated",
47
60
  isRequired: false,
@@ -1 +1 @@
1
- {"version":3,"file":"sentry.module.js","sourceRoot":"","sources":["../../../src/sentry.module.ts"],"names":[],"mappings":";;;;;;;;;;;;;AAAA,gDAA8E;AAC9E,2DAAqD;AACrD,mEAA4D;AAC5D,8DAAwG;AAExG,oDAAkC;AAClC,0DAAwC;AAE3B,QAAA,YAAY,GAAoB;IACzC,OAAO,EAAE,2CAAmB;IAC5B,wBAAwB,EAAE;QACtB;YACI,aAAa,EAAE,2CAAmB,GAAG,YAAY;YACjD,UAAU,EAAE,IAAI;YAChB,gBAAgB,EAAE;gBACd,IAAI,2CAA2B,CAAC,qBAAqB,CAAC;aACzD;SACJ;QACD;YACI,aAAa,EAAE,2CAAmB,GAAG,aAAa;YAClD,UAAU,EAAE,IAAI;YAChB,gBAAgB,EAAE;gBACd,IAAI,2CAA2B,CAAC,6BAA6B,CAAC;aACjE;SACJ;QACD;YACI,aAAa,EAAE,2CAAmB,GAAG,mBAAmB;YACxD,UAAU,EAAE,KAAK;YACjB,YAAY,EAAE,GAAG;YACjB,gBAAgB,EAAE;gBACd,IAAI,8BAAc,CAAC,IAAI,2CAA2B,CAAC,6BAA6B,CAAC,CAAC;aACrF;SACJ;QACD;YACI,aAAa,EAAE,2CAAmB,GAAG,kBAAkB;YACvD,UAAU,EAAE,KAAK;YACjB,YAAY,EAAE,KAAK;YACnB,gBAAgB,EAAE;gBACd,IAAI,+BAAe,CAAC,IAAI,2CAA2B,CAAC,2BAA2B,CAAC,CAAC;aACpF;SACJ;KACJ;IACD,aAAa,EAAE,EAAE;IACjB,qBAAqB,EAAE;QACnB;YACI,KAAK,EAAE,iCAAwB,CAAC,MAAM;YACtC,QAAQ,EAAE,4BAAY;SACzB;KACJ;CACJ,CAAA"}
1
+ {"version":3,"file":"sentry.module.js","sourceRoot":"","sources":["../../../src/sentry.module.ts"],"names":[],"mappings":";;;;;;;;;;;;;AAAA,gDAA8E;AAC9E,2DAAqD;AACrD,mEAA4D;AAC5D,8DAAwG;AAExG,oDAAkC;AAClC,0DAAwC;AAE3B,QAAA,YAAY,GAAoB;IACzC,OAAO,EAAE,2CAAmB;IAC5B,wBAAwB,EAAE;QACtB;;WAEG;QACH;YACI,aAAa,EAAE,2CAAmB,GAAG,YAAY;YACjD,UAAU,EAAE,IAAI;YAChB,gBAAgB,EAAE;gBACd,IAAI,2CAA2B,CAAC,qBAAqB,CAAC;aACzD;SACJ;QAED;;WAEG;QACH;YACI,aAAa,EAAE,2CAAmB,GAAG,aAAa;YAClD,UAAU,EAAE,IAAI;YAChB,gBAAgB,EAAE;gBACd,IAAI,2CAA2B,CAAC,6BAA6B,CAAC;aACjE;SACJ;QAED;;;WAGG;QACH;YACI,aAAa,EAAE,2CAAmB,GAAG,mBAAmB;YACxD,UAAU,EAAE,KAAK;YACjB,YAAY,EAAE,GAAG;YACjB,gBAAgB,EAAE;gBACd,IAAI,8BAAc,CAAC,IAAI,2CAA2B,CAAC,6BAA6B,CAAC,CAAC;aACrF;SACJ;QAED;;WAEG;QACH;YACI,aAAa,EAAE,2CAAmB,GAAG,kBAAkB;YACvD,UAAU,EAAE,KAAK;YACjB,YAAY,EAAE,KAAK;YACnB,gBAAgB,EAAE;gBACd,IAAI,+BAAe,CAAC,IAAI,2CAA2B,CAAC,2BAA2B,CAAC,CAAC;aACpF;SACJ;KACJ;IACD,aAAa,EAAE,EAAE;IACjB,qBAAqB,EAAE;QACnB;YACI,KAAK,EAAE,iCAAwB,CAAC,MAAM;YACtC,QAAQ,EAAE,4BAAY;SACzB;KACJ;CACJ,CAAA"}
@@ -19,14 +19,27 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
19
19
  step((generator = generator.apply(thisArg, _arguments || [])).next());
20
20
  });
21
21
  };
22
- import { injectable, inject } from "tsyringe";
22
+ import { inject, injectable } from "tsyringe";
23
23
  import * as Sentry from "@sentry/node";
24
24
  import { Severity as SentrySeverity } from "@sentry/node";
25
25
  import { Readable } from "stream";
26
26
  import { SeverityEnum } from "@pristine-ts/logging";
27
- import { moduleScoped } from "@pristine-ts/common";
27
+ import { moduleScoped, ServiceDefinitionTagEnum, tag } from "@pristine-ts/common";
28
28
  import { SentryModule } from "../sentry.module";
29
+ /**
30
+ * The SentryLogger captures the logs and sends it to Sentry.
31
+ * It is registered with the tag Logger so that it can be injected along with all the other Loggers.
32
+ * It is module scoped to the Sentry module so that it is only registered if the Sentry module is imported in the app module.
33
+ */
29
34
  let SentryLogger = class SentryLogger {
35
+ /**
36
+ * The SentryLogger captures the logs and sends it to Sentry.
37
+ * @param sentryDsn The sentry dsn.
38
+ * @param tagRelease The release to tag the captured logs with.
39
+ * @param sentrySampleRate The sample rate at which logs should be captured. Only a certain percentage of the logs will be sent to Sentry to avoid sending to many logs.
40
+ * Should be between 0 and 1. If no value or a value outside this range is provided, the default value of 0.1 will be used.
41
+ * @param sentryActivated Whether or not logs should be captured and sent to Sentry.
42
+ */
30
43
  constructor(sentryDsn, tagRelease, sentrySampleRate, sentryActivated) {
31
44
  this.sentryDsn = sentryDsn;
32
45
  this.tagRelease = tagRelease;
@@ -34,10 +47,16 @@ let SentryLogger = class SentryLogger {
34
47
  this.sentryActivated = sentryActivated;
35
48
  this.initialize();
36
49
  }
50
+ /**
51
+ * Terminates the readable stream.
52
+ */
37
53
  terminate() {
38
54
  var _a;
39
55
  (_a = this.readableStream) === null || _a === void 0 ? void 0 : _a.destroy();
40
56
  }
57
+ /**
58
+ * Initializes the Sentry logger.
59
+ */
41
60
  initialize() {
42
61
  var _a;
43
62
  if (this.isActive() === false) {
@@ -58,6 +77,10 @@ let SentryLogger = class SentryLogger {
58
77
  yield this.capture(chunk);
59
78
  }));
60
79
  }
80
+ /**
81
+ * Determines whether or not it should send the logs to Sentry based on the sample rate.
82
+ * @private
83
+ */
61
84
  shouldSendToSentry() {
62
85
  var _a;
63
86
  // We capture by default only 10% of all the events.
@@ -71,10 +94,17 @@ let SentryLogger = class SentryLogger {
71
94
  // If the random number generated is smaller or equal to the sample rate, then we want to send to Sentry.
72
95
  return randomNumber <= sampleRate;
73
96
  }
97
+ /**
98
+ * Whether or not the Sentry logger is activated.
99
+ */
74
100
  isActive() {
75
101
  var _a;
76
102
  return (_a = this.sentryActivated) !== null && _a !== void 0 ? _a : true;
77
103
  }
104
+ /**
105
+ * Captures and sends the log to sentry.
106
+ * @param log The log to capture.
107
+ */
78
108
  capture(log) {
79
109
  return __awaiter(this, void 0, void 0, function* () {
80
110
  if (this.isActive() === false) {
@@ -114,6 +144,7 @@ let SentryLogger = class SentryLogger {
114
144
  }
115
145
  };
116
146
  SentryLogger = __decorate([
147
+ tag(ServiceDefinitionTagEnum.Logger),
117
148
  moduleScoped(SentryModule.keyname),
118
149
  injectable(),
119
150
  __param(0, inject("%pristine.sentry.sentryDsn%")),
@@ -1 +1 @@
1
- {"version":3,"file":"sentry.logger.js","sourceRoot":"","sources":["../../../../src/loggers/sentry.logger.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;AAAA,OAAO,EAAC,UAAU,EAAE,MAAM,EAAC,MAAM,UAAU,CAAC;AAC5C,OAAO,KAAK,MAAM,MAAM,cAAc,CAAC;AACvC,OAAO,EAAC,QAAQ,IAAI,cAAc,EAAC,MAAM,cAAc,CAAC;AACxD,OAAO,EAAC,QAAQ,EAAW,MAAM,QAAQ,CAAC;AAC1C,OAAO,EAAW,YAAY,EAAkB,MAAM,sBAAsB,CAAC;AAC7E,OAAO,EAAC,YAAY,EAAC,MAAM,qBAAqB,CAAC;AACjD,OAAO,EAAC,YAAY,EAAC,MAAM,kBAAkB,CAAC;AAI9C,IAAa,YAAY,GAAzB,MAAa,YAAY;IAGrB,YAAoE,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AAC,GAAG,CAAC,OAAO,EAAE;4BAC/B,4BAA4B;4BAC5B,KAAK,EAAE,GAAG,CAAC,KAAK;4BAChB,KAAK,EAAE,cAAc,CAAC,KAAK;yBAC9B,CAAC,CAAC;wBACH,MAAM;oBAEV,KAAK,YAAY,CAAC,QAAQ;wBACtB,4CAA4C;wBAC5C,MAAM,CAAC,cAAc,CAAC,GAAG,CAAC,OAAO,EAAE;4BAC/B,4BAA4B;4BAC5B,KAAK,EAAE,GAAG,CAAC,KAAK;4BAChB,KAAK,EAAE,cAAc,CAAC,QAAQ;yBACjC,CAAC,CAAC;wBACH,MAAM;iBACb;gBAED,MAAM,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;aAC5B;YAAC,OAAO,KAAK,EAAE;gBACZ,OAAO,CAAC,KAAK,CAAC,uCAAuC,CAAC,CAAC;gBACvD,OAAO,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;aACxB;YACD,OAAO;QACX,CAAC;KAAA;CACJ,CAAA;AA5HY,YAAY;IAHxB,GAAG,CAAC,wBAAwB,CAAC,MAAM,CAAC;IACpC,YAAY,CAAC,YAAY,CAAC,OAAO,CAAC;IAClC,UAAU,EAAE;IAgBI,WAAA,MAAM,CAAC,6BAA6B,CAAC,CAAA;IACrC,WAAA,MAAM,CAAC,8BAA8B,CAAC,CAAA;IACtC,WAAA,MAAM,CAAC,oCAAoC,CAAC,CAAA;IAC5C,WAAA,MAAM,CAAC,mCAAmC,CAAC,CAAA;;GAlB/C,YAAY,CA4HxB;SA5HY,YAAY"}
@@ -7,6 +7,9 @@ export * from "./sentry.module.keyname";
7
7
  export const SentryModule = {
8
8
  keyname: SentryModuleKeyname,
9
9
  configurationDefinitions: [
10
+ /**
11
+ * The Sentry dsn.
12
+ */
10
13
  {
11
14
  parameterName: SentryModuleKeyname + ".sentryDsn",
12
15
  isRequired: true,
@@ -14,6 +17,9 @@ export const SentryModule = {
14
17
  new EnvironmentVariableResolver("PRISTINE_SENTRY_DSN"),
15
18
  ]
16
19
  },
20
+ /**
21
+ * The release to tag the captured logs with.
22
+ */
17
23
  {
18
24
  parameterName: SentryModuleKeyname + ".tagRelease",
19
25
  isRequired: true,
@@ -21,6 +27,10 @@ export const SentryModule = {
21
27
  new EnvironmentVariableResolver("PRISTINE_SENTRY_TAG_RELEASE"),
22
28
  ]
23
29
  },
30
+ /**
31
+ * The sample rate at which logs should be captured. Only a certain percentage of the logs will be sent to Sentry to avoid sending to many logs.
32
+ * Should be between 0 and 1. If no value or a value outside this range is provided, the default value of 0.1 will be used.
33
+ */
24
34
  {
25
35
  parameterName: SentryModuleKeyname + ".sentrySampleRate",
26
36
  isRequired: false,
@@ -29,6 +39,9 @@ export const SentryModule = {
29
39
  new NumberResolver(new EnvironmentVariableResolver("PRISTINE_SENTRY_SAMPLE_RATE")),
30
40
  ]
31
41
  },
42
+ /**
43
+ * Whether or not logs should be captured and sent to Sentry.
44
+ */
32
45
  {
33
46
  parameterName: SentryModuleKeyname + ".sentryActivated",
34
47
  isRequired: false,
@@ -1 +1 @@
1
- {"version":3,"file":"sentry.module.js","sourceRoot":"","sources":["../../../src/sentry.module.ts"],"names":[],"mappings":"AAAA,OAAO,EAAkB,wBAAwB,EAAC,MAAM,qBAAqB,CAAC;AAC9E,OAAO,EAAC,YAAY,EAAC,MAAM,yBAAyB,CAAC;AACrD,OAAO,EAAC,mBAAmB,EAAC,MAAM,yBAAyB,CAAC;AAC5D,OAAO,EAAC,eAAe,EAAE,2BAA2B,EAAE,cAAc,EAAC,MAAM,4BAA4B,CAAC;AAExG,cAAc,mBAAmB,CAAC;AAClC,cAAc,yBAAyB,CAAC;AAExC,MAAM,CAAC,MAAM,YAAY,GAAoB;IACzC,OAAO,EAAE,mBAAmB;IAC5B,wBAAwB,EAAE;QACtB;YACI,aAAa,EAAE,mBAAmB,GAAG,YAAY;YACjD,UAAU,EAAE,IAAI;YAChB,gBAAgB,EAAE;gBACd,IAAI,2BAA2B,CAAC,qBAAqB,CAAC;aACzD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2BAA2B,CAAC,qBAAqB,CAAC;aACzD;SACJ;QAED;;WAEG;QACH;YACI,aAAa,EAAE,mBAAmB,GAAG,aAAa;YAClD,UAAU,EAAE,IAAI;YAChB,gBAAgB,EAAE;gBACd,IAAI,2BAA2B,CAAC,6BAA6B,CAAC;aACjE;SACJ;QAED;;;WAGG;QACH;YACI,aAAa,EAAE,mBAAmB,GAAG,mBAAmB;YACxD,UAAU,EAAE,KAAK;YACjB,YAAY,EAAE,GAAG;YACjB,gBAAgB,EAAE;gBACd,IAAI,cAAc,CAAC,IAAI,2BAA2B,CAAC,6BAA6B,CAAC,CAAC;aACrF;SACJ;QAED;;WAEG;QACH;YACI,aAAa,EAAE,mBAAmB,GAAG,kBAAkB;YACvD,UAAU,EAAE,KAAK;YACjB,YAAY,EAAE,KAAK;YACnB,gBAAgB,EAAE;gBACd,IAAI,eAAe,CAAC,IAAI,2BAA2B,CAAC,2BAA2B,CAAC,CAAC;aACpF;SACJ;KACJ;IACD,aAAa,EAAE,EAAE;IACjB,qBAAqB,EAAE;QACnB;YACI,KAAK,EAAE,wBAAwB,CAAC,MAAM;YACtC,QAAQ,EAAE,YAAY;SACzB;KACJ;CACJ,CAAA"}
@@ -1,16 +1,49 @@
1
1
  /// <reference types="node" />
2
2
  import { Readable } from "stream";
3
- import { LogModel, LoggerInterface } from "@pristine-ts/logging";
3
+ import { LoggerInterface, LogModel } from "@pristine-ts/logging";
4
+ /**
5
+ * The SentryLogger captures the logs and sends it to Sentry.
6
+ * It is registered with the tag Logger so that it can be injected along with all the other Loggers.
7
+ * It is module scoped to the Sentry module so that it is only registered if the Sentry module is imported in the app module.
8
+ */
4
9
  export declare class SentryLogger implements LoggerInterface {
5
10
  private readonly sentryDsn;
6
11
  private readonly tagRelease?;
7
12
  private readonly sentrySampleRate?;
8
13
  private readonly sentryActivated?;
14
+ /**
15
+ * The readable stream from which the logger reads the logs that need to be captured.
16
+ */
9
17
  readableStream?: Readable;
18
+ /**
19
+ * The SentryLogger captures the logs and sends it to Sentry.
20
+ * @param sentryDsn The sentry dsn.
21
+ * @param tagRelease The release to tag the captured logs with.
22
+ * @param sentrySampleRate The sample rate at which logs should be captured. Only a certain percentage of the logs will be sent to Sentry to avoid sending to many logs.
23
+ * Should be between 0 and 1. If no value or a value outside this range is provided, the default value of 0.1 will be used.
24
+ * @param sentryActivated Whether or not logs should be captured and sent to Sentry.
25
+ */
10
26
  constructor(sentryDsn: string, tagRelease?: string | undefined, sentrySampleRate?: number | undefined, sentryActivated?: boolean | undefined);
27
+ /**
28
+ * Terminates the readable stream.
29
+ */
11
30
  terminate(): void;
31
+ /**
32
+ * Initializes the Sentry logger.
33
+ */
12
34
  initialize(): void;
35
+ /**
36
+ * Determines whether or not it should send the logs to Sentry based on the sample rate.
37
+ * @private
38
+ */
13
39
  private shouldSendToSentry;
40
+ /**
41
+ * Whether or not the Sentry logger is activated.
42
+ */
14
43
  isActive(): boolean;
44
+ /**
45
+ * Captures and sends the log to sentry.
46
+ * @param log The log to capture.
47
+ */
15
48
  capture(log: LogModel): Promise<void>;
16
49
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pristine-ts/sentry",
3
- "version": "0.0.189",
3
+ "version": "0.0.190",
4
4
  "description": "",
5
5
  "module": "dist/lib/esm/sentry.module.js",
6
6
  "main": "dist/lib/cjs/sentry.module.js",
@@ -11,8 +11,8 @@
11
11
  "test": "jest"
12
12
  },
13
13
  "dependencies": {
14
- "@pristine-ts/common": "^0.0.189",
15
- "@pristine-ts/logging": "^0.0.189",
14
+ "@pristine-ts/common": "^0.0.190",
15
+ "@pristine-ts/logging": "^0.0.190",
16
16
  "@sentry/node": "^6.2.1"
17
17
  },
18
18
  "files": [
@@ -57,5 +57,5 @@
57
57
  "src/*.{js,ts}"
58
58
  ]
59
59
  },
60
- "gitHead": "8e39ed86b4bd7fdb510ccb8aee4955df82010f90"
60
+ "gitHead": "b3a54c2748face44898cbd15d479c72eea834719"
61
61
  }