@exodus/error-tracking 1.0.0 → 1.1.1
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 +17 -0
- package/api/index.js +8 -24
- package/atoms/index.js +2 -2
- package/index.js +14 -2
- package/is-empty.js +9 -0
- package/module/create-error-tracking.js +30 -0
- package/module/error-tracking.js +10 -0
- package/module/index.js +2 -0
- package/module/remote-error-tracking.js +18 -0
- package/package.json +9 -3
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
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.1](https://github.com/ExodusMovement/exodus-hydra/compare/@exodus/error-tracking@1.1.0...@exodus/error-tracking@1.1.1) (2024-07-12)
|
|
7
|
+
|
|
8
|
+
### Bug Fixes
|
|
9
|
+
|
|
10
|
+
- Add missing is-empty.js file when publish ([#7821](https://github.com/ExodusMovement/exodus-hydra/issues/7821)) ([b2996cc](https://github.com/ExodusMovement/exodus-hydra/commit/b2996cc2cc8591a7b4dc21b4508429d0b962c101))
|
|
11
|
+
|
|
12
|
+
## [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)
|
|
13
|
+
|
|
14
|
+
### Features
|
|
15
|
+
|
|
16
|
+
- 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)
|
|
17
|
+
- **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
|
-
|
|
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
|
|
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
|
-
|
|
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 =
|
|
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:
|
|
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,
|
package/is-empty.js
ADDED
|
@@ -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
|
+
}
|
package/module/index.js
ADDED
|
@@ -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.
|
|
3
|
+
"version": "1.1.1",
|
|
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.",
|
|
@@ -17,8 +17,10 @@
|
|
|
17
17
|
"exports": "./index.js",
|
|
18
18
|
"files": [
|
|
19
19
|
".",
|
|
20
|
+
"is-empty.js",
|
|
20
21
|
"api",
|
|
21
22
|
"atoms",
|
|
23
|
+
"module",
|
|
22
24
|
"report",
|
|
23
25
|
"CHANGELOG.md",
|
|
24
26
|
"README.md",
|
|
@@ -30,7 +32,11 @@
|
|
|
30
32
|
"lint:fix": "yarn lint --fix"
|
|
31
33
|
},
|
|
32
34
|
"dependencies": {
|
|
33
|
-
"@exodus/atoms": "^7.5.0"
|
|
35
|
+
"@exodus/atoms": "^7.5.0",
|
|
36
|
+
"@exodus/basic-utils": "^3.0.1",
|
|
37
|
+
"@exodus/fetch": "^1.3.1",
|
|
38
|
+
"@exodus/sentry-client": "^3.2.0",
|
|
39
|
+
"@exodus/typeforce": "^1.19.0"
|
|
34
40
|
},
|
|
35
|
-
"gitHead": "
|
|
41
|
+
"gitHead": "08aaeda839e81dde42cc93a017ec320be4b73b37"
|
|
36
42
|
}
|