@molecule/api-error-tracking-sentry 1.0.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/LICENSE +115 -0
- package/dist/browser-guard.d.ts +2 -0
- package/dist/browser-guard.d.ts.map +1 -0
- package/dist/browser-guard.js +19 -0
- package/dist/browser-guard.js.map +1 -0
- package/dist/index.d.ts +40 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +40 -0
- package/dist/index.js.map +1 -0
- package/dist/provider.d.ts +20 -0
- package/dist/provider.d.ts.map +1 -0
- package/dist/provider.js +130 -0
- package/dist/provider.js.map +1 -0
- package/dist/secrets.d.ts +16 -0
- package/dist/secrets.d.ts.map +1 -0
- package/dist/secrets.js +37 -0
- package/dist/secrets.js.map +1 -0
- package/package.json +51 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work.
|
|
38
|
+
|
|
39
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
40
|
+
form, that is based on (or derived from) the Work and for which the
|
|
41
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
42
|
+
represent, as a whole, an original work of authorship.
|
|
43
|
+
|
|
44
|
+
"Contribution" shall mean any work of authorship, including the
|
|
45
|
+
original version of the Work and any modifications or additions
|
|
46
|
+
to that Work, that is intentionally submitted to the Licensor for
|
|
47
|
+
inclusion in the Work by the copyright owner or by an individual or
|
|
48
|
+
Legal Entity authorized to submit on behalf of the copyright owner.
|
|
49
|
+
|
|
50
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
51
|
+
on behalf of whom a Contribution has been received by the Licensor and
|
|
52
|
+
subsequently incorporated within the Work.
|
|
53
|
+
|
|
54
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
55
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
56
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
57
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
58
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
59
|
+
Work and such Derivative Works in Source or Object form.
|
|
60
|
+
|
|
61
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
62
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
63
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
64
|
+
patent license to make, have made, use, offer to sell, sell, import,
|
|
65
|
+
and otherwise transfer the Work.
|
|
66
|
+
|
|
67
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
68
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
69
|
+
modifications, and in Source or Object form, provided that You
|
|
70
|
+
meet the following conditions:
|
|
71
|
+
|
|
72
|
+
(a) You must give any other recipients of the Work or
|
|
73
|
+
Derivative Works a copy of this License; and
|
|
74
|
+
|
|
75
|
+
(b) You must cause any modified files to carry prominent notices
|
|
76
|
+
stating that You changed the files; and
|
|
77
|
+
|
|
78
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
79
|
+
that You distribute, all copyright, patent, trademark, and
|
|
80
|
+
attribution notices from the Source form of the Work,
|
|
81
|
+
excluding those notices that do not pertain to any part of
|
|
82
|
+
the Derivative Works; and
|
|
83
|
+
|
|
84
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
85
|
+
distribution, then any Derivative Works that You distribute must
|
|
86
|
+
include a readable copy of the attribution notices contained
|
|
87
|
+
within such NOTICE file.
|
|
88
|
+
|
|
89
|
+
5. Submission of Contributions.
|
|
90
|
+
|
|
91
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
92
|
+
names, trademarks, service marks, or product names of the Licensor.
|
|
93
|
+
|
|
94
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
95
|
+
agreed to in writing, Licensor provides the Work on an "AS IS" BASIS,
|
|
96
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND.
|
|
97
|
+
|
|
98
|
+
8. Limitation of Liability. In no event and under no legal theory shall
|
|
99
|
+
any Contributor be liable to You for damages.
|
|
100
|
+
|
|
101
|
+
9. Accepting Warranty or Additional Liability.
|
|
102
|
+
|
|
103
|
+
Copyright 2026 Molecule Dev, Inc.
|
|
104
|
+
|
|
105
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
106
|
+
you may not use this file except in compliance with the License.
|
|
107
|
+
You may obtain a copy of the License at
|
|
108
|
+
|
|
109
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
110
|
+
|
|
111
|
+
Unless required by applicable law or agreed to in writing, software
|
|
112
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
113
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
114
|
+
See the License for the specific language governing permissions and
|
|
115
|
+
limitations under the License.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"browser-guard.d.ts","sourceRoot":"","sources":["../src/browser-guard.ts"],"names":[],"mappings":"AAuBA,OAAO,EAAE,CAAA"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Browser guard — `@molecule/api-error-tracking-sentry` is SERVER-ONLY.
|
|
3
|
+
*
|
|
4
|
+
* Generated by scripts/gen-browser-guards.mjs (workspace root) — edit THAT, not this.
|
|
5
|
+
* Evaluating a server package in a browser bundle is always an import-graph mistake
|
|
6
|
+
* (node APIs, secrets); without this guard it surfaces as a cryptic downstream crash
|
|
7
|
+
* ("Buffer is not defined") far from the culprit. Throwing here names the package and
|
|
8
|
+
* the fix at the exact moment the client bundle evaluates it. jsdom tests and SSR are
|
|
9
|
+
* unaffected: the throw requires browser globals AND the absence of a node runtime.
|
|
10
|
+
*/
|
|
11
|
+
const g = globalThis;
|
|
12
|
+
if (g.window !== undefined && g.document !== undefined && !g.process?.versions?.node) {
|
|
13
|
+
throw new Error('@molecule/api-error-tracking-sentry is SERVER-ONLY: it was bundled into browser/client code. Import it only ' +
|
|
14
|
+
'from server code (a server route/function or your API), or dynamic-import it inside ' +
|
|
15
|
+
'the server handler — never from components or shared client modules, and never ' +
|
|
16
|
+
'polyfill Buffer/process to silence this.');
|
|
17
|
+
}
|
|
18
|
+
export {};
|
|
19
|
+
//# sourceMappingURL=browser-guard.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"browser-guard.js","sourceRoot":"","sources":["../src/browser-guard.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AACH,MAAM,CAAC,GAAG,UAIT,CAAA;AACD,IAAI,CAAC,CAAC,MAAM,KAAK,SAAS,IAAI,CAAC,CAAC,QAAQ,KAAK,SAAS,IAAI,CAAC,CAAC,CAAC,OAAO,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC;IACrF,MAAM,IAAI,KAAK,CACb,8GAA8G;QAC5G,sFAAsF;QACtF,iFAAiF;QACjF,0CAA0C,CAC7C,CAAA;AACH,CAAC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Sentry error tracking provider for molecule.dev.
|
|
3
|
+
*
|
|
4
|
+
* Reports exceptions and messages to Sentry via `@sentry/node`, mapping the
|
|
5
|
+
* normalized `@molecule/api-error-tracking` context onto Sentry scopes
|
|
6
|
+
* (tags/user/extra).
|
|
7
|
+
*
|
|
8
|
+
* @see https://www.npmjs.com/package/@sentry/node
|
|
9
|
+
*
|
|
10
|
+
* @module
|
|
11
|
+
* @example
|
|
12
|
+
* ```typescript
|
|
13
|
+
* import { setProvider, captureException } from '@molecule/api-error-tracking'
|
|
14
|
+
* import { provider } from '@molecule/api-error-tracking-sentry'
|
|
15
|
+
*
|
|
16
|
+
* // Bond at startup (e.g. in setupBonds())
|
|
17
|
+
* setProvider(provider)
|
|
18
|
+
*
|
|
19
|
+
* // Anywhere in the app — delivered to Sentry once SENTRY_DSN is set
|
|
20
|
+
* captureException(new Error('boom'), { tags: { source: 'worker' } })
|
|
21
|
+
* ```
|
|
22
|
+
* @remarks
|
|
23
|
+
* - **Without `SENTRY_DSN` the provider is a documented no-op.** It never
|
|
24
|
+
* throws or crashes an app that installed it but hasn't configured the
|
|
25
|
+
* key — captures simply do nothing, and the boot-time config report flags
|
|
26
|
+
* the missing `SENTRY_DSN` with setup instructions.
|
|
27
|
+
* - The SDK is initialized lazily (once) on first use, from `SENTRY_DSN`,
|
|
28
|
+
* optional `SENTRY_ENVIRONMENT` (defaults to `NODE_ENV`), and optional
|
|
29
|
+
* `SENTRY_TRACES_SAMPLE_RATE` (0–1; unset disables tracing).
|
|
30
|
+
* - **A returned event id does NOT confirm delivery.** The SDK buffers and
|
|
31
|
+
* sends asynchronously; a capture can return an id and still never reach
|
|
32
|
+
* Sentry (bad DSN, network egress blocked, process exited too soon). Call
|
|
33
|
+
* `flush(timeoutMs)` before process exit — `false` means events may have
|
|
34
|
+
* been dropped — and check the DSN/network before concluding the
|
|
35
|
+
* integration is broken.
|
|
36
|
+
*/
|
|
37
|
+
export * from './browser-guard.js';
|
|
38
|
+
export * from './provider.js';
|
|
39
|
+
export * from './secrets.js';
|
|
40
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAmCG;AAEH,cAAc,oBAAoB,CAAA;AAClC,cAAc,eAAe,CAAA;AAC7B,cAAc,cAAc,CAAA"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Sentry error tracking provider for molecule.dev.
|
|
3
|
+
*
|
|
4
|
+
* Reports exceptions and messages to Sentry via `@sentry/node`, mapping the
|
|
5
|
+
* normalized `@molecule/api-error-tracking` context onto Sentry scopes
|
|
6
|
+
* (tags/user/extra).
|
|
7
|
+
*
|
|
8
|
+
* @see https://www.npmjs.com/package/@sentry/node
|
|
9
|
+
*
|
|
10
|
+
* @module
|
|
11
|
+
* @example
|
|
12
|
+
* ```typescript
|
|
13
|
+
* import { setProvider, captureException } from '@molecule/api-error-tracking'
|
|
14
|
+
* import { provider } from '@molecule/api-error-tracking-sentry'
|
|
15
|
+
*
|
|
16
|
+
* // Bond at startup (e.g. in setupBonds())
|
|
17
|
+
* setProvider(provider)
|
|
18
|
+
*
|
|
19
|
+
* // Anywhere in the app — delivered to Sentry once SENTRY_DSN is set
|
|
20
|
+
* captureException(new Error('boom'), { tags: { source: 'worker' } })
|
|
21
|
+
* ```
|
|
22
|
+
* @remarks
|
|
23
|
+
* - **Without `SENTRY_DSN` the provider is a documented no-op.** It never
|
|
24
|
+
* throws or crashes an app that installed it but hasn't configured the
|
|
25
|
+
* key — captures simply do nothing, and the boot-time config report flags
|
|
26
|
+
* the missing `SENTRY_DSN` with setup instructions.
|
|
27
|
+
* - The SDK is initialized lazily (once) on first use, from `SENTRY_DSN`,
|
|
28
|
+
* optional `SENTRY_ENVIRONMENT` (defaults to `NODE_ENV`), and optional
|
|
29
|
+
* `SENTRY_TRACES_SAMPLE_RATE` (0–1; unset disables tracing).
|
|
30
|
+
* - **A returned event id does NOT confirm delivery.** The SDK buffers and
|
|
31
|
+
* sends asynchronously; a capture can return an id and still never reach
|
|
32
|
+
* Sentry (bad DSN, network egress blocked, process exited too soon). Call
|
|
33
|
+
* `flush(timeoutMs)` before process exit — `false` means events may have
|
|
34
|
+
* been dropped — and check the DSN/network before concluding the
|
|
35
|
+
* integration is broken.
|
|
36
|
+
*/
|
|
37
|
+
export * from './browser-guard.js';
|
|
38
|
+
export * from './provider.js';
|
|
39
|
+
export * from './secrets.js';
|
|
40
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAmCG;AAEH,cAAc,oBAAoB,CAAA;AAClC,cAAc,eAAe,CAAA;AAC7B,cAAc,cAAc,CAAA"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Sentry error tracking provider implementation.
|
|
3
|
+
*
|
|
4
|
+
* Lazily initializes the Sentry SDK from `SENTRY_DSN` on first use. WITHOUT
|
|
5
|
+
* a DSN every method is a documented no-op — an app that installed the bond
|
|
6
|
+
* but hasn't configured Sentry must keep working untouched (the boot-time
|
|
7
|
+
* config report flags the missing key; see `secrets.ts`).
|
|
8
|
+
*
|
|
9
|
+
* @see https://www.npmjs.com/package/@sentry/node
|
|
10
|
+
*
|
|
11
|
+
* @module
|
|
12
|
+
*/
|
|
13
|
+
import './secrets.js';
|
|
14
|
+
import type { ErrorTrackingProvider } from '@molecule/api-error-tracking';
|
|
15
|
+
/**
|
|
16
|
+
* Sentry error tracking provider. Lazily initialized from `SENTRY_DSN`;
|
|
17
|
+
* every method is a documented no-op while the DSN is unset.
|
|
18
|
+
*/
|
|
19
|
+
export declare const provider: ErrorTrackingProvider;
|
|
20
|
+
//# sourceMappingURL=provider.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"provider.d.ts","sourceRoot":"","sources":["../src/provider.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AASH,OAAO,cAAc,CAAA;AAErB,OAAO,KAAK,EAGV,qBAAqB,EAEtB,MAAM,8BAA8B,CAAA;AAkGrC;;;GAGG;AACH,eAAO,MAAM,QAAQ,EAAE,qBA0BtB,CAAA"}
|
package/dist/provider.js
ADDED
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Sentry error tracking provider implementation.
|
|
3
|
+
*
|
|
4
|
+
* Lazily initializes the Sentry SDK from `SENTRY_DSN` on first use. WITHOUT
|
|
5
|
+
* a DSN every method is a documented no-op — an app that installed the bond
|
|
6
|
+
* but hasn't configured Sentry must keep working untouched (the boot-time
|
|
7
|
+
* config report flags the missing key; see `secrets.ts`).
|
|
8
|
+
*
|
|
9
|
+
* @see https://www.npmjs.com/package/@sentry/node
|
|
10
|
+
*
|
|
11
|
+
* @module
|
|
12
|
+
*/
|
|
13
|
+
import * as Sentry from '@sentry/node';
|
|
14
|
+
import { getLogger } from '@molecule/api-bond';
|
|
15
|
+
const logger = getLogger();
|
|
16
|
+
// Side-effect import: registers this bond's secret definitions so the
|
|
17
|
+
// runtime registry is populated even when provider.js is imported directly
|
|
18
|
+
// (not through the package barrel).
|
|
19
|
+
import './secrets.js';
|
|
20
|
+
/** Whether `Sentry.init()` has already run (it must run exactly once). */
|
|
21
|
+
let initialized = false;
|
|
22
|
+
/**
|
|
23
|
+
* Parses `SENTRY_TRACES_SAMPLE_RATE` into a valid sample rate.
|
|
24
|
+
*
|
|
25
|
+
* @param raw - The raw env var value.
|
|
26
|
+
* @returns A number in [0, 1], or `undefined` when unset/invalid (invalid
|
|
27
|
+
* values are warned about — tracing is then disabled, never crashed on).
|
|
28
|
+
*/
|
|
29
|
+
const parseTracesSampleRate = (raw) => {
|
|
30
|
+
if (raw === undefined || raw === '')
|
|
31
|
+
return undefined;
|
|
32
|
+
const rate = Number(raw);
|
|
33
|
+
if (!Number.isFinite(rate) || rate < 0 || rate > 1) {
|
|
34
|
+
logger.warn(`error-tracking: SENTRY_TRACES_SAMPLE_RATE must be a number between 0 and 1 — got "${raw}"; tracing disabled.`);
|
|
35
|
+
return undefined;
|
|
36
|
+
}
|
|
37
|
+
return rate;
|
|
38
|
+
};
|
|
39
|
+
/**
|
|
40
|
+
* Lazily initializes the Sentry SDK from the environment (exactly once).
|
|
41
|
+
*
|
|
42
|
+
* @returns `true` when Sentry is initialized and captures may proceed;
|
|
43
|
+
* `false` when `SENTRY_DSN` is unset (the documented no-op mode).
|
|
44
|
+
*/
|
|
45
|
+
const ensureInitialized = () => {
|
|
46
|
+
const dsn = process.env.SENTRY_DSN;
|
|
47
|
+
if (!dsn) {
|
|
48
|
+
// Documented no-op: no DSN means the app installed the bond but hasn't
|
|
49
|
+
// configured Sentry. Captures silently do nothing — the boot config
|
|
50
|
+
// report already flags the missing SENTRY_DSN loudly.
|
|
51
|
+
return false;
|
|
52
|
+
}
|
|
53
|
+
if (!initialized) {
|
|
54
|
+
Sentry.init({
|
|
55
|
+
dsn,
|
|
56
|
+
// `||` (not `??`): an empty-string env var means "unset" here.
|
|
57
|
+
environment: process.env.SENTRY_ENVIRONMENT || process.env.NODE_ENV,
|
|
58
|
+
tracesSampleRate: parseTracesSampleRate(process.env.SENTRY_TRACES_SAMPLE_RATE),
|
|
59
|
+
});
|
|
60
|
+
initialized = true;
|
|
61
|
+
}
|
|
62
|
+
return true;
|
|
63
|
+
};
|
|
64
|
+
/**
|
|
65
|
+
* Maps the normalized molecule user to Sentry's user shape.
|
|
66
|
+
*
|
|
67
|
+
* @param user - The normalized user.
|
|
68
|
+
* @returns The equivalent Sentry `User`.
|
|
69
|
+
*/
|
|
70
|
+
const toSentryUser = (user) => ({
|
|
71
|
+
id: user.id,
|
|
72
|
+
email: user.email,
|
|
73
|
+
username: user.username,
|
|
74
|
+
ip_address: user.ipAddress,
|
|
75
|
+
});
|
|
76
|
+
/**
|
|
77
|
+
* Maps the normalized {@link ErrorTrackingContext} to a Sentry capture
|
|
78
|
+
* context (scope partial): `tags` → scope tags, `user` → scope user,
|
|
79
|
+
* `extra` → scope extra, and `request` folded into `extra.request` so it
|
|
80
|
+
* shows up as structured additional data.
|
|
81
|
+
*
|
|
82
|
+
* @param context - The normalized context, if any.
|
|
83
|
+
* @param level - The severity level, if any.
|
|
84
|
+
* @returns The Sentry capture context, or `undefined` when there is nothing to attach.
|
|
85
|
+
*/
|
|
86
|
+
const toCaptureContext = (context, level) => {
|
|
87
|
+
const captureContext = {};
|
|
88
|
+
if (context?.tags)
|
|
89
|
+
captureContext.tags = context.tags;
|
|
90
|
+
if (context?.user)
|
|
91
|
+
captureContext.user = toSentryUser(context.user);
|
|
92
|
+
if (context?.extra || context?.request) {
|
|
93
|
+
captureContext.extra = {
|
|
94
|
+
...context.extra,
|
|
95
|
+
...(context.request ? { request: context.request } : {}),
|
|
96
|
+
};
|
|
97
|
+
}
|
|
98
|
+
if (level)
|
|
99
|
+
captureContext.level = level;
|
|
100
|
+
return Object.keys(captureContext).length > 0 ? captureContext : undefined;
|
|
101
|
+
};
|
|
102
|
+
/**
|
|
103
|
+
* Sentry error tracking provider. Lazily initialized from `SENTRY_DSN`;
|
|
104
|
+
* every method is a documented no-op while the DSN is unset.
|
|
105
|
+
*/
|
|
106
|
+
export const provider = {
|
|
107
|
+
captureException(error, context) {
|
|
108
|
+
if (!ensureInitialized())
|
|
109
|
+
return undefined;
|
|
110
|
+
return Sentry.captureException(error, toCaptureContext(context));
|
|
111
|
+
},
|
|
112
|
+
captureMessage(message, level = 'info', context) {
|
|
113
|
+
if (!ensureInitialized())
|
|
114
|
+
return undefined;
|
|
115
|
+
return Sentry.captureMessage(message, toCaptureContext(context, level));
|
|
116
|
+
},
|
|
117
|
+
setUser(user) {
|
|
118
|
+
if (!ensureInitialized())
|
|
119
|
+
return;
|
|
120
|
+
Sentry.setUser(user ? toSentryUser(user) : null);
|
|
121
|
+
},
|
|
122
|
+
async flush(timeoutMs) {
|
|
123
|
+
// Nothing was ever initialized, so nothing is buffered — report success
|
|
124
|
+
// without touching the SDK (documented no-op mode).
|
|
125
|
+
if (!initialized)
|
|
126
|
+
return true;
|
|
127
|
+
return Sentry.flush(timeoutMs);
|
|
128
|
+
},
|
|
129
|
+
};
|
|
130
|
+
//# sourceMappingURL=provider.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"provider.js","sourceRoot":"","sources":["../src/provider.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,OAAO,KAAK,MAAM,MAAM,cAAc,CAAA;AAEtC,OAAO,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAA;AAC9C,MAAM,MAAM,GAAG,SAAS,EAAE,CAAA;AAC1B,sEAAsE;AACtE,2EAA2E;AAC3E,oCAAoC;AACpC,OAAO,cAAc,CAAA;AASrB,0EAA0E;AAC1E,IAAI,WAAW,GAAG,KAAK,CAAA;AAEvB;;;;;;GAMG;AACH,MAAM,qBAAqB,GAAG,CAAC,GAAuB,EAAsB,EAAE;IAC5E,IAAI,GAAG,KAAK,SA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AA8B;QACpC,IAAI,CAAC,iBAAiB,EAAE;YAAE,OAAM;QAChC,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,YAAY,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAA;IAClD,CAAC;IAED,KAAK,CAAC,KAAK,CAAC,SAAkB;QAC5B,wEAAwE;QACxE,oDAAoD;QACpD,IAAI,CAAC,WAAW;YAAE,OAAO,IAAI,CAAA;QAC7B,OAAO,MAAM,CAAC,KAAK,CAAC,SAAS,CAAC,CAAA;IAChC,CAAC;CACF,CAAA"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Sentry secret definitions — self-registered at import time so the
|
|
3
|
+
* runtime secrets registry (`@molecule/api-secrets`) can drive boot-time
|
|
4
|
+
* configuration reports and actionable "not configured" errors.
|
|
5
|
+
*
|
|
6
|
+
* Content is derived MECHANICALLY from this package's mlcl registry secrets
|
|
7
|
+
* entry (label/instructions/setupUrl/example) via the fleet formula, so
|
|
8
|
+
* packages sharing a key register byte-identical definitions and
|
|
9
|
+
* registration order never matters.
|
|
10
|
+
*
|
|
11
|
+
* @module
|
|
12
|
+
*/
|
|
13
|
+
import type { SecretDefinition } from '@molecule/api-secrets';
|
|
14
|
+
/** Secret definitions required by the Sentry error tracking bond. */
|
|
15
|
+
export declare const sentrySecretDefinitions: SecretDefinition[];
|
|
16
|
+
//# sourceMappingURL=secrets.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"secrets.d.ts","sourceRoot":"","sources":["../src/secrets.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAA;AAG7D,qEAAqE;AACrE,eAAO,MAAM,uBAAuB,EAAE,gBAAgB,EAuBrD,CAAA"}
|
package/dist/secrets.js
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Sentry secret definitions — self-registered at import time so the
|
|
3
|
+
* runtime secrets registry (`@molecule/api-secrets`) can drive boot-time
|
|
4
|
+
* configuration reports and actionable "not configured" errors.
|
|
5
|
+
*
|
|
6
|
+
* Content is derived MECHANICALLY from this package's mlcl registry secrets
|
|
7
|
+
* entry (label/instructions/setupUrl/example) via the fleet formula, so
|
|
8
|
+
* packages sharing a key register byte-identical definitions and
|
|
9
|
+
* registration order never matters.
|
|
10
|
+
*
|
|
11
|
+
* @module
|
|
12
|
+
*/
|
|
13
|
+
import { registerSecrets } from '@molecule/api-secrets';
|
|
14
|
+
/** Secret definitions required by the Sentry error tracking bond. */
|
|
15
|
+
export const sentrySecretDefinitions = [
|
|
16
|
+
{
|
|
17
|
+
key: 'SENTRY_DSN',
|
|
18
|
+
description: 'Sentry DSN — Sentry → Settings → Projects → your project → Client Keys (DSN); copy the DSN. Until it is set the bond is a no-op (no events are sent).',
|
|
19
|
+
helpUrl: 'https://sentry.io/settings/projects/',
|
|
20
|
+
required: true,
|
|
21
|
+
example: 'https://examplePublicKey@o0.ingest.sentry.io/0',
|
|
22
|
+
},
|
|
23
|
+
{
|
|
24
|
+
key: 'SENTRY_ENVIRONMENT',
|
|
25
|
+
description: 'Sentry environment — Environment tag applied to every event (e.g. production, staging); defaults to NODE_ENV when unset.',
|
|
26
|
+
required: false,
|
|
27
|
+
example: 'production',
|
|
28
|
+
},
|
|
29
|
+
{
|
|
30
|
+
key: 'SENTRY_TRACES_SAMPLE_RATE',
|
|
31
|
+
description: 'Sentry traces sample rate — Fraction between 0 and 1 of transactions sampled for performance tracing (e.g. 0.1 = 10%); unset disables tracing.',
|
|
32
|
+
required: false,
|
|
33
|
+
example: '0.1',
|
|
34
|
+
},
|
|
35
|
+
];
|
|
36
|
+
registerSecrets(sentrySecretDefinitions);
|
|
37
|
+
//# sourceMappingURL=secrets.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"secrets.js","sourceRoot":"","sources":["../src/secrets.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAGH,OAAO,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAA;AAEvD,qEAAqE;AACrE,MAAM,CAAC,MAAM,uBAAuB,GAAuB;IACzD;QACE,GAAG,EAAE,YAAY;QACjB,WAAW,EACT,uJAAuJ;QACzJ,OAAO,EAAE,sCAAsC;QAC/C,QAAQ,EAAE,IAAI;QACd,OAAO,EAAE,gDAAgD;KAC1D;IACD;QACE,GAAG,EAAE,oBAAoB;QACzB,WAAW,EACT,0HAA0H;QAC5H,QAAQ,EAAE,KAAK;QACf,OAAO,EAAE,YAAY;KACtB;IACD;QACE,GAAG,EAAE,2BAA2B;QAChC,WAAW,EACT,gJAAgJ;QAClJ,QAAQ,EAAE,KAAK;QACf,OAAO,EAAE,KAAK;KACf;CACF,CAAA;AAED,eAAe,CAAC,uBAAuB,CAAC,CAAA"}
|
package/package.json
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@molecule/api-error-tracking-sentry",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "Sentry error tracking provider for molecule.dev.",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "dist/index.js",
|
|
7
|
+
"types": "dist/index.d.ts",
|
|
8
|
+
"scripts": {
|
|
9
|
+
"build": "tsc",
|
|
10
|
+
"test": "vitest run",
|
|
11
|
+
"test:watch": "vitest"
|
|
12
|
+
},
|
|
13
|
+
"exports": {
|
|
14
|
+
".": {
|
|
15
|
+
"types": "./dist/index.d.ts",
|
|
16
|
+
"import": "./dist/index.js"
|
|
17
|
+
}
|
|
18
|
+
},
|
|
19
|
+
"files": [
|
|
20
|
+
"dist"
|
|
21
|
+
],
|
|
22
|
+
"keywords": [
|
|
23
|
+
"molecule",
|
|
24
|
+
"error-tracking",
|
|
25
|
+
"sentry"
|
|
26
|
+
],
|
|
27
|
+
"license": "Apache-2.0",
|
|
28
|
+
"dependencies": {
|
|
29
|
+
"@sentry/node": "10.69.0"
|
|
30
|
+
},
|
|
31
|
+
"devDependencies": {
|
|
32
|
+
"@types/node": "26.1.2",
|
|
33
|
+
"typescript": "6.0.3",
|
|
34
|
+
"vitest": "4.1.10"
|
|
35
|
+
},
|
|
36
|
+
"peerDependencies": {
|
|
37
|
+
"@molecule/api-bond": "^1.0.0",
|
|
38
|
+
"@molecule/api-error-tracking": "^1.0.0",
|
|
39
|
+
"@molecule/api-secrets": "^1.0.0"
|
|
40
|
+
},
|
|
41
|
+
"repository": {
|
|
42
|
+
"type": "git",
|
|
43
|
+
"url": "https://github.com/molecule-dev/molecule.git",
|
|
44
|
+
"directory": "packages/api/bonds/error-tracking/sentry"
|
|
45
|
+
},
|
|
46
|
+
"homepage": "https://github.com/molecule-dev/molecule/tree/main/packages/api/bonds/error-tracking/sentry",
|
|
47
|
+
"bugs": "https://github.com/molecule-dev/molecule/issues",
|
|
48
|
+
"publishConfig": {
|
|
49
|
+
"access": "public"
|
|
50
|
+
}
|
|
51
|
+
}
|