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
Logging with google-cloud-logging-logback is not grouping request logs #94
Comments
Thanks for the report @mgenov. Could you please provide me with an example of how you are producing your log entries as well as what compute product this application is running on? |
@mgenov Is this still an issue for you? |
Closing due to lack of response. Please reopen if you are still experiencing issues. |
@codyoss this is still an issue. Can we reopen it? I"m trying to setup stack driver logging for my GAE web application but i'm having issue getting the traceLoggingEnhancer provided by google to work properly. Library: https://github.com/googleapis/google-cloud-java/issues/6061 I've created a repo of the example: https://github.com/darewreck54/GoogleTraceIdExample Goal: I wanted to associate a trace ID with all the logs that occur from one request. In the code, i'm using dropwizard web framework hooked up with slf4j logging. From my understanding, all i need to do is create a Filter and an Appender. The filter called TraceLogFilter.java would either grab a unique ID from X_CLOUD_TRACE or generate one. It will store the ID in TraceLoggerEnhancer.setCurrentTraceId() which every web request would hit. I also created a log appender called ConsoleJsonAppenderFactory.java labeled with 'cloud-stackdriver'. I add this to the dropwizard equivalent of logback.xml in /config/dropWizardConfig-dev.yaml or /config/dropWizardConfig-stage.yaml. Whenever a log was made. ex: log.INFO("test") it should trigger the log appender which would then add should call setTrace in the TraceLoggingEnhancer::enhanceLogEntry. However, when i step through the code this isn't happening. What i'm seeing is that the traceId is set to null but that part doesn't make sense unless there is some threading issue i'm not seeing. Here is an example so that you can get a better example:
@get When you trigger the endpoint without a date param, you will hit the else statement. The code first make sure the trace ID is stored and it is so it prints out the traceId. Then it triggers the LOGGER.warn. If you step through the code it hits the the TraceLoggingEnhancer::enhanceLogEntry(). In this it tries to get the traceId, but it's null. As a result, it never gets added to the log message. This is the part that doesn't make sense to me because prior to this I retrieved the traceId correctly and it wasn't null. The only thing that I can think is somehow they are on different threads and it's not clear how you are support set it up properly. log coniguration: https://github.com/darewreck54/GoogleTraceIdExample/blob/master/config/dropWizardConfig-dev.yaml Customer Logger: https://github.com/darewreck54/GoogleTraceIdExample/blob/master/src/main/java/com/example/google_trace_example/logger/ConsoleJsonAppenderFactory.java. Documentation is really limiting to so it's hard to figure out what is suppose to be correct. Existing doc: https://cloud.google.com/logging/docs/setup/java#jul_config |
@darewreck54 Thank you for your detailed report. |
cc @chingor13 |
@simonz130 Thanks for the clarification. Whats the ETA for this new feature and is there something I can subscribe to so that I can follow it? Just out of curiosity what was the intention of the usage of TraceLoggingEnhancer. I figured that being able to associate a traceId generated from a request would be a common use case. Am I using it incorrectly? |
I played with this before I saw this issue. And it seems that it works if you implement
But I tried with just few requests and not with a lot of traffic. Hope this helps. |
While a roundabout way, what @asodja proposes is, in fact, the solution. At the start of your request, you need to grab the |
@pouyanjazayeri Thanks for collecting the full solution - eventually, I arrived at the same conclusion and it's been running fine for a year now. The only pain point is that it requires a |
adding the solution again since I deleted it by mistake: add the following to your logback config file:
the use an http filter to set the trace in the MDC:
replace YOUR_PROJECT_ID with your actual project id. Note that only the first part before "/" is used from the x-cloud-trace-context header. Now the logs should be grouped in the request log. |
Environment details
Steps to reproduce
Code example
Any additional information below
The log lines: line1 and line2 are not rendered as single log entry as on GAE or on Flexible Environment.
The text was updated successfully, but these errors were encountered: