@ttt-productions/monitoring-core 0.13.5 → 0.13.7
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/dist/adapter.d.ts +5 -1
- package/dist/adapter.d.ts.map +1 -1
- package/dist/adapter.js.map +1 -1
- package/dist/adapters/noop.js +1 -1
- package/dist/adapters/noop.js.map +1 -1
- package/dist/adapters/sentry-node.d.ts.map +1 -1
- package/dist/adapters/sentry-node.js +25 -13
- package/dist/adapters/sentry-node.js.map +1 -1
- package/dist/adapters/sentry.d.ts.map +1 -1
- package/dist/adapters/sentry.js +18 -8
- package/dist/adapters/sentry.js.map +1 -1
- package/dist/api.d.ts +1 -1
- package/dist/api.d.ts.map +1 -1
- package/dist/api.js +2 -2
- package/dist/api.js.map +1 -1
- package/package.json +1 -1
package/dist/adapter.d.ts
CHANGED
|
@@ -2,7 +2,11 @@ import type { MonitoringInitOptions, MonitoringUser, ScopeLike } from "./types.j
|
|
|
2
2
|
export interface MonitoringAdapter {
|
|
3
3
|
init(options: MonitoringInitOptions): void | Promise<void>;
|
|
4
4
|
captureException(error: unknown, context?: Record<string, unknown>): void;
|
|
5
|
-
|
|
5
|
+
/** `context` follows the same contract as `captureException`: keys become extras,
|
|
6
|
+
* with `tags` (flat string map) and `level` special-cased onto the real Sentry
|
|
7
|
+
* fields — see `capture-context.ts`. The explicit `level` argument remains the
|
|
8
|
+
* message's severity; a `level` inside `context` is applied to the scope. */
|
|
9
|
+
captureMessage(message: string, level?: "fatal" | "error" | "warning" | "info" | "debug", context?: Record<string, unknown>): void;
|
|
6
10
|
setUser(user: MonitoringUser | null): void;
|
|
7
11
|
setTag(key: string, value: string): void;
|
|
8
12
|
withScope?<T>(fn: (scope: ScopeLike) => T): T;
|
package/dist/adapter.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"adapter.d.ts","sourceRoot":"","sources":["../src/adapter.ts"],"names":[],"mappings":"AAAA,OAAO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AS,KAAK,CAAC,GAAG,CAAC,CAAC;IAE9C,aAAa,CAAC,CAAC,UAAU,EAAE;QACzB,QAAQ,CAAC,EAAE,MAAM,CAAC;QAClB,OAAO,CAAC,EAAE,MAAM,CAAC;QACjB,KAAK,CAAC,EAAE,OAAO,GAAG,OAAO,GAAG,SAAS,GAAG,MAAM,GAAG,OAAO,CAAC;QACzD,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;KAChC,GAAG,IAAI,CAAC;CACV"}
|
package/dist/adapter.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"adapter.js","sourceRoot":"","sources":["../src/adapter.ts"],"names":[],"mappings":"","sourcesContent":["import type { MonitoringInitOptions, MonitoringUser, ScopeLike } from \"./types.js\";\n\nexport interface MonitoringAdapter {\n init(options: MonitoringInitOptions): void | Promise<void>;\n\n captureException(error: unknown, context?: Record<string, unknown>): void;\n captureMessage(\n message: string,\n level?: \"fatal\" | \"error\" | \"warning\" | \"info\" | \"debug\"
|
|
1
|
+
{"version":3,"file":"adapter.js","sourceRoot":"","sources":["../src/adapter.ts"],"names":[],"mappings":"","sourcesContent":["import type { MonitoringInitOptions, MonitoringUser, ScopeLike } from \"./types.js\";\n\nexport interface MonitoringAdapter {\n init(options: MonitoringInitOptions): void | Promise<void>;\n\n captureException(error: unknown, context?: Record<string, unknown>): void;\n /** `context` follows the same contract as `captureException`: keys become extras,\n * with `tags` (flat string map) and `level` special-cased onto the real Sentry\n * fields — see `capture-context.ts`. The explicit `level` argument remains the\n * message's severity; a `level` inside `context` is applied to the scope. */\n captureMessage(\n message: string,\n level?: \"fatal\" | \"error\" | \"warning\" | \"info\" | \"debug\",\n context?: Record<string, unknown>\n ): void;\n\n setUser(user: MonitoringUser | null): void;\n setTag(key: string, value: string): void;\n\n withScope?<T>(fn: (scope: ScopeLike) => T): T;\n \n addBreadcrumb?(breadcrumb: {\n category?: string;\n message?: string;\n level?: \"fatal\" | \"error\" | \"warning\" | \"info\" | \"debug\";\n data?: Record<string, unknown>;\n }): void;\n}"]}
|
package/dist/adapters/noop.js
CHANGED
|
@@ -7,7 +7,7 @@ const noopScope = {
|
|
|
7
7
|
export const NoopAdapter = {
|
|
8
8
|
init: (_options) => { },
|
|
9
9
|
captureException: (_error, _context) => { },
|
|
10
|
-
captureMessage: (_message, _level) => { },
|
|
10
|
+
captureMessage: (_message, _level, _context) => { },
|
|
11
11
|
setUser: (_user) => { },
|
|
12
12
|
setTag: (_key, _value) => { },
|
|
13
13
|
withScope: (fn) => fn(noopScope),
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"noop.js","sourceRoot":"","sources":["../../src/adapters/noop.ts"],"names":[],"mappings":"AAGA,MAAM,SAAS,GAAc;IAC3B,MAAM,EAAE,GAAG,EAAE,GAAE,CAAC;IAChB,OAAO,EAAE,GAAG,EAAE,GAAE,CAAC;IACjB,QAAQ,EAAE,GAAG,EAAE,GAAE,CAAC;IAClB,UAAU,EAAE,GAAG,EAAE,GAAE,CAAC;CACrB,CAAC;AAEF,MAAM,CAAC,MAAM,WAAW,GAAsB;IAC5C,IAAI,EAAE,CAAC,QAA+B,EAAE,EAAE,GAAE,CAAC;IAE7C,gBAAgB,EAAE,CAAC,MAAe,EAAE,QAAkC,EAAE,EAAE,GAAE,CAAC;IAC7E,cAAc,EAAE,CAAC,QAAgB,EAAE,MAAY,EAAE,EAAE,GAAE,CAAC;
|
|
1
|
+
{"version":3,"file":"noop.js","sourceRoot":"","sources":["../../src/adapters/noop.ts"],"names":[],"mappings":"AAGA,MAAM,SAAS,GAAc;IAC3B,MAAM,EAAE,GAAG,EAAE,GAAE,CAAC;IAChB,OAAO,EAAE,GAAG,EAAE,GAAE,CAAC;IACjB,QAAQ,EAAE,GAAG,EAAE,GAAE,CAAC;IAClB,UAAU,EAAE,GAAG,EAAE,GAAE,CAAC;CACrB,CAAC;AAEF,MAAM,CAAC,MAAM,WAAW,GAAsB;IAC5C,IAAI,EAAE,CAAC,QAA+B,EAAE,EAAE,GAAE,CAAC;IAE7C,gBAAgB,EAAE,CAAC,MAAe,EAAE,QAAkC,EAAE,EAAE,GAAE,CAAC;IAC7E,cAAc,EAAE,CAAC,QAAgB,EAAE,MAAY,EAAE,QAAkC,EAAE,EAAE,GAAE,CAAC;IAE1F,OAAO,EAAE,CAAC,KAA4B,EAAE,EAAE,GAAE,CAAC;IAC7C,MAAM,EAAE,CAAC,IAAY,EAAE,MAAc,EAAE,EAAE,GAAE,CAAC;IAE5C,SAAS,EAAE,CAAI,EAA2B,EAAE,EAAE,CAAC,EAAE,CAAC,SAAS,CAAC;IAE5D,aAAa,EAAE,CAAC,WAKf,EAAE,EAAE,GAAE,CAAC;CACT,CAAC","sourcesContent":["import type { MonitoringAdapter } from \"../adapter.js\";\nimport type { MonitoringInitOptions, MonitoringUser, ScopeLike } from \"../types.js\";\n\nconst noopScope: ScopeLike = {\n setTag: () => {},\n setUser: () => {},\n setExtra: () => {},\n setContext: () => {},\n};\n\nexport const NoopAdapter: MonitoringAdapter = {\n init: (_options: MonitoringInitOptions) => {},\n\n captureException: (_error: unknown, _context?: Record<string, unknown>) => {},\n captureMessage: (_message: string, _level?: any, _context?: Record<string, unknown>) => {},\n\n setUser: (_user: MonitoringUser | null) => {},\n setTag: (_key: string, _value: string) => {},\n\n withScope: <T>(fn: (scope: ScopeLike) => T) => fn(noopScope),\n \n addBreadcrumb: (_breadcrumb: {\n category?: string;\n message?: string;\n level?: \"fatal\" | \"error\" | \"warning\" | \"info\" | \"debug\";\n data?: Record<string, unknown>;\n }) => {},\n};"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sentry-node.d.ts","sourceRoot":"","sources":["../../src/adapters/sentry-node.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,eAAe,CAAC;AA2BvD,eAAO,MAAM,iBAAiB,EAAE,
|
|
1
|
+
{"version":3,"file":"sentry-node.d.ts","sourceRoot":"","sources":["../../src/adapters/sentry-node.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,eAAe,CAAC;AA2BvD,eAAO,MAAM,iBAAiB,EAAE,iBA0I/B,CAAC"}
|
|
@@ -49,13 +49,27 @@ export const SentryNodeAdapter = {
|
|
|
49
49
|
S.captureException(error);
|
|
50
50
|
})();
|
|
51
51
|
},
|
|
52
|
-
captureMessage(message, level) {
|
|
52
|
+
captureMessage(message, level, context) {
|
|
53
53
|
if (sentryNodeInstance) {
|
|
54
|
+
if (context) {
|
|
55
|
+
sentryNodeInstance.withScope((scope) => {
|
|
56
|
+
applyCaptureContext(scope, context);
|
|
57
|
+
sentryNodeInstance.captureMessage(message, level);
|
|
58
|
+
});
|
|
59
|
+
return;
|
|
60
|
+
}
|
|
54
61
|
sentryNodeInstance.captureMessage(message, level);
|
|
55
62
|
return;
|
|
56
63
|
}
|
|
57
64
|
void (async () => {
|
|
58
65
|
const S = await getSentryNode();
|
|
66
|
+
if (context) {
|
|
67
|
+
S.withScope((scope) => {
|
|
68
|
+
applyCaptureContext(scope, context);
|
|
69
|
+
S.captureMessage(message, level);
|
|
70
|
+
});
|
|
71
|
+
return;
|
|
72
|
+
}
|
|
59
73
|
S.captureMessage(message, level);
|
|
60
74
|
})();
|
|
61
75
|
},
|
|
@@ -79,14 +93,16 @@ export const SentryNodeAdapter = {
|
|
|
79
93
|
S.setTag(key, value);
|
|
80
94
|
})();
|
|
81
95
|
},
|
|
82
|
-
// NOTE: withScope calls `fn` exactly once. When Sentry is
|
|
83
|
-
// (the expected steady state — `init()` awaits the dynamic
|
|
84
|
-
// callers must await `initMonitoring()` before serving traffic),
|
|
85
|
-
// synchronously through the real Sentry scope.
|
|
86
|
-
// pre-load
|
|
87
|
-
// resolution)
|
|
88
|
-
//
|
|
89
|
-
//
|
|
96
|
+
// NOTE: withScope calls `fn` exactly once, on every path. When Sentry is
|
|
97
|
+
// already loaded (the expected steady state — `init()` awaits the dynamic
|
|
98
|
+
// import, and callers must await `initMonitoring()` before serving traffic),
|
|
99
|
+
// it runs synchronously through the real Sentry scope. During the narrow
|
|
100
|
+
// pre-load window (a call that races the very first `getSentryNode()`
|
|
101
|
+
// resolution) it runs against a minimal no-op scope instead, so scope data
|
|
102
|
+
// set in that window is not attached to later events. Callers wrap whole
|
|
103
|
+
// request handlers in `fn`, so re-running it against the real scope once the
|
|
104
|
+
// SDK resolves would re-execute their business logic — losing that window's
|
|
105
|
+
// scope data is the correct tradeoff.
|
|
90
106
|
withScope(fn) {
|
|
91
107
|
if (sentryNodeInstance) {
|
|
92
108
|
let result;
|
|
@@ -101,10 +117,6 @@ export const SentryNodeAdapter = {
|
|
|
101
117
|
setExtra: () => { },
|
|
102
118
|
setContext: () => { },
|
|
103
119
|
};
|
|
104
|
-
void (async () => {
|
|
105
|
-
const S = await getSentryNode();
|
|
106
|
-
S.withScope((scope) => fn(scope));
|
|
107
|
-
})();
|
|
108
120
|
return fn(minimalScope);
|
|
109
121
|
},
|
|
110
122
|
addBreadcrumb(breadcrumb) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sentry-node.js","sourceRoot":"","sources":["../../src/adapters/sentry-node.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAC;AAY5D,IAAI,iBAAiB,GAAmC,IAAI,CAAC;AAC7D,IAAI,kBAAkB,GAA0B,IAAI,CAAC;AAErD,SAAS,aAAa;IACpB,IAAI,CAAC,iBAAiB,EAAE,CAAC;QACvB,iBAAiB,GAAG,MAAM,CAAC,cAAc,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE;YACpD,kBAAkB,GAAG,CAAQ,CAAC;YAC9B,OAAO,kBAAmB,CAAC;QAC7B,CAAC,CAAC,CAAC;IACL,CAAC;IACD,OAAO,iBAAiB,CAAC;AAC3B,CAAC;AAED,MAAM,CAAC,MAAM,iBAAiB,GAAsB;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C;YAChC,CAAC,CAAC,MAAM,CAAC,GAAG,EAAE,KAAK,CAAC,CAAC;QACvB,CAAC,CAAC,EAAE,CAAC;IACP,CAAC;IAED,yEAAyE;IACzE,0EAA0E;IAC1E,6EAA6E;IAC7E,yEAAyE;IACzE,sEAAsE;IACtE,2EAA2E;IAC3E,yEAAyE;IACzE,6EAA6E;IAC7E,4EAA4E;IAC5E,sCAAsC;IACtC,SAAS,CAAI,EAA2B;QACtC,IAAI,kBAAkB,EAAE,CAAC;YACvB,IAAI,MAAS,CAAC;YACd,kBAAkB,CAAC,SAAS,CAAC,CAAC,KAAK,EAAE,EAAE;gBACrC,MAAM,GAAG,EAAE,CAAC,KAAY,CAAC,CAAC;YAC5B,CAAC,CAAC,CAAC;YACH,OAAO,MAAO,CAAC;QACjB,CAAC;QAED,MAAM,YAAY,GAAc;YAC9B,MAAM,EAAE,GAAG,EAAE,GAAE,CAAC;YAChB,OAAO,EAAE,GAAG,EAAE,GAAE,CAAC;YACjB,QAAQ,EAAE,GAAG,EAAE,GAAE,CAAC;YAClB,UAAU,EAAE,GAAG,EAAE,GAAE,CAAC;SACrB,CAAC;QAEF,OAAO,EAAE,CAAC,YAAY,CAAC,CAAC;IAC1B,CAAC;IAED,aAAa,CAAC,UAKb;QACC,IAAI,kBAAkB,EAAE,CAAC;YACvB,kBAAkB,CAAC,aAAa,CAAC,UAAU,CAAC,CAAC;YAC7C,OAAO;QACT,CAAC;QACD,KAAK,CAAC,KAAK,IAAI,EAAE;YACf,MAAM,CAAC,GAAG,MAAM,aAAa,EAAE,CAAC;YAChC,CAAC,CAAC,aAAa,CAAC,UAAU,CAAC,CAAC;QAC9B,CAAC,CAAC,EAAE,CAAC;IACP,CAAC;CACF,CAAC","sourcesContent":["import type { MonitoringAdapter } from \"../adapter.js\";\nimport type { MonitoringInitOptions, MonitoringUser, ScopeLike } from \"../types.js\";\nimport { applyCaptureContext } from \"../capture-context.js\";\n\ntype SentryNodeLike = {\n init: (opts: any) => void;\n captureException: (e: unknown, hint?: any) => void;\n captureMessage: (m: string, level?: any) => void;\n setUser: (u: any) => void;\n setTag: (k: string, v: string) => void;\n withScope: (fn: (scope: any) => void) => void;\n addBreadcrumb: (breadcrumb: any) => void;\n};\n\nlet sentryNodePromise: Promise<SentryNodeLike> | null = null;\nlet sentryNodeInstance: SentryNodeLike | null = null;\n\nfunction getSentryNode(): Promise<SentryNodeLike> {\n if (!sentryNodePromise) {\n sentryNodePromise = import(\"@sentry/node\").then((m) => {\n sentryNodeInstance = m as any;\n return sentryNodeInstance!;\n });\n }\n return sentryNodePromise;\n}\n\nexport const SentryNodeAdapter: MonitoringAdapter = {\n async init(options: MonitoringInitOptions) {\n const enabled = options.enabled ?? true;\n if (!enabled || !options.dsn) return;\n\n const S = await getSentryNode();\n S.init({\n dsn: options.dsn,\n environment: options.environment,\n enabled: true,\n release: options.release,\n ...(options.tracesSampleRate !== undefined ? { tracesSampleRate: options.tracesSampleRate } : {}),\n ...(options.integrations !== undefined ? { integrations: options.integrations } : {}),\n });\n },\n\n captureException(error: unknown, context?: Record<string, unknown>) {\n if (sentryNodeInstance) {\n if (context) {\n sentryNodeInstance.withScope((scope) => {\n applyCaptureContext(scope, context);\n sentryNodeInstance!.captureException(error);\n });\n return;\n }\n sentryNodeInstance.captureException(error);\n return;\n }\n\n void (async () => {\n const S = await getSentryNode();\n\n if (context) {\n S.withScope((scope) => {\n applyCaptureContext(scope, context);\n S.captureException(error);\n });\n return;\n }\n\n S.captureException(error);\n })();\n },\n\n captureMessage(message: string, level?: any, context?: Record<string, unknown>) {\n if (sentryNodeInstance) {\n if (context) {\n sentryNodeInstance.withScope((scope) => {\n applyCaptureContext(scope, context);\n sentryNodeInstance!.captureMessage(message, level);\n });\n return;\n }\n sentryNodeInstance.captureMessage(message, level);\n return;\n }\n\n void (async () => {\n const S = await getSentryNode();\n\n if (context) {\n S.withScope((scope) => {\n applyCaptureContext(scope, context);\n S.captureMessage(message, level);\n });\n return;\n }\n\n S.captureMessage(message, level);\n })();\n },\n\n setUser(user: MonitoringUser | null) {\n if (sentryNodeInstance) {\n sentryNodeInstance.setUser(user as any);\n return;\n }\n void (async () => {\n const S = await getSentryNode();\n S.setUser(user as any);\n })();\n },\n\n setTag(key: string, value: string) {\n if (sentryNodeInstance) {\n sentryNodeInstance.setTag(key, value);\n return;\n }\n void (async () => {\n const S = await getSentryNode();\n S.setTag(key, value);\n })();\n },\n\n // NOTE: withScope calls `fn` exactly once, on every path. When Sentry is\n // already loaded (the expected steady state — `init()` awaits the dynamic\n // import, and callers must await `initMonitoring()` before serving traffic),\n // it runs synchronously through the real Sentry scope. During the narrow\n // pre-load window (a call that races the very first `getSentryNode()`\n // resolution) it runs against a minimal no-op scope instead, so scope data\n // set in that window is not attached to later events. Callers wrap whole\n // request handlers in `fn`, so re-running it against the real scope once the\n // SDK resolves would re-execute their business logic — losing that window's\n // scope data is the correct tradeoff.\n withScope<T>(fn: (scope: ScopeLike) => T): T {\n if (sentryNodeInstance) {\n let result: T;\n sentryNodeInstance.withScope((scope) => {\n result = fn(scope as any);\n });\n return result!;\n }\n\n const minimalScope: ScopeLike = {\n setTag: () => {},\n setUser: () => {},\n setExtra: () => {},\n setContext: () => {},\n };\n\n return fn(minimalScope);\n },\n\n addBreadcrumb(breadcrumb: {\n category?: string;\n message?: string;\n level?: \"fatal\" | \"error\" | \"warning\" | \"info\" | \"debug\";\n data?: Record<string, unknown>;\n }) {\n if (sentryNodeInstance) {\n sentryNodeInstance.addBreadcrumb(breadcrumb);\n return;\n }\n void (async () => {\n const S = await getSentryNode();\n S.addBreadcrumb(breadcrumb);\n })();\n },\n};"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sentry.d.ts","sourceRoot":"","sources":["../../src/adapters/sentry.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,eAAe,CAAC;AA2BvD,eAAO,MAAM,aAAa,EAAE,
|
|
1
|
+
{"version":3,"file":"sentry.d.ts","sourceRoot":"","sources":["../../src/adapters/sentry.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,eAAe,CAAC;AA2BvD,eAAO,MAAM,aAAa,EAAE,iBAuI3B,CAAC"}
|
package/dist/adapters/sentry.js
CHANGED
|
@@ -49,13 +49,27 @@ export const SentryAdapter = {
|
|
|
49
49
|
S.captureException(error);
|
|
50
50
|
})();
|
|
51
51
|
},
|
|
52
|
-
captureMessage(message, level) {
|
|
52
|
+
captureMessage(message, level, context) {
|
|
53
53
|
if (sentryInstance) {
|
|
54
|
+
if (context && sentryInstance.withScope) {
|
|
55
|
+
sentryInstance.withScope((scope) => {
|
|
56
|
+
applyCaptureContext(scope, context);
|
|
57
|
+
sentryInstance.captureMessage(message, level);
|
|
58
|
+
});
|
|
59
|
+
return;
|
|
60
|
+
}
|
|
54
61
|
sentryInstance.captureMessage(message, level);
|
|
55
62
|
return;
|
|
56
63
|
}
|
|
57
64
|
void (async () => {
|
|
58
65
|
const S = await getSentry();
|
|
66
|
+
if (context && S.withScope) {
|
|
67
|
+
S.withScope((scope) => {
|
|
68
|
+
applyCaptureContext(scope, context);
|
|
69
|
+
S.captureMessage(message, level);
|
|
70
|
+
});
|
|
71
|
+
return;
|
|
72
|
+
}
|
|
59
73
|
S.captureMessage(message, level);
|
|
60
74
|
})();
|
|
61
75
|
},
|
|
@@ -87,19 +101,15 @@ export const SentryAdapter = {
|
|
|
87
101
|
});
|
|
88
102
|
return result;
|
|
89
103
|
}
|
|
90
|
-
// Sentry not loaded yet — run
|
|
104
|
+
// Sentry not loaded yet — run `fn` exactly once against a no-op scope. Its
|
|
105
|
+
// scope data is not attached, and it is never replayed against the real
|
|
106
|
+
// scope: `fn` is caller business logic and must not run twice.
|
|
91
107
|
const minimalScope = {
|
|
92
108
|
setTag: () => { },
|
|
93
109
|
setUser: () => { },
|
|
94
110
|
setExtra: () => { },
|
|
95
111
|
setContext: () => { },
|
|
96
112
|
};
|
|
97
|
-
void (async () => {
|
|
98
|
-
const S = await getSentry();
|
|
99
|
-
if (!S.withScope)
|
|
100
|
-
return;
|
|
101
|
-
S.withScope((scope) => fn(scope));
|
|
102
|
-
})();
|
|
103
113
|
return fn(minimalScope);
|
|
104
114
|
},
|
|
105
115
|
addBreadcrumb(breadcrumb) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sentry.js","sourceRoot":"","sources":["../../src/adapters/sentry.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAC;AAY5D,IAAI,aAAa,GAA+B,IAAI,CAAC;AACrD,IAAI,cAAc,GAAsB,IAAI,CAAC;AAE7C,SAAS,SAAS;IAChB,IAAI,CAAC,aAAa,EAAE,CAAC;QACnB,aAAa,GAAG,MAAM,CAAC,gBAAgB,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE;YAClD,cAAc,GAAG,CAAQ,CAAC;YAC1B,OAAO,cAAe,CAAC;QACzB,CAAC,CAAC,CAAC;IACL,CAAC;IACD,OAAO,aAAa,CAAC;AACvB,CAAC;AAED,MAAM,CAAC,MAAM,aAAa,GAAsB;IAC9C,KAAK,CAAC,IAAI,CAAC,OAA8B;QACvC,MAAM,OAAO,GAAG,OAAO,CAAC,OAAO,IAAI,IAAI,CAAC;QACxC,IAAI,CAAC,OAAO,IAAI,CAAC,OAAO,CAAC,GAAG;YAAE,OAAO;QAErC,MAAM,CAAC,GAAG,MAAM,SAAS,EAAE,CAAC;QAC5B,CAAC,CAAC,IAAI,CAAC;YACL,GAAG,EAAE,OAAO,CAAC,GAAG;YAChB,WAAW,EAAE,OAAO,CAAC,WAAW;YAChC,OAAO,EAAE,IAAI;YACb,OAAO,EAAE,OAAO,CAAC,OAAO;YACxB,GAAG,CAAC,OAAO,CAAC,gBAAgB,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,gBAAgB,EAAE,OAAO,CAAC,gBAAgB,EAAE,CAAC,CAAC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+D;QAC/D,MAAM,YAAY,GAAc;YAC9B,MAAM,EAAE,GAAG,EAAE,GAAE,CAAC;YAChB,OAAO,EAAE,GAAG,EAAE,GAAE,CAAC;YACjB,QAAQ,EAAE,GAAG,EAAE,GAAE,CAAC;YAClB,UAAU,EAAE,GAAG,EAAE,GAAE,CAAC;SACrB,CAAC;QAEF,OAAO,EAAE,CAAC,YAAY,CAAC,CAAC;IAC1B,CAAC;IAED,aAAa,CAAC,UAKb;QACC,IAAI,cAAc,EAAE,CAAC;YACnB,IAAI,cAAc,CAAC,aAAa,EAAE,CAAC;gBACjC,cAAc,CAAC,aAAa,CAAC,UAAU,CAAC,CAAC;YAC3C,CAAC;YACD,OAAO;QACT,CAAC;QACD,KAAK,CAAC,KAAK,IAAI,EAAE;YACf,MAAM,CAAC,GAAG,MAAM,SAAS,EAAE,CAAC;YAC5B,IAAI,CAAC,CAAC,aAAa,EAAE,CAAC;gBACpB,CAAC,CAAC,aAAa,CAAC,UAAU,CAAC,CAAC;YAC9B,CAAC;QACH,CAAC,CAAC,EAAE,CAAC;IACP,CAAC;CACF,CAAC","sourcesContent":["import type { MonitoringAdapter } from \"../adapter.js\";\nimport type { MonitoringInitOptions, MonitoringUser, ScopeLike } from \"../types.js\";\nimport { applyCaptureContext } from \"../capture-context.js\";\n\ntype SentryLike = {\n init: (opts: any) => void;\n captureException: (e: unknown) => void;\n captureMessage: (m: string, level?: any) => void;\n setUser: (u: any) => void;\n setTag: (k: string, v: string) => void;\n withScope?: (fn: (scope: any) => void) => void;\n addBreadcrumb?: (breadcrumb: any) => void;\n};\n\nlet sentryPromise: Promise<SentryLike> | null = null;\nlet sentryInstance: SentryLike | null = null;\n\nfunction getSentry(): Promise<SentryLike> {\n if (!sentryPromise) {\n sentryPromise = import(\"@sentry/nextjs\").then((m) => {\n sentryInstance = m as any;\n return sentryInstance!;\n });\n }\n return sentryPromise;\n}\n\nexport const SentryAdapter: MonitoringAdapter = {\n async init(options: MonitoringInitOptions) {\n const enabled = options.enabled ?? true;\n if (!enabled || !options.dsn) return;\n\n const S = await getSentry();\n S.init({\n dsn: options.dsn,\n environment: options.environment,\n enabled: true,\n release: options.release,\n ...(options.tracesSampleRate !== undefined ? { tracesSampleRate: options.tracesSampleRate } : {}),\n ...(options.integrations !== undefined ? { integrations: options.integrations } : {}),\n });\n },\n\n captureException(error: unknown, context?: Record<string, unknown>) {\n if (sentryInstance) {\n if (context && sentryInstance.withScope) {\n sentryInstance.withScope((scope) => {\n applyCaptureContext(scope, context);\n sentryInstance!.captureException(error);\n });\n return;\n }\n sentryInstance.captureException(error);\n return;\n }\n\n void (async () => {\n const S = await getSentry();\n\n if (context && S.withScope) {\n S.withScope((scope) => {\n applyCaptureContext(scope, context);\n S.captureException(error);\n });\n return;\n }\n\n S.captureException(error);\n })();\n },\n\n captureMessage(message: string, level?: any, context?: Record<string, unknown>) {\n if (sentryInstance) {\n if (context && sentryInstance.withScope) {\n sentryInstance.withScope((scope) => {\n applyCaptureContext(scope, context);\n sentryInstance!.captureMessage(message, level);\n });\n return;\n }\n sentryInstance.captureMessage(message, level);\n return;\n }\n\n void (async () => {\n const S = await getSentry();\n\n if (context && S.withScope) {\n S.withScope((scope) => {\n applyCaptureContext(scope, context);\n S.captureMessage(message, level);\n });\n return;\n }\n\n S.captureMessage(message, level);\n })();\n },\n\n setUser(user: MonitoringUser | null) {\n if (sentryInstance) {\n sentryInstance.setUser(user as any);\n return;\n }\n void (async () => {\n const S = await getSentry();\n S.setUser(user as any);\n })();\n },\n\n setTag(key: string, value: string) {\n if (sentryInstance) {\n sentryInstance.setTag(key, value);\n return;\n }\n void (async () => {\n const S = await getSentry();\n S.setTag(key, value);\n })();\n },\n\n withScope<T>(fn: (scope: ScopeLike) => T): T {\n if (sentryInstance && sentryInstance.withScope) {\n let result: T;\n sentryInstance.withScope((scope) => {\n result = fn(scope as any);\n });\n return result!;\n }\n\n // Sentry not loaded yet — run `fn` exactly once against a no-op scope. Its\n // scope data is not attached, and it is never replayed against the real\n // scope: `fn` is caller business logic and must not run twice.\n const minimalScope: ScopeLike = {\n setTag: () => {},\n setUser: () => {},\n setExtra: () => {},\n setContext: () => {},\n };\n\n return fn(minimalScope);\n },\n\n addBreadcrumb(breadcrumb: {\n category?: string;\n message?: string;\n level?: \"fatal\" | \"error\" | \"warning\" | \"info\" | \"debug\";\n data?: Record<string, unknown>;\n }) {\n if (sentryInstance) {\n if (sentryInstance.addBreadcrumb) {\n sentryInstance.addBreadcrumb(breadcrumb);\n }\n return;\n }\n void (async () => {\n const S = await getSentry();\n if (S.addBreadcrumb) {\n S.addBreadcrumb(breadcrumb);\n }\n })();\n },\n};"]}
|
package/dist/api.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { MonitoringUser } from "./types.js";
|
|
2
2
|
export declare function captureException(error: unknown, context?: Record<string, unknown>): void;
|
|
3
|
-
export declare function captureMessage(message: string, level?: "fatal" | "error" | "warning" | "info" | "debug"): void;
|
|
3
|
+
export declare function captureMessage(message: string, level?: "fatal" | "error" | "warning" | "info" | "debug", context?: Record<string, unknown>): void;
|
|
4
4
|
export declare function setUser(user: MonitoringUser | null): void;
|
|
5
5
|
export declare function setTag(key: string, value: string): void;
|
|
6
6
|
export declare function withScope(fn: (scope: any) => any): any;
|
package/dist/api.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"api.d.ts","sourceRoot":"","sources":["../src/api.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAGjD,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,OAAO,EAAE,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,QAEjF;AAED,wBAAgB,cAAc,CAC5B,OAAO,EAAE,MAAM,EACf,KAAK,CAAC,EAAE,OAAO,GAAG,OAAO,GAAG,SAAS,GAAG,MAAM,GAAG,OAAO,
|
|
1
|
+
{"version":3,"file":"api.d.ts","sourceRoot":"","sources":["../src/api.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAGjD,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,OAAO,EAAE,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,QAEjF;AAED,wBAAgB,cAAc,CAC5B,OAAO,EAAE,MAAM,EACf,KAAK,CAAC,EAAE,OAAO,GAAG,OAAO,GAAG,SAAS,GAAG,MAAM,GAAG,OAAO,EACxD,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,QAGlC;AAED,wBAAgB,OAAO,CAAC,IAAI,EAAE,cAAc,GAAG,IAAI,QAElD;AAED,wBAAgB,MAAM,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,QAEhD;AAED,wBAAgB,SAAS,CAAC,EAAE,EAAE,CAAC,KAAK,EAAE,GAAG,KAAK,GAAG,OAQhD;AAED,wBAAgB,aAAa,CAAC,UAAU,EAAE;IACxC,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,KAAK,CAAC,EAAE,OAAO,GAAG,OAAO,GAAG,SAAS,GAAG,MAAM,GAAG,OAAO,CAAC;IACzD,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CAChC,QAKA"}
|
package/dist/api.js
CHANGED
|
@@ -2,8 +2,8 @@ import { getMonitoringAdapter } from "./init.js";
|
|
|
2
2
|
export function captureException(error, context) {
|
|
3
3
|
return getMonitoringAdapter().captureException(error, context);
|
|
4
4
|
}
|
|
5
|
-
export function captureMessage(message, level) {
|
|
6
|
-
return getMonitoringAdapter().captureMessage(message, level);
|
|
5
|
+
export function captureMessage(message, level, context) {
|
|
6
|
+
return getMonitoringAdapter().captureMessage(message, level, context);
|
|
7
7
|
}
|
|
8
8
|
export function setUser(user) {
|
|
9
9
|
return getMonitoringAdapter().setUser(user);
|
package/dist/api.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"api.js","sourceRoot":"","sources":["../src/api.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,oBAAoB,EAAE,MAAM,WAAW,CAAC;AAEjD,MAAM,UAAU,gBAAgB,CAAC,KAAc,EAAE,OAAiC;IAChF,OAAO,oBAAoB,EAAE,CAAC,gBAAgB,CAAC,KAAK,EAAE,OAAO,CAAC,CAAC;AACjE,CAAC;AAED,MAAM,UAAU,cAAc,CAC5B,OAAe,EACf,KAAwD;
|
|
1
|
+
{"version":3,"file":"api.js","sourceRoot":"","sources":["../src/api.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,oBAAoB,EAAE,MAAM,WAAW,CAAC;AAEjD,MAAM,UAAU,gBAAgB,CAAC,KAAc,EAAE,OAAiC;IAChF,OAAO,oBAAoB,EAAE,CAAC,gBAAgB,CAAC,KAAK,EAAE,OAAO,CAAC,CAAC;AACjE,CAAC;AAED,MAAM,UAAU,cAAc,CAC5B,OAAe,EACf,KAAwD,EACxD,OAAiC;IAEjC,OAAO,oBAAoB,EAAE,CAAC,cAAc,CAAC,OAAO,EAAE,KAAK,EAAE,OAAO,CAAC,CAAC;AACxE,CAAC;AAED,MAAM,UAAU,OAAO,CAAC,IAA2B;IACjD,OAAO,oBAAoB,EAAE,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;AAC9C,CAAC;AAED,MAAM,UAAU,MAAM,CAAC,GAAW,EAAE,KAAa;IAC/C,OAAO,oBAAoB,EAAE,CAAC,MAAM,CAAC,GAAG,EAAE,KAAK,CAAC,CAAC;AACnD,CAAC;AAED,MAAM,UAAU,SAAS,CAAC,EAAuB;IAC/C,MAAM,CAAC,GAAG,oBAAoB,EAAE,CAAC;IACjC,OAAO,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,EAAS,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;QAC/C,MAAM,EAAE,GAAG,EAAE,GAAE,CAAC;QAChB,OAAO,EAAE,GAAG,EAAE,GAAE,CAAC;QACjB,QAAQ,EAAE,GAAG,EAAE,GAAE,CAAC;QAClB,UAAU,EAAE,GAAG,EAAE,GAAE,CAAC;KACrB,CAAC,CAAC;AACL,CAAC;AAED,MAAM,UAAU,aAAa,CAAC,UAK7B;IACC,MAAM,CAAC,GAAG,oBAAoB,EAAE,CAAC;IACjC,IAAI,CAAC,CAAC,aAAa,EAAE,CAAC;QACpB,CAAC,CAAC,aAAa,CAAC,UAAU,CAAC,CAAC;IAC9B,CAAC;AACH,CAAC","sourcesContent":["import type { MonitoringUser } from \"./types.js\";\nimport { getMonitoringAdapter } from \"./init.js\";\n\nexport function captureException(error: unknown, context?: Record<string, unknown>) {\n return getMonitoringAdapter().captureException(error, context);\n}\n\nexport function captureMessage(\n message: string,\n level?: \"fatal\" | \"error\" | \"warning\" | \"info\" | \"debug\",\n context?: Record<string, unknown>\n) {\n return getMonitoringAdapter().captureMessage(message, level, context);\n}\n\nexport function setUser(user: MonitoringUser | null) {\n return getMonitoringAdapter().setUser(user);\n}\n\nexport function setTag(key: string, value: string) {\n return getMonitoringAdapter().setTag(key, value);\n}\n\nexport function withScope(fn: (scope: any) => any) {\n const a = getMonitoringAdapter();\n return a.withScope ? a.withScope(fn as any) : fn({\n setTag: () => {},\n setUser: () => {},\n setExtra: () => {},\n setContext: () => {},\n });\n}\n\nexport function addBreadcrumb(breadcrumb: {\n category?: string;\n message?: string;\n level?: \"fatal\" | \"error\" | \"warning\" | \"info\" | \"debug\";\n data?: Record<string, unknown>;\n}) {\n const a = getMonitoringAdapter();\n if (a.addBreadcrumb) {\n a.addBreadcrumb(breadcrumb);\n }\n}"]}
|