@exodus/error-tracking 1.2.0 → 1.3.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 +11 -0
- package/README.md +13 -13
- package/api/index.d.ts +34 -0
- package/api/index.js +21 -26
- package/index.d.ts +8 -0
- package/index.js +38 -26
- package/module/error-tracking.js +21 -2
- package/package.json +5 -5
- package/module/create-error-tracking.js +0 -30
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,17 @@
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
5
|
|
|
6
|
+
## [1.3.0](https://github.com/ExodusMovement/exodus-hydra/compare/@exodus/error-tracking@1.2.1...@exodus/error-tracking@1.3.0) (2024-10-03)
|
|
7
|
+
|
|
8
|
+
### Features
|
|
9
|
+
|
|
10
|
+
- add error tracking API types ([#9579](https://github.com/ExodusMovement/exodus-hydra/issues/9579)) ([317e40b](https://github.com/ExodusMovement/exodus-hydra/commit/317e40bde1007f7d192379ab390e3aed0a6ebd1a))
|
|
11
|
+
- use atoms v9 ([#9651](https://github.com/ExodusMovement/exodus-hydra/issues/9651)) ([524aa61](https://github.com/ExodusMovement/exodus-hydra/commit/524aa61f69c81e6ac00b2f94ea830688a105b3e4))
|
|
12
|
+
|
|
13
|
+
## [1.2.1](https://github.com/ExodusMovement/exodus-hydra/compare/@exodus/error-tracking@1.2.0...@exodus/error-tracking@1.2.1) (2024-08-13)
|
|
14
|
+
|
|
15
|
+
**Note:** Version bump only for package @exodus/error-tracking
|
|
16
|
+
|
|
6
17
|
## [1.2.0](https://github.com/ExodusMovement/exodus-hydra/compare/@exodus/error-tracking@1.1.3...@exodus/error-tracking@1.2.0) (2024-08-08)
|
|
7
18
|
|
|
8
19
|
### Features
|
package/README.md
CHANGED
|
@@ -8,23 +8,23 @@ A simple namespaces error tracking package to let any feature collect errors and
|
|
|
8
8
|
yarn add @exodus/error-tracking
|
|
9
9
|
```
|
|
10
10
|
|
|
11
|
-
## Methods
|
|
12
|
-
|
|
13
|
-
`#errorTracking.track({ namespace: string, error: Error | string, context: Object })`
|
|
14
|
-
|
|
15
|
-
Collects tracked error to the provided namespaced error list.
|
|
16
|
-
|
|
17
11
|
## Usage
|
|
18
12
|
|
|
19
|
-
|
|
13
|
+
This feature is designed to be used together with `@exodus/headless`. See [using the sdk](../../docs/docs-website/docs/development/using-the-sdk.md).
|
|
20
14
|
|
|
21
|
-
|
|
22
|
-
import errorTracking from '@exodus/error-tracking'
|
|
15
|
+
### Play with it
|
|
23
16
|
|
|
24
|
-
|
|
17
|
+
1. Open the playground https://exodus-hydra.pages.dev/features/errors
|
|
18
|
+
2. Try out the some methods via the UI. These corresponds 1:1 with the `exodus.errors` API.
|
|
19
|
+
3. Run `await exodus.errors.track({ namespace: 'balances', error: 'Encountered an issue when computing total balances', context: {} })` in the Dev Tools Console.
|
|
25
20
|
|
|
26
|
-
|
|
27
|
-
ioc.use(errorTracking(config))
|
|
21
|
+
### API Side
|
|
28
22
|
|
|
29
|
-
|
|
23
|
+
See [using the sdk](../../docs/docs-website/docs/development/using-the-sdk.md#setup-the-api-side) for more details on how features plug into the SDK and the API interface in the [type declaration](./api/index.d.ts).
|
|
24
|
+
|
|
25
|
+
```ts
|
|
26
|
+
await exodus.errors.track({ namespace, error, context: {} })
|
|
27
|
+
await exodus.errors.trackRemote({ error })
|
|
30
28
|
```
|
|
29
|
+
|
|
30
|
+
If you're building a feature and like to use error tracking inside that feature, you can depend on `errorTracking` and will receive the module with a track method that is auto-namespaced to your feature id.
|
package/api/index.d.ts
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
export interface ErrorTrackingApi {
|
|
2
|
+
/**
|
|
3
|
+
* Track an error
|
|
4
|
+
* @example
|
|
5
|
+
* ```typescript
|
|
6
|
+
* exodus.errors.track({
|
|
7
|
+
* namespace: 'balances',
|
|
8
|
+
* error: 'Encountered an issue when computing total balances',
|
|
9
|
+
* context: {},
|
|
10
|
+
* })
|
|
11
|
+
* ```
|
|
12
|
+
*/
|
|
13
|
+
track(params: { error: string | Error; namespace: string; context: any }): Promise<void>
|
|
14
|
+
/**
|
|
15
|
+
* Track an error remotely using sentry if available
|
|
16
|
+
* @example
|
|
17
|
+
* ```typescript
|
|
18
|
+
* exodus.errors.trackRemote({
|
|
19
|
+
* error: 'Encountered an issue when computing total balances',
|
|
20
|
+
* })
|
|
21
|
+
* ```
|
|
22
|
+
*/
|
|
23
|
+
trackRemote(params: { error: string }): Promise<void>
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
declare const errorTrackingApiDefinition: {
|
|
27
|
+
id: 'errorTrackingApi'
|
|
28
|
+
type: 'api'
|
|
29
|
+
factory(): {
|
|
30
|
+
errors: ErrorTrackingApi
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export default errorTrackingApiDefinition
|
package/api/index.js
CHANGED
|
@@ -1,38 +1,33 @@
|
|
|
1
|
-
|
|
1
|
+
const createTrackRemote = ({ remoteErrorTracking, logger }) => {
|
|
2
|
+
if (!remoteErrorTracking) {
|
|
3
|
+
return async ({ error }) => {
|
|
4
|
+
logger.debug('remote error tracking is disabled', error)
|
|
5
|
+
}
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
return async ({ error }) => {
|
|
9
|
+
try {
|
|
10
|
+
await remoteErrorTracking.captureError({
|
|
11
|
+
error,
|
|
12
|
+
})
|
|
13
|
+
} catch (err) {
|
|
14
|
+
logger.error('failed to remote track error', err)
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
}
|
|
2
18
|
|
|
3
19
|
export const errorTrackingApiDefinition = {
|
|
4
20
|
id: 'errorTrackingApi',
|
|
5
21
|
type: 'api',
|
|
6
|
-
factory: ({
|
|
7
|
-
const
|
|
8
|
-
|
|
9
|
-
let trackRemote
|
|
10
|
-
if (remoteErrorTracking) {
|
|
11
|
-
trackRemote = async ({ error }) => {
|
|
12
|
-
try {
|
|
13
|
-
await remoteErrorTracking.captureError({
|
|
14
|
-
error,
|
|
15
|
-
})
|
|
16
|
-
} catch (err) {
|
|
17
|
-
logger.error('failed to remote track error', err)
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
} else {
|
|
21
|
-
trackRemote = async ({ error }) => {
|
|
22
|
-
logger.debug('remote error tracking is disabled', error)
|
|
23
|
-
}
|
|
24
|
-
}
|
|
22
|
+
factory: ({ errorTracking, logger, remoteErrorTracking }) => {
|
|
23
|
+
const trackRemote = createTrackRemote({ remoteErrorTracking, logger })
|
|
25
24
|
|
|
26
25
|
return {
|
|
27
26
|
errors: {
|
|
28
|
-
track,
|
|
27
|
+
track: errorTracking.track,
|
|
29
28
|
trackRemote,
|
|
30
29
|
},
|
|
31
30
|
}
|
|
32
31
|
},
|
|
33
|
-
dependencies: ['
|
|
32
|
+
dependencies: ['logger', 'remoteErrorTracking?', 'errorTracking'],
|
|
34
33
|
}
|
|
35
|
-
|
|
36
|
-
// Implementation Note: It would have made more sense to add the `errorTracking` module as a dependency instead of
|
|
37
|
-
// just its factory function. However, the issue is that adding errorTracking as a dependency to this API node
|
|
38
|
-
// will cause the error-tracking-preprocessor to change the track function definition, which is not what we require here.
|
package/index.d.ts
ADDED
package/index.js
CHANGED
|
@@ -1,34 +1,46 @@
|
|
|
1
|
-
import
|
|
1
|
+
import typeforce from '@exodus/typeforce'
|
|
2
2
|
|
|
3
|
+
import { isEmpty } from './is-empty.js'
|
|
3
4
|
import { errorTrackingApiDefinition } from './api/index.js'
|
|
4
|
-
|
|
5
5
|
import errorTrackingAtomDefinition from './atoms/index.js'
|
|
6
6
|
import errorTrackingReportDefinition from './report/index.js'
|
|
7
7
|
import { errorTrackingDefinition, remoteErrorTrackingDefinition } from './module/index.js'
|
|
8
8
|
|
|
9
|
-
const
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
}
|
|
9
|
+
const defaultConfig = { maxErrorsCount: 100 }
|
|
10
|
+
|
|
11
|
+
const configSchema = {
|
|
12
|
+
maxErrorsCount: (value) => typeof value === 'number' && value > 0 && value <= 9999,
|
|
13
|
+
sentryConfig: '?Object',
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
const errorTracking = (config = Object.create(null)) => {
|
|
17
|
+
config = { ...defaultConfig, ...config }
|
|
18
|
+
|
|
19
|
+
const { maxErrorsCount, sentryConfig } = typeforce.parse(configSchema, config)
|
|
20
|
+
|
|
21
|
+
return {
|
|
22
|
+
id: 'errorTracking',
|
|
23
|
+
definitions: [
|
|
24
|
+
{
|
|
25
|
+
definition: errorTrackingAtomDefinition,
|
|
26
|
+
},
|
|
27
|
+
{
|
|
28
|
+
definition: errorTrackingApiDefinition,
|
|
29
|
+
},
|
|
30
|
+
{
|
|
31
|
+
definition: errorTrackingDefinition,
|
|
32
|
+
config: { maxErrorsCount },
|
|
33
|
+
},
|
|
34
|
+
{
|
|
35
|
+
if: sentryConfig !== undefined && sentryConfig !== null && !isEmpty(sentryConfig),
|
|
36
|
+
definition: remoteErrorTrackingDefinition,
|
|
37
|
+
config: sentryConfig,
|
|
38
|
+
},
|
|
39
|
+
{
|
|
40
|
+
definition: errorTrackingReportDefinition,
|
|
41
|
+
},
|
|
42
|
+
],
|
|
43
|
+
}
|
|
44
|
+
}
|
|
33
45
|
|
|
34
46
|
export default errorTracking
|
package/module/error-tracking.js
CHANGED
|
@@ -1,7 +1,26 @@
|
|
|
1
|
-
import { createErrorTracking } from './create-error-tracking.js'
|
|
2
|
-
|
|
3
1
|
const MODULE_ID = 'errorTracking'
|
|
4
2
|
|
|
3
|
+
const createErrorTracking = ({ errorsAtom, config }) => {
|
|
4
|
+
const track = async ({ error, context, namespace }) => {
|
|
5
|
+
if (!namespace) {
|
|
6
|
+
throw new Error('no namespace provided')
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
return errorsAtom.set(({ errors }) => {
|
|
10
|
+
return {
|
|
11
|
+
// this array can be big. not sure about prefering spread operator here
|
|
12
|
+
// concat function seems like a better option
|
|
13
|
+
errors: [{ namespace, error, context, time: Date.now() }]
|
|
14
|
+
// eslint-disable-next-line unicorn/prefer-spread
|
|
15
|
+
.concat(errors)
|
|
16
|
+
.slice(0, config.maxErrorsCount),
|
|
17
|
+
}
|
|
18
|
+
})
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
return { track }
|
|
22
|
+
}
|
|
23
|
+
|
|
5
24
|
export const errorTrackingDefinition = {
|
|
6
25
|
id: MODULE_ID,
|
|
7
26
|
type: 'module',
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@exodus/error-tracking",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.3.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.",
|
|
@@ -16,7 +16,7 @@
|
|
|
16
16
|
"main": "index.js",
|
|
17
17
|
"exports": "./index.js",
|
|
18
18
|
"files": [
|
|
19
|
-
".",
|
|
19
|
+
"index.d.ts",
|
|
20
20
|
"is-empty.js",
|
|
21
21
|
"api",
|
|
22
22
|
"atoms",
|
|
@@ -28,15 +28,15 @@
|
|
|
28
28
|
],
|
|
29
29
|
"scripts": {
|
|
30
30
|
"test": "run -T jest",
|
|
31
|
-
"lint": "run -T eslint
|
|
31
|
+
"lint": "run -T eslint -c ../../eslint.config.mjs",
|
|
32
32
|
"lint:fix": "yarn lint --fix"
|
|
33
33
|
},
|
|
34
34
|
"dependencies": {
|
|
35
|
-
"@exodus/atoms": "^
|
|
35
|
+
"@exodus/atoms": "^9.0.0",
|
|
36
36
|
"@exodus/basic-utils": "^3.0.1",
|
|
37
37
|
"@exodus/fetch": "^1.3.1",
|
|
38
38
|
"@exodus/sentry-client": "^3.2.0",
|
|
39
39
|
"@exodus/typeforce": "^1.19.0"
|
|
40
40
|
},
|
|
41
|
-
"gitHead": "
|
|
41
|
+
"gitHead": "6172788cc9a82ac74c1228d228e5743b894eb245"
|
|
42
42
|
}
|
|
@@ -1,30 +0,0 @@
|
|
|
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
|
-
}
|