You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Mar 11, 2026. It is now read-only.
Repository navigation
This repository was archived by the owner on Mar 11, 2026. It is now read-only.
Reacted by Rémi Chanaud, Guillaume Humbert, Juliusz Gonera, Henrique Silvério, Kaare, Jonathan Dierckens, Armando Borge, Panagiotis Kapros, Pavan Prakash, Mark Paolo Libunao and 12 more
Apart from the level to severity mapping, an important consideration to work with error reporting, the stack trace for errors should be in a specific field, according to an exchange with the Error Reporting team these are message, exception or stack_trace ... @mcollina please correct me if I am wrong but I believe we could configure a pino error serializer slightly different than the standard err serializer to output the error stack on the field expected by Google Cloud Error Reporting (exception or stack_trace are preferred, whereas as message should be saved for https://github.com/pinojs/pino/blob/master/docs/api.md#message-string, where we could put a stack trace in technically, but probably better to leverage the serializer).
The field isn't customizable. Error Reporting will also accept "stack_trace" or "exception" as aliases for "message" (which leaves the "message" field available for a more human readable text).
@mcollina please correct me if I am wrong but I believe we could configure a pino error serializer slightly different than the standard err serializer to output the error stack on the field expected by Google Cloud Error Reporting (exception or stack_trace are preferred,
Conversely, Google Cloud Error Reporting may wish to add err.stack to the aliases of stack trace fields, that way we can take full advantage of pino's error serializer as is.
@simonz130 In case this helps, this is our current config, which most if not all could be offloaded to the plugin. the fact that we add the @type prop to every severity>=ERROR log should probably be an option
import{context,getSpan}from'@opentelemetry/api';import*aspinofrom'pino';// Map Pino levels to Google Cloud Logging severity levels// https://cloud.google.com/logging/docs/reference/v2/rest/v2/LogEntry#LogSeverityconstlevelToSeverity={trace: 'DEBUG',debug: 'DEBUG',info: 'INFO',warn: 'WARNING',error: 'ERROR',fatal: 'CRITICAL',};
export functioninitLogger(opts: {
serviceName: string;level?: pino.Level;format?: 'text'|'json';pinoLoggerOptions?: pino.LoggerOptions;}){const{serviceName, level, format, pinoLoggerOptions}=opts;constprettyPrint=(format||process.env.LOG_FORMAT?.toLowerCase())==='text';returnpino({
...{// https://cloud.google.com/error-reporting/docs/formatting-error-messages#json_representationbase: {serviceContext: {service: serviceName}},formatters: {level(label){constpinoLevel=labelaspino.Level;// `@type` property tells Error Reporting to track even if there is no `stack_trace`consttypeProp=label==='error'||label==='fatal'
? {'@type':
'type.googleapis.com/google.devtools.clouderrorreporting.v1beta1.ReportedErrorEvent',}
: {};return{level: pinoLevel,severity: levelToSeverity[pinoLevel],
...typeProp,};},log(object: object&{err?: Error}){const stackTrace =object.err?.stack;conststackProp=stackTrace ? {stack_trace: stackTrace} : {};return{
...object,
...stackProp,};},},level: level||process.env.LOG_LEVEL?.toLowerCase()||'info',messageKey: 'message',mixin: ()=>getSpan(context.active())?.context()??{},
prettyPrint,timestamp: prettyPrint
? pino.stdTimeFunctions.isoTime
: ()=>`,"eventTime":${Date.now()/1000.0}`,},
...pinoLoggerOptions,});}
Reacted by Brian Torres-Gil, Gus Narea, Thibaut Nguyen, Max Holman, Juliusz Gonera and Yonatan
Reacted by Thibaut Nguyen, Jeff Fasulkey, Juliusz Gonera and Serhii Kozlov
Hi, how is work going on this plugin? We are using Cloud Run and struggling with using "normal" Pino with structured logs. Would be great if there was just a plugin
I missed it when browsing on mobile. Looks good but I don't see way to make it use httpRequest field for structured logging. Is it only for fix severity issue?
Activity
mcollina commentedon Aug 13, 2020
I'm happy to assist/review.
naseemkullah commentedon Aug 13, 2020
Apart from the level to severity mapping, an important consideration to work with error reporting, the stack trace for errors should be in a specific field, according to an exchange with the Error Reporting team these are
message,exceptionorstack_trace... @mcollina please correct me if I am wrong but I believe we could configure a pino error serializer slightly different than the standard err serializer to output the error stack on the field expected by Google Cloud Error Reporting (exceptionorstack_traceare preferred, whereas asmessageshould be saved for https://github.com/pinojs/pino/blob/master/docs/api.md#message-string, where we could put a stack trace in technically, but probably better to leverage the serializer).naseemkullah commentedon Aug 14, 2020
Conversely, Google Cloud Error Reporting may wish to add
err.stackto the aliases of stack trace fields, that way we can take full advantage of pino's error serializer as is.mcollina commentedon Aug 14, 2020
@naseemkullah I think so, yes! See https://www.npmjs.com/package/@elastic/ecs-pino-format as an example for a custom config for a specific cloud provider.
naseemkullah commentedon Sep 10, 2020
@simonz130 In case this helps, this is our current config, which most if not all could be offloaded to the plugin. the fact that we add the
@typeprop to every severity>=ERROR log should probably be an optionteebot commentedon Jan 17, 2021
@naseemkullah thanks for opening this issue and providing the required config for ErrorReporting to work with pino!
1 remaining item
Mistic92 commentedon Apr 12, 2021
Hi, how is work going on this plugin? We are using Cloud Run and struggling with using "normal" Pino with structured logs. Would be great if there was just a plugin
gnarea commentedon Apr 12, 2021
@Mistic92, did you try the library I mentioned in the previous comment?
Mistic92 commentedon Apr 12, 2021
I missed it when browsing on mobile. Looks good but I don't see way to make it use httpRequest field for structured logging. Is it only for fix severity issue?
guillenotfound commentedon Apr 17, 2021
@Mistic92 I created https://github.com/guillenotfound/pino-gcp-logger and so far is working for logging & error reporting 👍
Mistic92 commentedon Apr 19, 2021
@guillenotfound do you have plans for structured logging, trace and httprequest fields?
yoitsro commentedon Jul 8, 2021
Hey! Any updates on this? 🙏 Is there anything we can do to push this forward?
guillenotfound commentedon Feb 20, 2022
Sorry for the late reply, point me to the docs and I'll investigate 👍
jordanebelanger commentedon Jul 11, 2023
This is what I use on CloudRun, it does the job for me.
bkw commentedon Dec 18, 2024
Heads Up: This seems to have been solved by @google-cloud/pino-logging-gcp-config, see https://googlecloudplatform.github.io/cloud-solutions/pino-logging-gcp-config/ for details.
mbrevda commentedon Dec 31, 2024
@google-cloud/pino-logging-gcp-config is an interesting approach, but shouldn't that be a transport instead of taking over the ensure pino settings?
dir commentedon Dec 3, 2025
@mbrevda Yes, yes it should.