question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Send trace context with logs from web applications

See original GitHub issue

When running on App Engine (and potentially other platforms in the future), we should send along the trace context when writing logs. This context is available in the HTTP request headers as X-Cloud-Trace-Context and should be passed in the structured log as the traceId. For more details, read here.

Since this is a web request header, we will need to make the core of this web application-framework agnostic. We’ll then need to write helpers/adaptors for Flask and Django.

To my knowledge, we have one blocking bug (#2997) that needs to be resolved before this can happen. Secondly, we need to agree on where the framework helpers should live. (@dhermes). I’m not aware of any other blockers.

Assigned to initially @waprin, as he currently has the most context and can hopefully address open questions and point out any additional pre-work that needs to be done. @liyanhui1228 and @duggelz are the product owners for this, and have offered to provide the implementation.

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:15 (11 by maintainers)

github_iconTop GitHub Comments

1reaction
aatreyacommented, Feb 5, 2018

Your PR fixed the issue for us. Thanks!

0reactions
liyanhui1228commented, Feb 1, 2018

@aatreya Instead of using client.setup_logging(), you can also add handler to a logger like below as described in the document:

import logging
import google.cloud.logging
from google.cloud.logging.handlers import AppEngineHandler

client = google.cloud.logging.Client()
handler = AppEngineHandler(client)
cloud_logger = logging.getLogger('cloudLogger')
cloud_logger.addHandler(handler)

@app.route('/')
def hello():
    handler.labels = handler.get_gae_labels()
    cloud_logger.error('test logging')
    return 'Hello'

Moving the get_gae_labels to emit() function can simplify the code, I have prepared a PR for changing that code path. But you can use the above code as the work around for now.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Trace Context in Logs - AppOptics - SolarWinds Documentation
The trace context inserted into application logs takes the form of a Trace ID that is 40 hex characters followed by a dash...
Read more >
Logs in context of your app and host data
Link your log data with related data across the rest of the New Relic platform by configuring logs in context.
Read more >
Connecting log data to traces | Dynatrace Docs
Automatically connecting log data to traces works for all log data, no matter how the log data was ingested by Dynatrace. You can...
Read more >
Distributed Tracing 101 for Full Stack Developers - Sentry Blog
In the early days of the web, writing web applications was simple. ... how to use tracing metadata to add valuable context to...
Read more >
Using application logs in context with auto config - YouTube
Logs are a critical telemetry type for observability and now, when you upgrade to the latest versions of the Ruby, Java, and ....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found