@exodus/error-tracking 1.2.1 → 1.3.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 +13 -0
- package/LICENSE +7 -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 +0 -1
- package/module/error-tracking.js +21 -2
- package/package.json +10 -8
- package/module/create-error-tracking.js +0 -21
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,19 @@
|
|
|
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.1](https://github.com/ExodusMovement/exodus-hydra/compare/@exodus/error-tracking@1.3.0...@exodus/error-tracking@1.3.1) (2025-01-09)
|
|
7
|
+
|
|
8
|
+
### License
|
|
9
|
+
|
|
10
|
+
- license: re-license under MIT license (#11022)
|
|
11
|
+
|
|
12
|
+
## [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)
|
|
13
|
+
|
|
14
|
+
### Features
|
|
15
|
+
|
|
16
|
+
- add error tracking API types ([#9579](https://github.com/ExodusMovement/exodus-hydra/issues/9579)) ([317e40b](https://github.com/ExodusMovement/exodus-hydra/commit/317e40bde1007f7d192379ab390e3aed0a6ebd1a))
|
|
17
|
+
- use atoms v9 ([#9651](https://github.com/ExodusMovement/exodus-hydra/issues/9651)) ([524aa61](https://github.com/ExodusMovement/exodus-hydra/commit/524aa61f69c81e6ac00b2f94ea830688a105b3e4))
|
|
18
|
+
|
|
6
19
|
## [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)
|
|
7
20
|
|
|
8
21
|
**Note:** Version bump only for package @exodus/error-tracking
|
package/LICENSE
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
Copyright (c) 2024 Exodus Movement, Inc.
|
|
2
|
+
|
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
4
|
+
|
|
5
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
|
6
|
+
|
|
7
|
+
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
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
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.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.",
|
|
@@ -9,14 +9,14 @@
|
|
|
9
9
|
"url": "git+https://github.com/ExodusMovement/exodus-hydra.git"
|
|
10
10
|
},
|
|
11
11
|
"homepage": "https://github.com/ExodusMovement/exodus-hydra/tree/master/features/error-tracking",
|
|
12
|
-
"license": "
|
|
12
|
+
"license": "MIT",
|
|
13
13
|
"bugs": {
|
|
14
14
|
"url": "https://github.com/ExodusMovement/exodus-hydra/issues?q=is%3Aissue+is%3Aopen+label%3Aerror-tracking"
|
|
15
15
|
},
|
|
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",
|
|
@@ -27,16 +27,18 @@
|
|
|
27
27
|
"!**/__tests__/**"
|
|
28
28
|
],
|
|
29
29
|
"scripts": {
|
|
30
|
-
"test": "run -T jest",
|
|
31
|
-
"lint": "run -T eslint
|
|
30
|
+
"test": "run -T exodus-test --jest",
|
|
31
|
+
"lint": "run -T eslint -c ../../eslint.config.mjs",
|
|
32
32
|
"lint:fix": "yarn lint --fix"
|
|
33
33
|
},
|
|
34
34
|
"dependencies": {
|
|
35
|
-
"@exodus/atoms": "^
|
|
36
|
-
"@exodus/basic-utils": "^3.0.1",
|
|
35
|
+
"@exodus/atoms": "^9.0.0",
|
|
37
36
|
"@exodus/fetch": "^1.3.1",
|
|
38
37
|
"@exodus/sentry-client": "^3.2.0",
|
|
39
38
|
"@exodus/typeforce": "^1.19.0"
|
|
40
39
|
},
|
|
41
|
-
"
|
|
40
|
+
"publishConfig": {
|
|
41
|
+
"access": "public"
|
|
42
|
+
},
|
|
43
|
+
"gitHead": "5aa6323e154d95a1a16f4b5039d95b092d907eaf"
|
|
42
44
|
}
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
export const createErrorTracking = ({ errorsAtom, config }) => {
|
|
2
|
-
const track = async ({ error, context, namespace }) => {
|
|
3
|
-
if (!namespace) {
|
|
4
|
-
throw new Error('no namespace provided')
|
|
5
|
-
}
|
|
6
|
-
|
|
7
|
-
return errorsAtom.set(({ errors }) => {
|
|
8
|
-
errors = errors || []
|
|
9
|
-
return {
|
|
10
|
-
// this array can be big. not sure about prefering spread operator here
|
|
11
|
-
// concat function seems like a better option
|
|
12
|
-
errors: [{ namespace, error, context, time: Date.now() }]
|
|
13
|
-
// eslint-disable-next-line unicorn/prefer-spread
|
|
14
|
-
.concat(errors)
|
|
15
|
-
.slice(0, config.maxErrorsCount),
|
|
16
|
-
}
|
|
17
|
-
})
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
return { track }
|
|
21
|
-
}
|