File tree Expand file tree Collapse file tree 1 file changed +7
-4
lines changed Expand file tree Collapse file tree 1 file changed +7
-4
lines changed Original file line number Diff line number Diff line change @@ -87,6 +87,13 @@ function removeCircular(obj: any, refs: any[] = []): any {
8787 * @public
8888 */
8989export function write ( entry : LogEntry ) {
90+ const ctx = traceContext . getStore ( ) ;
91+ if ( ctx ?. traceId ) {
92+ entry [
93+ "logging.googleapis.com/trace"
94+ ] = `projects/${ process . env . GCLOUD_PROJECT } /traces/${ ctx . traceId } ` ;
95+ }
96+
9097 UNPATCHED_CONSOLE [ CONSOLE_SEVERITY [ entry . severity ] ] ( JSON . stringify ( removeCircular ( entry ) ) ) ;
9198}
9299
@@ -147,17 +154,13 @@ function entryFromArgs(severity: LogSeverity, args: any[]): LogEntry {
147154 if ( lastArg && typeof lastArg === "object" && lastArg . constructor === Object ) {
148155 entry = args . pop ( ) ;
149156 }
150- const ctx = traceContext . getStore ( ) ;
151157
152158 // mimic `console.*` behavior, see https://nodejs.org/api/console.html#console_console_log_data_args
153159 let message = format ( ...args ) ;
154160 if ( severity === "ERROR" && ! args . find ( ( arg ) => arg instanceof Error ) ) {
155161 message = new Error ( message ) . stack || message ;
156162 }
157163 const out : LogEntry = {
158- "logging.googleapis.com/trace" : ctx ?. traceId
159- ? `projects/${ process . env . GCLOUD_PROJECT } /traces/${ ctx . traceId } `
160- : undefined ,
161164 ...entry ,
162165 severity,
163166 } ;
You can’t perform that action at this time.
0 commit comments