55 addExceptionMechanism ,
66 captureException ,
77 captureMessage ,
8+ defineIntegration ,
89 severityLevelFromString ,
910 withScope ,
1011} from '@sentry/core' ;
@@ -24,10 +25,7 @@ type MergeObject = {
2425 err ?: Error ;
2526} ;
2627
27- type PinoHookArgs = {
28- self : Pino ;
29- arguments : [ MergeObject , string , number ] ;
30- } ;
28+ type PinoHookArgs = [ MergeObject , string , number ] ;
3129
3230type Options = {
3331 /**
@@ -57,10 +55,14 @@ function attributesFromObject(obj: object, attr: Record<string, unknown>, key?:
5755 return attr ;
5856}
5957
60- export const pinoIntegration = ( ( options : Options = { eventLevels : [ 'error' , 'fatal' ] , handled : true } ) => {
58+ const DEFAULT_OPTIONS : Options = { eventLevels : [ 'error' , 'fatal' ] , handled : true } ;
59+
60+ export const pinoIntegration = defineIntegration ( ( options : Options = DEFAULT_OPTIONS ) => {
6161 return {
6262 name : 'Pino' ,
63- setup : ( ) => {
63+ setup : client => {
64+ const enableLogs = ! ! client . getOptions ( ) . enableLogs ;
65+
6466 addInstrumentationConfig ( {
6567 channelName : 'pino-log' ,
6668 // From Pino v9.10.0 a tracing channel is available directly from Pino:
@@ -73,10 +75,9 @@ export const pinoIntegration = ((options: Options = { eventLevels: ['error', 'fa
7375 } ) ;
7476
7577 const injectedChannel = tracingChannel ( 'orchestrion:pino:pino-log' ) ;
76- const integratedChannel = tracingChannel ( 'pino_asJson' ) ;
78+ const integratedChannel = tracingChannel ( 'tracing: pino_asJson' ) ;
7779
78- const onPinoStart = ( data : unknown ) : void => {
79- const { self, arguments : args } = data as PinoHookArgs ;
80+ function onPinoStart ( self : Pino , args : PinoHookArgs ) : void {
8081 const [ obj , message , levelNumber ] = args ;
8182 const level = self ?. levels ?. labels ?. [ levelNumber ] || 'info' ;
8283
@@ -85,7 +86,9 @@ export const pinoIntegration = ((options: Options = { eventLevels: ['error', 'fa
8586 'sentry.pino.level' : levelNumber ,
8687 } ) ;
8788
88- _INTERNAL_captureLog ( { level, message, attributes } ) ;
89+ if ( enableLogs ) {
90+ _INTERNAL_captureLog ( { level, message, attributes } ) ;
91+ }
8992
9093 if ( options . eventLevels ?. includes ( level ) ) {
9194 const captureContext = {
@@ -112,10 +115,17 @@ export const pinoIntegration = ((options: Options = { eventLevels: ['error', 'fa
112115 captureMessage ( message , captureContext ) ;
113116 } ) ;
114117 }
115- } ;
118+ }
116119
117- injectedChannel . start . subscribe ( onPinoStart ) ;
118- integratedChannel . start . subscribe ( onPinoStart ) ;
120+ injectedChannel . start . subscribe ( data => {
121+ const { self, arguments : args } = data as { self : Pino ; arguments : PinoHookArgs } ;
122+ onPinoStart ( self , args ) ;
123+ } ) ;
124+
125+ integratedChannel . start . subscribe ( data => {
126+ const { instance, arguments : args } = data as { instance : Pino ; arguments : PinoHookArgs } ;
127+ onPinoStart ( instance , args ) ;
128+ } ) ;
119129 } ,
120130 } ;
121131} ) satisfies IntegrationFn ;
0 commit comments