@exodus/error-tracking 1.0.0 → 1.1.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/CHANGELOG.md ADDED
@@ -0,0 +1,11 @@
1
+ # Change Log
2
+
3
+ All notable changes to this project will be documented in this file.
4
+ See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
+
6
+ ## [1.1.0](https://github.com/ExodusMovement/exodus-hydra/compare/@exodus/error-tracking@1.0.0...@exodus/error-tracking@1.1.0) (2024-07-12)
7
+
8
+ ### Features
9
+
10
+ - add errorTracking feature to sdk ([#7670](https://github.com/ExodusMovement/exodus-hydra/issues/7670)) ([34dbc5c](https://github.com/ExodusMovement/exodus-hydra/commit/34dbc5c1f0b94ef4213dfaec788790c475eb962c)), closes [#7708](https://github.com/ExodusMovement/exodus-hydra/issues/7708)
11
+ - **error-tracking:** adds errorTracking module + namespaced preprocessor ([#7603](https://github.com/ExodusMovement/exodus-hydra/issues/7603)) ([aa7f8d7](https://github.com/ExodusMovement/exodus-hydra/commit/aa7f8d75aad88f83495c963f7271331a87181467)), closes [#7708](https://github.com/ExodusMovement/exodus-hydra/issues/7708)
package/api/index.js CHANGED
@@ -1,34 +1,18 @@
1
+ import { createErrorTracking } from '../module/create-error-tracking.js'
2
+
3
+ // Implementation Note: It would have made more sense to add the `errorTracking` module as a dependency instead of
4
+ // just its factory function. However, the issue is that adding errorTracking as a dependency to this API node
5
+ // will cause the error-tracking-preprocessor to change the track function definition, which is not what we require here.
6
+
1
7
  const errorTrackingApiDefinition = {
2
8
  id: 'errorTrackingApi',
3
9
  type: 'api',
4
10
  factory: ({ errorsAtom, config }) => {
5
- if (
6
- !config.maxErrorsCount ||
7
- typeof config.maxErrorsCount !== 'number' ||
8
- config.maxErrorsCount < 1 ||
9
- config.maxErrorsCount > 9999
10
- ) {
11
- throw new Error('`maxErrorsCount` is required config and must be a number [0-9999]')
12
- }
11
+ const { track } = createErrorTracking({ errorsAtom, config })
13
12
 
14
13
  return {
15
14
  errors: {
16
- track: async ({ namespace, error, context }) => {
17
- if (!namespace) {
18
- throw new Error('`namespace` is required to track/collect errors')
19
- }
20
-
21
- return errorsAtom.set((namespaces) => {
22
- const errors = namespaces[namespace] || []
23
- return {
24
- ...namespaces,
25
- [namespace]: [{ namespace, error, context, time: Date.now() }, ...errors].slice(
26
- 0,
27
- config.maxErrorsCount
28
- ),
29
- }
30
- })
31
- },
15
+ track,
32
16
  },
33
17
  }
34
18
  },
package/atoms/index.js CHANGED
@@ -2,14 +2,14 @@ import { createInMemoryAtom } from '@exodus/atoms'
2
2
 
3
3
  /* errorsAtom schema:
4
4
  {
5
- `namespace`: [{ `namespace`, `error`, `context`, `time` }, ...]
5
+ errors: [{ `namespace`, `error`, `context`, `time` }, ...]
6
6
  }
7
7
  */
8
8
  const errorsAtomDefinition = {
9
9
  id: 'errorsAtom',
10
10
  private: true,
11
11
  type: 'atom',
12
- factory: () => createInMemoryAtom({ defaultValue: {} }),
12
+ factory: () => createInMemoryAtom({ defaultValue: { errors: [] } }),
13
13
  dependencies: [],
14
14
  }
15
15
 
package/index.js CHANGED
@@ -1,16 +1,28 @@
1
+ import { isEmpty } from './is-empty.js'
2
+
1
3
  import errorTrackingApiDefinition from './api/index.js'
2
4
  import errorTrackingAtomDefinition from './atoms/index.js'
3
5
  import errorTrackingReportDefinition from './report/index.js'
6
+ import { errorTrackingDefinition, remoteErrorTrackingDefinition } from './module/index.js'
4
7
 
5
- const errorTracking = ({ maxErrorsCount = 10 } = Object.create(null)) => ({
8
+ const errorTracking = ({ maxErrorsCount = 100, sentryConfig } = Object.create(null)) => ({
6
9
  id: 'errorTracking',
7
10
  definitions: [
11
+ {
12
+ definition: errorTrackingAtomDefinition,
13
+ },
8
14
  {
9
15
  definition: errorTrackingApiDefinition,
10
16
  config: { maxErrorsCount },
11
17
  },
12
18
  {
13
- definition: errorTrackingAtomDefinition,
19
+ definition: errorTrackingDefinition,
20
+ config: { maxErrorsCount },
21
+ },
22
+ {
23
+ if: sentryConfig !== undefined && sentryConfig !== null && !isEmpty(sentryConfig),
24
+ definition: remoteErrorTrackingDefinition,
25
+ config: sentryConfig,
14
26
  },
15
27
  {
16
28
  definition: errorTrackingReportDefinition,
@@ -0,0 +1,30 @@
1
+ import typeforce from '@exodus/typeforce'
2
+
3
+ export const createErrorTracking = ({ errorsAtom, config }) => {
4
+ const { maxErrorsCount } = typeforce.parse(
5
+ {
6
+ maxErrorsCount: (value) => typeof value === 'number' && value > 0 && value <= 9999,
7
+ },
8
+ config
9
+ )
10
+
11
+ const track = async ({ error, context, namespace }) => {
12
+ if (!namespace) {
13
+ throw new Error('no namespace provided')
14
+ }
15
+
16
+ return errorsAtom.set(({ errors }) => {
17
+ errors = errors || []
18
+ return {
19
+ // this array can be big. not sure about prefering spread operator here
20
+ // concat function seems like a better option
21
+ errors: [{ namespace, error, context, time: Date.now() }]
22
+ // eslint-disable-next-line unicorn/prefer-spread
23
+ .concat(errors)
24
+ .slice(0, maxErrorsCount),
25
+ }
26
+ })
27
+ }
28
+
29
+ return { track }
30
+ }
@@ -0,0 +1,10 @@
1
+ import { createErrorTracking } from './create-error-tracking.js'
2
+
3
+ const MODULE_ID = 'errorTracking'
4
+
5
+ export const errorTrackingDefinition = {
6
+ id: MODULE_ID,
7
+ type: 'module',
8
+ factory: createErrorTracking,
9
+ dependencies: ['config', 'errorsAtom'],
10
+ }
@@ -0,0 +1,2 @@
1
+ export { errorTrackingDefinition } from './error-tracking.js'
2
+ export { remoteErrorTrackingDefinition } from './remote-error-tracking.js'
@@ -0,0 +1,18 @@
1
+ import createSentryClient from '@exodus/sentry-client'
2
+ import stackTraceParser from '@exodus/sentry-client/src/stack-trace-parsers/default.js'
3
+ import createFetchival from '@exodus/fetch/create-fetchival'
4
+
5
+ export const remoteErrorTrackingDefinition = {
6
+ id: 'remoteErrorTracking',
7
+ type: 'module',
8
+ private: true,
9
+ factory: ({ config, fetch, defaultStackTraceParser }) => {
10
+ const fetchival = createFetchival({ fetch })
11
+ return createSentryClient({
12
+ config,
13
+ fetchival,
14
+ defaultStackTraceParser: defaultStackTraceParser || stackTraceParser,
15
+ })
16
+ },
17
+ dependencies: ['config', 'fetch', 'defaultStackTraceParser?'],
18
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@exodus/error-tracking",
3
- "version": "1.0.0",
3
+ "version": "1.1.0",
4
4
  "type": "module",
5
5
  "description": "A simple error tracking package to let any feature collect errors and create the report",
6
6
  "author": "Exodus Movement, Inc.",
@@ -19,6 +19,7 @@
19
19
  ".",
20
20
  "api",
21
21
  "atoms",
22
+ "module",
22
23
  "report",
23
24
  "CHANGELOG.md",
24
25
  "README.md",
@@ -30,7 +31,11 @@
30
31
  "lint:fix": "yarn lint --fix"
31
32
  },
32
33
  "dependencies": {
33
- "@exodus/atoms": "^7.5.0"
34
+ "@exodus/atoms": "^7.5.0",
35
+ "@exodus/basic-utils": "^3.0.1",
36
+ "@exodus/fetch": "^1.3.1",
37
+ "@exodus/sentry-client": "^3.2.0",
38
+ "@exodus/typeforce": "^1.19.0"
34
39
  },
35
- "gitHead": "5618f82730d7fab9716a974488d2d96afbe99922"
40
+ "gitHead": "14d2baaf7c1adf673aeb49562d6625a30195de03"
36
41
  }