I have a NodeJS project hosted on GKE with trace agent and Stackdriver logging enabled. The project is logging to stdout using winston like this:
const { createLogger, format, transports } = require('winston');
const { combine, json } = format;
const addTraceId = format(info => {
const agent = global._google_trace_agent;
if (agent) {
const traceProjectId = agent.getWriterProjectId();
const traceId = agent.getCurrentContextId();
if (traceProjectId && traceId) {
info['logging.googleapis.com/trace'] = `projects/${traceProjectId}/traces/${traceId}`;
}
}
});
createLogger({
level: 'debug',
transports: new transports.Console()
format: combine(
addTraceId(),
json()
);
});
I can see traceId appear in Stackdriver and consistent across the logs within same trace. But they are all individual log entries instead of collapsed under the first entry.
I checked the request log has header x-cloud-trace-context: "a54d7110fc59c879b7ae67fb481fb89b/113593995793831;o=1" as well.
Also, I'm able to see in the tracing done properly trace list console. And when I deploy the same to GAE I can see logs associated and collapsed under the first entry. Any ideas?

@google-cloud/logging-winston. Not really worth it for just adding traceId and http request formatting (unless I missed something.) Did it manually instead. The problem for me is thattraceIds were attached but Stackdriver UI didn't fold them. - xiangxin