File tree Expand file tree Collapse file tree
dev-packages/node-integration-tests/suites/pino Expand file tree Collapse file tree Original file line number Diff line number Diff line change 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 ) ;
You can’t perform that action at this time.
0 commit comments