@drawbridge/drawbridge-telemetry 0.0.5 → 0.0.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/bullmq.cjs +1 -0
- package/dist/bullmq.d.cts +1 -0
- package/dist/bullmq.d.ts +1 -0
- package/dist/bullmq.js +1 -1
- package/dist/{chunk-O6EHU4U7.js → chunk-CODZHH5I.js} +58 -1
- package/dist/index.cjs +59 -1
- package/dist/index.d.cts +119 -7
- package/dist/index.d.ts +119 -7
- package/dist/index.js +3 -1
- package/dist/nextjs.cjs +4 -4
- package/dist/nextjs.d.cts +1 -1
- package/dist/nextjs.d.ts +1 -1
- package/dist/nextjs.js +2 -3
- package/package.json +4 -2
package/dist/bullmq.cjs
CHANGED
|
@@ -38,6 +38,7 @@ var import_crypto = require("crypto");
|
|
|
38
38
|
|
|
39
39
|
// index.js
|
|
40
40
|
var Sentry = __toESM(require("@sentry/node"), 1);
|
|
41
|
+
var import_pino = __toESM(require("pino"), 1);
|
|
41
42
|
var withTraceScope = (traceId, fn) => Sentry.withScope((scope) => {
|
|
42
43
|
if (traceId) scope.setTag("traceId", traceId);
|
|
43
44
|
return fn(scope);
|
package/dist/bullmq.d.cts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { randomUUID } from 'crypto';
|
|
2
2
|
import { currentTraceId, withTraceScope } from './index.cjs';
|
|
3
3
|
import '@sentry/node';
|
|
4
|
+
import 'pino';
|
|
4
5
|
|
|
5
6
|
// Wrap a BullMQ worker handler so it runs inside a Sentry scope tagged
|
|
6
7
|
// with the job's traceId, queue name, and job name. Matches BullMQ's
|
package/dist/bullmq.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { randomUUID } from 'crypto';
|
|
2
2
|
import { currentTraceId, withTraceScope } from './index.js';
|
|
3
3
|
import '@sentry/node';
|
|
4
|
+
import 'pino';
|
|
4
5
|
|
|
5
6
|
// Wrap a BullMQ worker handler so it runs inside a Sentry scope tagged
|
|
6
7
|
// with the job's traceId, queue name, and job name. Matches BullMQ's
|
package/dist/bullmq.js
CHANGED
|
@@ -1,16 +1,72 @@
|
|
|
1
1
|
// index.js
|
|
2
2
|
import * as Sentry from "@sentry/node";
|
|
3
|
+
import pino from "pino";
|
|
3
4
|
var init2 = (config = {}) => Sentry.init({
|
|
4
5
|
dsn: process.env.SENTRY_DSN,
|
|
5
6
|
enableLogs: true,
|
|
6
7
|
environment: process.env.SENTRY_ENVIRONMENT || "localhost",
|
|
7
8
|
tracesSampleRate: 0.1,
|
|
8
9
|
profilesSampleRate: 0.05,
|
|
9
|
-
...config
|
|
10
|
+
...config,
|
|
11
|
+
integrations: [
|
|
12
|
+
Sentry.pinoIntegration(),
|
|
13
|
+
...config.integrations || []
|
|
14
|
+
]
|
|
10
15
|
});
|
|
11
16
|
var captureException2 = (error, options) => Sentry.captureException(error, options);
|
|
12
17
|
var captureMessage2 = (message, options) => Sentry.captureMessage(message, options);
|
|
13
18
|
var logger2 = Sentry.logger;
|
|
19
|
+
var createLogger = ({ eventWriter, level = "info" } = {}) => {
|
|
20
|
+
const isProd = process.env.SENTRY_ENVIRONMENT === "production";
|
|
21
|
+
const pinoConfig = isProd ? { level } : {
|
|
22
|
+
level,
|
|
23
|
+
transport: {
|
|
24
|
+
target: "pino-pretty",
|
|
25
|
+
options: {
|
|
26
|
+
colorize: true,
|
|
27
|
+
translateTime: "SYS:standard"
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
};
|
|
31
|
+
const log = pino(pinoConfig);
|
|
32
|
+
const info = (message, data = {}) => log.info(data, message);
|
|
33
|
+
const warn = (message, data = {}) => log.warn(data, message);
|
|
34
|
+
const error = (first, second) => {
|
|
35
|
+
if (first instanceof Error) {
|
|
36
|
+
Sentry.captureException(first, second);
|
|
37
|
+
log.error(
|
|
38
|
+
{ err: first, ...second },
|
|
39
|
+
first.message
|
|
40
|
+
);
|
|
41
|
+
} else if ((second == null ? void 0 : second.err) instanceof Error) {
|
|
42
|
+
Sentry.captureException(second.err);
|
|
43
|
+
log.error(second, first);
|
|
44
|
+
} else {
|
|
45
|
+
log.error(second || {}, first);
|
|
46
|
+
}
|
|
47
|
+
};
|
|
48
|
+
const emit = async (name, data = {}) => {
|
|
49
|
+
var _a, _b, _c, _d;
|
|
50
|
+
const scope = Sentry.getIsolationScope();
|
|
51
|
+
const scopeData = (_a = scope == null ? void 0 : scope.getScopeData) == null ? void 0 : _a.call(scope);
|
|
52
|
+
const traceId = (_b = scopeData == null ? void 0 : scopeData.tags) == null ? void 0 : _b.traceId;
|
|
53
|
+
const userId = (_c = scopeData == null ? void 0 : scopeData.user) == null ? void 0 : _c.id;
|
|
54
|
+
const organizationId = (_d = scopeData == null ? void 0 : scopeData.tags) == null ? void 0 : _d.organization;
|
|
55
|
+
log.info(
|
|
56
|
+
{ event: name, traceId, userId, organizationId, ...data },
|
|
57
|
+
"event:" + name
|
|
58
|
+
);
|
|
59
|
+
if (eventWriter) {
|
|
60
|
+
await eventWriter(name, {
|
|
61
|
+
traceId,
|
|
62
|
+
userId,
|
|
63
|
+
organizationId,
|
|
64
|
+
data
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
};
|
|
68
|
+
return { info, warn, error, emit };
|
|
69
|
+
};
|
|
14
70
|
var attached = false;
|
|
15
71
|
var attachProcessHandlers = () => {
|
|
16
72
|
if (attached) return;
|
|
@@ -60,6 +116,7 @@ export {
|
|
|
60
116
|
captureException2 as captureException,
|
|
61
117
|
captureMessage2 as captureMessage,
|
|
62
118
|
logger2 as logger,
|
|
119
|
+
createLogger,
|
|
63
120
|
attachProcessHandlers,
|
|
64
121
|
withTraceScope,
|
|
65
122
|
currentTraceId
|
package/dist/index.cjs
CHANGED
|
@@ -33,6 +33,7 @@ __export(index_exports, {
|
|
|
33
33
|
attachProcessHandlers: () => attachProcessHandlers,
|
|
34
34
|
captureException: () => captureException2,
|
|
35
35
|
captureMessage: () => captureMessage2,
|
|
36
|
+
createLogger: () => createLogger,
|
|
36
37
|
currentTraceId: () => currentTraceId,
|
|
37
38
|
init: () => init2,
|
|
38
39
|
logger: () => logger2,
|
|
@@ -40,17 +41,73 @@ __export(index_exports, {
|
|
|
40
41
|
});
|
|
41
42
|
module.exports = __toCommonJS(index_exports);
|
|
42
43
|
var Sentry = __toESM(require("@sentry/node"), 1);
|
|
44
|
+
var import_pino = __toESM(require("pino"), 1);
|
|
43
45
|
var init2 = (config = {}) => Sentry.init({
|
|
44
46
|
dsn: process.env.SENTRY_DSN,
|
|
45
47
|
enableLogs: true,
|
|
46
48
|
environment: process.env.SENTRY_ENVIRONMENT || "localhost",
|
|
47
49
|
tracesSampleRate: 0.1,
|
|
48
50
|
profilesSampleRate: 0.05,
|
|
49
|
-
...config
|
|
51
|
+
...config,
|
|
52
|
+
integrations: [
|
|
53
|
+
Sentry.pinoIntegration(),
|
|
54
|
+
...config.integrations || []
|
|
55
|
+
]
|
|
50
56
|
});
|
|
51
57
|
var captureException2 = (error, options) => Sentry.captureException(error, options);
|
|
52
58
|
var captureMessage2 = (message, options) => Sentry.captureMessage(message, options);
|
|
53
59
|
var logger2 = Sentry.logger;
|
|
60
|
+
var createLogger = ({ eventWriter, level = "info" } = {}) => {
|
|
61
|
+
const isProd = process.env.SENTRY_ENVIRONMENT === "production";
|
|
62
|
+
const pinoConfig = isProd ? { level } : {
|
|
63
|
+
level,
|
|
64
|
+
transport: {
|
|
65
|
+
target: "pino-pretty",
|
|
66
|
+
options: {
|
|
67
|
+
colorize: true,
|
|
68
|
+
translateTime: "SYS:standard"
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
};
|
|
72
|
+
const log = (0, import_pino.default)(pinoConfig);
|
|
73
|
+
const info = (message, data = {}) => log.info(data, message);
|
|
74
|
+
const warn = (message, data = {}) => log.warn(data, message);
|
|
75
|
+
const error = (first, second) => {
|
|
76
|
+
if (first instanceof Error) {
|
|
77
|
+
Sentry.captureException(first, second);
|
|
78
|
+
log.error(
|
|
79
|
+
{ err: first, ...second },
|
|
80
|
+
first.message
|
|
81
|
+
);
|
|
82
|
+
} else if ((second == null ? void 0 : second.err) instanceof Error) {
|
|
83
|
+
Sentry.captureException(second.err);
|
|
84
|
+
log.error(second, first);
|
|
85
|
+
} else {
|
|
86
|
+
log.error(second || {}, first);
|
|
87
|
+
}
|
|
88
|
+
};
|
|
89
|
+
const emit = async (name, data = {}) => {
|
|
90
|
+
var _a, _b, _c, _d;
|
|
91
|
+
const scope = Sentry.getIsolationScope();
|
|
92
|
+
const scopeData = (_a = scope == null ? void 0 : scope.getScopeData) == null ? void 0 : _a.call(scope);
|
|
93
|
+
const traceId = (_b = scopeData == null ? void 0 : scopeData.tags) == null ? void 0 : _b.traceId;
|
|
94
|
+
const userId = (_c = scopeData == null ? void 0 : scopeData.user) == null ? void 0 : _c.id;
|
|
95
|
+
const organizationId = (_d = scopeData == null ? void 0 : scopeData.tags) == null ? void 0 : _d.organization;
|
|
96
|
+
log.info(
|
|
97
|
+
{ event: name, traceId, userId, organizationId, ...data },
|
|
98
|
+
"event:" + name
|
|
99
|
+
);
|
|
100
|
+
if (eventWriter) {
|
|
101
|
+
await eventWriter(name, {
|
|
102
|
+
traceId,
|
|
103
|
+
userId,
|
|
104
|
+
organizationId,
|
|
105
|
+
data
|
|
106
|
+
});
|
|
107
|
+
}
|
|
108
|
+
};
|
|
109
|
+
return { info, warn, error, emit };
|
|
110
|
+
};
|
|
54
111
|
var attached = false;
|
|
55
112
|
var attachProcessHandlers = () => {
|
|
56
113
|
if (attached) return;
|
|
@@ -99,6 +156,7 @@ var currentTraceId = () => {
|
|
|
99
156
|
attachProcessHandlers,
|
|
100
157
|
captureException,
|
|
101
158
|
captureMessage,
|
|
159
|
+
createLogger,
|
|
102
160
|
currentTraceId,
|
|
103
161
|
init,
|
|
104
162
|
logger,
|
package/dist/index.d.cts
CHANGED
|
@@ -1,12 +1,18 @@
|
|
|
1
1
|
import * as Sentry from '@sentry/node';
|
|
2
2
|
export { Sentry };
|
|
3
|
+
import pino from 'pino';
|
|
3
4
|
|
|
4
5
|
// Project-standard Sentry.init wrapper. Sets the conventions used across
|
|
5
6
|
// drawbridge-api / -sync / -webhooks (enableLogs, tracesSampleRate,
|
|
6
|
-
// profilesSampleRate, environment) so each service's init
|
|
7
|
-
// to dsn + any overrides.
|
|
7
|
+
// profilesSampleRate, environment, pinoIntegration) so each service's init
|
|
8
|
+
// call collapses to dsn + any overrides.
|
|
8
9
|
//
|
|
9
|
-
//
|
|
10
|
+
// pinoIntegration() ships with @sentry/node >=10.18 — captures pino logger
|
|
11
|
+
// output as Sentry Logs with the active scope tags attached. Required for
|
|
12
|
+
// createLogger() to flow through to Sentry.
|
|
13
|
+
//
|
|
14
|
+
// Defaults are conservative. Override per service as needed. Consumer-passed
|
|
15
|
+
// integrations append to ours rather than replacing them.
|
|
10
16
|
|
|
11
17
|
const init = ( config = {} ) => Sentry.init({
|
|
12
18
|
dsn : process.env.SENTRY_DSN,
|
|
@@ -14,7 +20,11 @@ const init = ( config = {} ) => Sentry.init({
|
|
|
14
20
|
environment : process.env.SENTRY_ENVIRONMENT || 'localhost',
|
|
15
21
|
tracesSampleRate : 0.1,
|
|
16
22
|
profilesSampleRate : 0.05,
|
|
17
|
-
...config
|
|
23
|
+
...config,
|
|
24
|
+
integrations : [
|
|
25
|
+
Sentry.pinoIntegration(),
|
|
26
|
+
...( config.integrations || [] )
|
|
27
|
+
]
|
|
18
28
|
});
|
|
19
29
|
|
|
20
30
|
// Named re-exports of the Sentry surface services actually use. Keep this
|
|
@@ -24,11 +34,113 @@ const captureException = ( error, options ) => Sentry.captureException( error, o
|
|
|
24
34
|
|
|
25
35
|
const captureMessage = ( message, options ) => Sentry.captureMessage( message, options );
|
|
26
36
|
|
|
27
|
-
// Sentry.logger is the structured-logs surface (ships to Sentry Logs).
|
|
28
|
-
// Exposed as `logger`
|
|
37
|
+
// Sentry.logger is the raw structured-logs surface (ships to Sentry Logs).
|
|
38
|
+
// Exposed as `logger` for one-off `logger.info(...)` / `logger.error(...)`
|
|
39
|
+
// without instantiating a per-service Pino instance. Prefer createLogger()
|
|
40
|
+
// in service code — it adds pretty local stdout, Sentry.captureException
|
|
41
|
+
// dispatch for Error-typed args, and the .event() method for writing
|
|
42
|
+
// domain events to a service-provided eventWriter (Mongo telemetry
|
|
43
|
+
// collection in drawbridge-api).
|
|
29
44
|
|
|
30
45
|
const logger = Sentry.logger;
|
|
31
46
|
|
|
47
|
+
// Build a per-service logger. Pino does the local write (pretty stdout in
|
|
48
|
+
// non-production, JSON in production); Sentry.pinoIntegration in init()
|
|
49
|
+
// auto-captures the same lines as Sentry Logs with active-scope tags
|
|
50
|
+
// (user / organization / traceId / route / method) already attached.
|
|
51
|
+
//
|
|
52
|
+
// info / warn – structured log line
|
|
53
|
+
// error – log line; if first arg is Error (or `data.err` is),
|
|
54
|
+
// also calls Sentry.captureException so the throw lands
|
|
55
|
+
// in Sentry Issues with the same scope context
|
|
56
|
+
// emit(n, d) – emits a Pino info line tagged `event:<n>`, then calls
|
|
57
|
+
// eventWriter( name, { traceId, userId, organizationId,
|
|
58
|
+
// data }) so the caller can persist to its store
|
|
59
|
+
// (drawbridge-api wraps controller.create with the
|
|
60
|
+
// `telemetry` collection)
|
|
61
|
+
//
|
|
62
|
+
// Reads traceId / userId / organizationId from the active Sentry isolation
|
|
63
|
+
// scope so call sites pass only the event-specific payload.
|
|
64
|
+
|
|
65
|
+
const createLogger = ({ eventWriter, level = 'info' } = {}) => {
|
|
66
|
+
|
|
67
|
+
const isProd = process.env.SENTRY_ENVIRONMENT === 'production';
|
|
68
|
+
|
|
69
|
+
const pinoConfig = isProd
|
|
70
|
+
? { level }
|
|
71
|
+
: {
|
|
72
|
+
level,
|
|
73
|
+
transport : {
|
|
74
|
+
target : 'pino-pretty',
|
|
75
|
+
options : {
|
|
76
|
+
colorize : true,
|
|
77
|
+
translateTime : 'SYS:standard'
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
};
|
|
81
|
+
|
|
82
|
+
const log = pino( pinoConfig );
|
|
83
|
+
|
|
84
|
+
const info = ( message, data = {} ) => log.info( data, message );
|
|
85
|
+
|
|
86
|
+
const warn = ( message, data = {} ) => log.warn( data, message );
|
|
87
|
+
|
|
88
|
+
const error = ( first, second ) => {
|
|
89
|
+
|
|
90
|
+
if( first instanceof Error ){
|
|
91
|
+
|
|
92
|
+
Sentry.captureException( first, second );
|
|
93
|
+
|
|
94
|
+
log.error(
|
|
95
|
+
{ err : first, ...second },
|
|
96
|
+
first.message
|
|
97
|
+
);
|
|
98
|
+
|
|
99
|
+
} else if( second?.err instanceof Error ){
|
|
100
|
+
|
|
101
|
+
Sentry.captureException( second.err );
|
|
102
|
+
|
|
103
|
+
log.error( second, first );
|
|
104
|
+
|
|
105
|
+
} else {
|
|
106
|
+
|
|
107
|
+
log.error( second || {}, first );
|
|
108
|
+
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
};
|
|
112
|
+
|
|
113
|
+
const emit = async ( name, data = {} ) => {
|
|
114
|
+
|
|
115
|
+
const scope = Sentry.getIsolationScope();
|
|
116
|
+
const scopeData = scope?.getScopeData?.();
|
|
117
|
+
|
|
118
|
+
const traceId = scopeData?.tags?.traceId;
|
|
119
|
+
const userId = scopeData?.user?.id;
|
|
120
|
+
const organizationId = scopeData?.tags?.organization;
|
|
121
|
+
|
|
122
|
+
log.info(
|
|
123
|
+
{ event : name, traceId, userId, organizationId, ...data },
|
|
124
|
+
'event:' + name
|
|
125
|
+
);
|
|
126
|
+
|
|
127
|
+
if( eventWriter ){
|
|
128
|
+
|
|
129
|
+
await eventWriter( name, {
|
|
130
|
+
traceId,
|
|
131
|
+
userId,
|
|
132
|
+
organizationId,
|
|
133
|
+
data
|
|
134
|
+
});
|
|
135
|
+
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
};
|
|
139
|
+
|
|
140
|
+
return { info, warn, error, emit };
|
|
141
|
+
|
|
142
|
+
};
|
|
143
|
+
|
|
32
144
|
// Diagnostic process-level handlers. Surfaces unhandled async errors to
|
|
33
145
|
// Sentry (without these, modern Node defaults silently exit) and logs
|
|
34
146
|
// exit-path signals to stderr so an operator can diagnose crashes.
|
|
@@ -119,4 +231,4 @@ const currentTraceId = () => {
|
|
|
119
231
|
|
|
120
232
|
};
|
|
121
233
|
|
|
122
|
-
export { attachProcessHandlers, captureException, captureMessage, currentTraceId, init, logger, withTraceScope };
|
|
234
|
+
export { attachProcessHandlers, captureException, captureMessage, createLogger, currentTraceId, init, logger, withTraceScope };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,12 +1,18 @@
|
|
|
1
1
|
import * as Sentry from '@sentry/node';
|
|
2
2
|
export { Sentry };
|
|
3
|
+
import pino from 'pino';
|
|
3
4
|
|
|
4
5
|
// Project-standard Sentry.init wrapper. Sets the conventions used across
|
|
5
6
|
// drawbridge-api / -sync / -webhooks (enableLogs, tracesSampleRate,
|
|
6
|
-
// profilesSampleRate, environment) so each service's init
|
|
7
|
-
// to dsn + any overrides.
|
|
7
|
+
// profilesSampleRate, environment, pinoIntegration) so each service's init
|
|
8
|
+
// call collapses to dsn + any overrides.
|
|
8
9
|
//
|
|
9
|
-
//
|
|
10
|
+
// pinoIntegration() ships with @sentry/node >=10.18 — captures pino logger
|
|
11
|
+
// output as Sentry Logs with the active scope tags attached. Required for
|
|
12
|
+
// createLogger() to flow through to Sentry.
|
|
13
|
+
//
|
|
14
|
+
// Defaults are conservative. Override per service as needed. Consumer-passed
|
|
15
|
+
// integrations append to ours rather than replacing them.
|
|
10
16
|
|
|
11
17
|
const init = ( config = {} ) => Sentry.init({
|
|
12
18
|
dsn : process.env.SENTRY_DSN,
|
|
@@ -14,7 +20,11 @@ const init = ( config = {} ) => Sentry.init({
|
|
|
14
20
|
environment : process.env.SENTRY_ENVIRONMENT || 'localhost',
|
|
15
21
|
tracesSampleRate : 0.1,
|
|
16
22
|
profilesSampleRate : 0.05,
|
|
17
|
-
...config
|
|
23
|
+
...config,
|
|
24
|
+
integrations : [
|
|
25
|
+
Sentry.pinoIntegration(),
|
|
26
|
+
...( config.integrations || [] )
|
|
27
|
+
]
|
|
18
28
|
});
|
|
19
29
|
|
|
20
30
|
// Named re-exports of the Sentry surface services actually use. Keep this
|
|
@@ -24,11 +34,113 @@ const captureException = ( error, options ) => Sentry.captureException( error, o
|
|
|
24
34
|
|
|
25
35
|
const captureMessage = ( message, options ) => Sentry.captureMessage( message, options );
|
|
26
36
|
|
|
27
|
-
// Sentry.logger is the structured-logs surface (ships to Sentry Logs).
|
|
28
|
-
// Exposed as `logger`
|
|
37
|
+
// Sentry.logger is the raw structured-logs surface (ships to Sentry Logs).
|
|
38
|
+
// Exposed as `logger` for one-off `logger.info(...)` / `logger.error(...)`
|
|
39
|
+
// without instantiating a per-service Pino instance. Prefer createLogger()
|
|
40
|
+
// in service code — it adds pretty local stdout, Sentry.captureException
|
|
41
|
+
// dispatch for Error-typed args, and the .event() method for writing
|
|
42
|
+
// domain events to a service-provided eventWriter (Mongo telemetry
|
|
43
|
+
// collection in drawbridge-api).
|
|
29
44
|
|
|
30
45
|
const logger = Sentry.logger;
|
|
31
46
|
|
|
47
|
+
// Build a per-service logger. Pino does the local write (pretty stdout in
|
|
48
|
+
// non-production, JSON in production); Sentry.pinoIntegration in init()
|
|
49
|
+
// auto-captures the same lines as Sentry Logs with active-scope tags
|
|
50
|
+
// (user / organization / traceId / route / method) already attached.
|
|
51
|
+
//
|
|
52
|
+
// info / warn – structured log line
|
|
53
|
+
// error – log line; if first arg is Error (or `data.err` is),
|
|
54
|
+
// also calls Sentry.captureException so the throw lands
|
|
55
|
+
// in Sentry Issues with the same scope context
|
|
56
|
+
// emit(n, d) – emits a Pino info line tagged `event:<n>`, then calls
|
|
57
|
+
// eventWriter( name, { traceId, userId, organizationId,
|
|
58
|
+
// data }) so the caller can persist to its store
|
|
59
|
+
// (drawbridge-api wraps controller.create with the
|
|
60
|
+
// `telemetry` collection)
|
|
61
|
+
//
|
|
62
|
+
// Reads traceId / userId / organizationId from the active Sentry isolation
|
|
63
|
+
// scope so call sites pass only the event-specific payload.
|
|
64
|
+
|
|
65
|
+
const createLogger = ({ eventWriter, level = 'info' } = {}) => {
|
|
66
|
+
|
|
67
|
+
const isProd = process.env.SENTRY_ENVIRONMENT === 'production';
|
|
68
|
+
|
|
69
|
+
const pinoConfig = isProd
|
|
70
|
+
? { level }
|
|
71
|
+
: {
|
|
72
|
+
level,
|
|
73
|
+
transport : {
|
|
74
|
+
target : 'pino-pretty',
|
|
75
|
+
options : {
|
|
76
|
+
colorize : true,
|
|
77
|
+
translateTime : 'SYS:standard'
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
};
|
|
81
|
+
|
|
82
|
+
const log = pino( pinoConfig );
|
|
83
|
+
|
|
84
|
+
const info = ( message, data = {} ) => log.info( data, message );
|
|
85
|
+
|
|
86
|
+
const warn = ( message, data = {} ) => log.warn( data, message );
|
|
87
|
+
|
|
88
|
+
const error = ( first, second ) => {
|
|
89
|
+
|
|
90
|
+
if( first instanceof Error ){
|
|
91
|
+
|
|
92
|
+
Sentry.captureException( first, second );
|
|
93
|
+
|
|
94
|
+
log.error(
|
|
95
|
+
{ err : first, ...second },
|
|
96
|
+
first.message
|
|
97
|
+
);
|
|
98
|
+
|
|
99
|
+
} else if( second?.err instanceof Error ){
|
|
100
|
+
|
|
101
|
+
Sentry.captureException( second.err );
|
|
102
|
+
|
|
103
|
+
log.error( second, first );
|
|
104
|
+
|
|
105
|
+
} else {
|
|
106
|
+
|
|
107
|
+
log.error( second || {}, first );
|
|
108
|
+
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
};
|
|
112
|
+
|
|
113
|
+
const emit = async ( name, data = {} ) => {
|
|
114
|
+
|
|
115
|
+
const scope = Sentry.getIsolationScope();
|
|
116
|
+
const scopeData = scope?.getScopeData?.();
|
|
117
|
+
|
|
118
|
+
const traceId = scopeData?.tags?.traceId;
|
|
119
|
+
const userId = scopeData?.user?.id;
|
|
120
|
+
const organizationId = scopeData?.tags?.organization;
|
|
121
|
+
|
|
122
|
+
log.info(
|
|
123
|
+
{ event : name, traceId, userId, organizationId, ...data },
|
|
124
|
+
'event:' + name
|
|
125
|
+
);
|
|
126
|
+
|
|
127
|
+
if( eventWriter ){
|
|
128
|
+
|
|
129
|
+
await eventWriter( name, {
|
|
130
|
+
traceId,
|
|
131
|
+
userId,
|
|
132
|
+
organizationId,
|
|
133
|
+
data
|
|
134
|
+
});
|
|
135
|
+
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
};
|
|
139
|
+
|
|
140
|
+
return { info, warn, error, emit };
|
|
141
|
+
|
|
142
|
+
};
|
|
143
|
+
|
|
32
144
|
// Diagnostic process-level handlers. Surfaces unhandled async errors to
|
|
33
145
|
// Sentry (without these, modern Node defaults silently exit) and logs
|
|
34
146
|
// exit-path signals to stderr so an operator can diagnose crashes.
|
|
@@ -119,4 +231,4 @@ const currentTraceId = () => {
|
|
|
119
231
|
|
|
120
232
|
};
|
|
121
233
|
|
|
122
|
-
export { attachProcessHandlers, captureException, captureMessage, currentTraceId, init, logger, withTraceScope };
|
|
234
|
+
export { attachProcessHandlers, captureException, captureMessage, createLogger, currentTraceId, init, logger, withTraceScope };
|
package/dist/index.js
CHANGED
|
@@ -3,16 +3,18 @@ import {
|
|
|
3
3
|
attachProcessHandlers,
|
|
4
4
|
captureException,
|
|
5
5
|
captureMessage,
|
|
6
|
+
createLogger,
|
|
6
7
|
currentTraceId,
|
|
7
8
|
init,
|
|
8
9
|
logger,
|
|
9
10
|
withTraceScope
|
|
10
|
-
} from "./chunk-
|
|
11
|
+
} from "./chunk-CODZHH5I.js";
|
|
11
12
|
export {
|
|
12
13
|
Sentry,
|
|
13
14
|
attachProcessHandlers,
|
|
14
15
|
captureException,
|
|
15
16
|
captureMessage,
|
|
17
|
+
createLogger,
|
|
16
18
|
currentTraceId,
|
|
17
19
|
init,
|
|
18
20
|
logger,
|
package/dist/nextjs.cjs
CHANGED
|
@@ -16,6 +16,7 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
16
16
|
}
|
|
17
17
|
return to;
|
|
18
18
|
};
|
|
19
|
+
var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
|
|
19
20
|
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
20
21
|
// If the importer is in node compatibility mode or this is not an ESM
|
|
21
22
|
// file that has been converted to a CommonJS file using a Babel-
|
|
@@ -34,12 +35,11 @@ __export(nextjs_exports, {
|
|
|
34
35
|
captureMessage: () => captureMessage2,
|
|
35
36
|
captureRequestError: () => captureRequestError2,
|
|
36
37
|
init: () => init2,
|
|
37
|
-
logger: () => logger2
|
|
38
|
-
withSentryConfig: () => import_nextjs.withSentryConfig
|
|
38
|
+
logger: () => logger2
|
|
39
39
|
});
|
|
40
40
|
module.exports = __toCommonJS(nextjs_exports);
|
|
41
41
|
var Sentry = __toESM(require("@sentry/nextjs"), 1);
|
|
42
|
-
|
|
42
|
+
__reExport(nextjs_exports, require("@sentry/nextjs"), module.exports);
|
|
43
43
|
var init2 = (config = {}) => Sentry.init({
|
|
44
44
|
dsn: process.env.NEXT_PUBLIC_SENTRY_DSN,
|
|
45
45
|
enableLogs: true,
|
|
@@ -59,5 +59,5 @@ var logger2 = Sentry.logger;
|
|
|
59
59
|
captureRequestError,
|
|
60
60
|
init,
|
|
61
61
|
logger,
|
|
62
|
-
|
|
62
|
+
...require("@sentry/nextjs")
|
|
63
63
|
});
|
package/dist/nextjs.d.cts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import * as Sentry from '@sentry/nextjs';
|
|
2
|
+
export * from '@sentry/nextjs';
|
|
2
3
|
export { Sentry };
|
|
3
|
-
export { withSentryConfig } from '@sentry/nextjs';
|
|
4
4
|
|
|
5
5
|
// @sentry/nextjs surface routed through drawbridge-telemetry so consumer
|
|
6
6
|
// apps (drawbridge-app-web, drawbridge-share) never import @sentry/nextjs
|
package/dist/nextjs.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import * as Sentry from '@sentry/nextjs';
|
|
2
|
+
export * from '@sentry/nextjs';
|
|
2
3
|
export { Sentry };
|
|
3
|
-
export { withSentryConfig } from '@sentry/nextjs';
|
|
4
4
|
|
|
5
5
|
// @sentry/nextjs surface routed through drawbridge-telemetry so consumer
|
|
6
6
|
// apps (drawbridge-app-web, drawbridge-share) never import @sentry/nextjs
|
package/dist/nextjs.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// nextjs.js
|
|
2
2
|
import * as Sentry from "@sentry/nextjs";
|
|
3
|
-
|
|
3
|
+
export * from "@sentry/nextjs";
|
|
4
4
|
var init2 = (config = {}) => Sentry.init({
|
|
5
5
|
dsn: process.env.NEXT_PUBLIC_SENTRY_DSN,
|
|
6
6
|
enableLogs: true,
|
|
@@ -18,6 +18,5 @@ export {
|
|
|
18
18
|
captureMessage2 as captureMessage,
|
|
19
19
|
captureRequestError2 as captureRequestError,
|
|
20
20
|
init2 as init,
|
|
21
|
-
logger2 as logger
|
|
22
|
-
withSentryConfig
|
|
21
|
+
logger2 as logger
|
|
23
22
|
};
|
package/package.json
CHANGED
|
@@ -2,7 +2,9 @@
|
|
|
2
2
|
"type": "module",
|
|
3
3
|
"dependencies": {
|
|
4
4
|
"@drawbridge/drawbridge-agents": "0.0.4",
|
|
5
|
-
"@sentry/node": "10.27.0"
|
|
5
|
+
"@sentry/node": "10.27.0",
|
|
6
|
+
"pino": "10.3.1",
|
|
7
|
+
"pino-pretty": "13.1.3"
|
|
6
8
|
},
|
|
7
9
|
"peerDependencies": {
|
|
8
10
|
"@sentry/nextjs": ">=10"
|
|
@@ -58,5 +60,5 @@
|
|
|
58
60
|
"build": "tsup && npm publish"
|
|
59
61
|
},
|
|
60
62
|
"types": "dist/index.d.ts",
|
|
61
|
-
"version": "0.0.
|
|
63
|
+
"version": "0.0.7"
|
|
62
64
|
}
|