Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GCP logging does not include span and sampled fields in structured logging #674

Open
wabrit opened this issue Sep 19, 2024 · 0 comments
Open

Comments

@wabrit
Copy link

wabrit commented Sep 19, 2024

I'm using version 2.11.0 of the quarkus-google-cloud-logging quarkiverse extension so that I can include tracing information when logging to GCP.

Following the instructions here I've implemented a TraceInfoExtractor that returns the current trace and span ids.

However the resulting payload, while it includes the trace in the format GCP expects, does not include the logging.googleapis.com/spanId value, and logging.googleapis.com/trace_sampled is left defaulted to false.

{
    "severity":"WARNING",
    "time":"2024-09-18T10:31:19.270162900Z",
    "logging.googleapis.com/labels":{},
    "logging.googleapis.com/trace":"projects/myProject/traces/2e6d1e217fe2a1c2c331424649918107",
    "logging.googleapis.com/trace_sampled":false,
       ...
}

Without these additional fields, it is not possible to navigate between traces and logs in the GCP console.

As far as I can see the issue is in the LoggingHandler#transform method from this extension, which omits to call the builder methods to set these (see java comments):

private LogEntry transform(ExtLogRecord record, TraceInfo trace) {
        Payload<?> payload = internalHandler.transform(record, trace);
        if (payload != null) {
            com.google.cloud.logging.LogEntry.Builder builder = LogEntry.newBuilder(payload)
                    .setSeverity(LevelTransformer.toSeverity(record.getLevel()))
                    .setTimestamp(record.getInstant());

           /*
            * Ideally should be setting labels for logging here too i.e.
            *
            * builder.addLabel("levelName", LevelTransformer.toSeverity(record.getLevel()).toString())
            * builder.addLabel("levelValue", String.valueOf(level.intValue()))
            * builder.addLabel("loggerName", extLogRecord.getSourceClassName())
            */ 

            if (this.config.gcpTracing().enabled() && trace != null && !Strings.isNullOrEmpty(trace.getTraceId())) {
                builder = builder.setTrace(composeTraceString(trace.getTraceId()));

               /* Should also be setting these for integrated log/tracing support:
                 *  builder.setSpan(trace.getSpanId())
                 *  builder.setTraceSampled(true) 
                 */
            }
            return builder.build();
        } else {
            return null;
        }
    }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant