Skip to content

Commit fa40481

Browse files
committed
added test case simulating cls-proxify proxy behavior
1 parent a028e22 commit fa40481

1 file changed

Lines changed: 36 additions & 0 deletions

File tree

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
import * as Sentry from '@sentry/node';
2+
import pino from 'pino';
3+
4+
function createProxiedLogger(originalLogger) {
5+
return new Proxy(originalLogger, {
6+
get(target, prop) {
7+
const value = target[prop];
8+
if (typeof value === 'function') {
9+
return (...args) => {
10+
return value.apply(target, args);
11+
};
12+
}
13+
return value;
14+
}
15+
});
16+
}
17+
18+
const baseLogger = pino({ name: 'proxied-app' });
19+
const proxiedLogger = createProxiedLogger(baseLogger);
20+
21+
Sentry.pinoIntegration.trackLogger(proxiedLogger);
22+
23+
Sentry.withIsolationScope(() => {
24+
Sentry.startSpan({ name: 'startup' }, () => {
25+
proxiedLogger.info({ user: 'user-id', context: 'proxied' }, 'hello from proxied logger');
26+
});
27+
});
28+
29+
setTimeout(() => {
30+
Sentry.withIsolationScope(() => {
31+
Sentry.startSpan({ name: 'later' }, () => {
32+
const child = proxiedLogger.child({ module: 'authentication' });
33+
child.error(new Error('oh no from proxied logger'));
34+
});
35+
});
36+
}, 1000);

0 commit comments

Comments
 (0)