@exodus/error-tracking 1.2.1 → 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 CHANGED
@@ -3,6 +3,13 @@
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
+
6
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)
7
14
 
8
15
  **Note:** Version bump only for package @exodus/error-tracking
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
- ### With a dependency injection container
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
- ```js
22
- import errorTracking from '@exodus/error-tracking'
15
+ ### Play with it
23
16
 
24
- const ioc = createIocContainer()
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
- const config = { maxErrorsCount: 20 }
27
- ioc.use(errorTracking(config))
21
+ ### API Side
28
22
 
29
- ioc.resolve()
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
- import { createErrorTracking } from '../module/create-error-tracking.js'
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: ({ errorsAtom, config, logger, remoteErrorTracking }) => {
7
- const { track } = createErrorTracking({ errorsAtom, config })
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: ['config', 'errorsAtom', 'logger', 'remoteErrorTracking?'],
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
@@ -0,0 +1,8 @@
1
+ import type errorTrackingApiDefinition from './api/index.js'
2
+
3
+ declare const errorTracking: () => {
4
+ id: 'errorTracking'
5
+ definitions: [{ definition: typeof errorTrackingApiDefinition }]
6
+ }
7
+
8
+ export default errorTracking
package/index.js CHANGED
@@ -26,7 +26,6 @@ const errorTracking = (config = Object.create(null)) => {
26
26
  },
27
27
  {
28
28
  definition: errorTrackingApiDefinition,
29
- config: { maxErrorsCount },
30
29
  },
31
30
  {
32
31
  definition: errorTrackingDefinition,
@@ -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.2.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 . --ignore-path ../../.gitignore",
31
+ "lint": "run -T eslint -c ../../eslint.config.mjs",
32
32
  "lint:fix": "yarn lint --fix"
33
33
  },
34
34
  "dependencies": {
35
- "@exodus/atoms": "^8.0.0",
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": "a667333565279122a2fc2da437dcb62f4ca864bb"
41
+ "gitHead": "6172788cc9a82ac74c1228d228e5743b894eb245"
42
42
  }
@@ -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
- }