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 {
87
87
* @public
88
88
*/
89
89
export 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
+
90
97
UNPATCHED_CONSOLE [ CONSOLE_SEVERITY [ entry . severity ] ] ( JSON . stringify ( removeCircular ( entry ) ) ) ;
91
98
}
92
99
@@ -147,17 +154,13 @@ function entryFromArgs(severity: LogSeverity, args: any[]): LogEntry {
147
154
if ( lastArg && typeof lastArg === "object" && lastArg . constructor === Object ) {
148
155
entry = args . pop ( ) ;
149
156
}
150
- const ctx = traceContext . getStore ( ) ;
151
157
152
158
// mimic `console.*` behavior, see https://nodejs.org/api/console.html#console_console_log_data_args
153
159
let message = format ( ...args ) ;
154
160
if ( severity === "ERROR" && ! args . find ( ( arg ) => arg instanceof Error ) ) {
155
161
message = new Error ( message ) . stack || message ;
156
162
}
157
163
const out : LogEntry = {
158
- "logging.googleapis.com/trace" : ctx ?. traceId
159
- ? `projects/${ process . env . GCLOUD_PROJECT } /traces/${ ctx . traceId } `
160
- : undefined ,
161
164
...entry ,
162
165
severity,
163
166
} ;
You can’t perform that action at this time.
0 commit comments