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.

Logging integration design discussion

See original GitHub issue

@c24t wish to know your thoughts as you’ve done the pilot work in #536.

  1. Currently the use_oc_logging works for all loggers created after the call. There is another way to work with loggers created before the call (although it could have wide impact, and only works for Py3.x), should we consider it (which seems to be useful for automatic capturing unhandled exceptions)?
class ContextLogRecord(logging.LogRecord):
    def __init__(self, name, level, pathname, lineno, msg, args, exc_info, func=None, sinfo=None):
        self.trace_id = 'foo'
        self.span_id = 'bar'
        return super(ContextLogRecord, self).__init__(name, level, pathname, lineno, msg, args, exc_info, func, sinfo)

logging.setLogRecordFactory(ContextLogRecord)
  1. Do we want to move use_oc_logging to an ext package and use config_integration?
config_integration.trace_integrations(['logging'])

Issue Analytics

  • State:open
  • Created 4 years ago
  • Comments:9 (9 by maintainers)

github_iconTop GitHub Comments

1reaction
c24tcommented, May 17, 2019

It’s also not clear why BlankSpan has a real span_id in the first place.

0reactions
reyangcommented, May 24, 2019

This is happening today. When we receive an incoming request, we always store the span id in the context. So even if sampling flag is off, we can get the top level local span.

Run the following command against the following Flask app:

curl --header "traceparent: 00-d4e6f7396f0d0e85b3f9f2fad6b4987c-1234567890123456-00" localhost:8080
from flask import Flask
import logging

from opencensus.ext.azure.log_exporter import AzureLogHandler
from opencensus.ext.flask.flask_middleware import FlaskMiddleware
from opencensus.trace import config_integration
from opencensus.trace import execution_context

app = Flask(__name__)
middleware = FlaskMiddleware(app)

config_integration.trace_integrations(['logging'])

logger = logging.getLogger(__name__)
handler = AzureLogHandler()
handler.setFormatter(logging.Formatter('%(traceId)s %(spanId)s %(message)s'))
logger.addHandler(handler)

@app.route('/')
def hello():
    logger.warning('before entering parent span')
    span = execution_context.get_opencensus_tracer().current_span()
    with span.span(name='parent') as parent:
        logger.warning('before entering child span')
        with parent.span(name='child'):
            logger.warning('inside child span')
        logger.warning('after leaving child span')
    logger.warning('after leaving parent span')
    return 'Hello, World!'

if __name__ == '__main__':
    config_integration.trace_integrations(['requests'])
    app.run(host='localhost', port=8080, threaded=True)

This is what we get:

127.0.0.1 - - [23/May/2019 13:17:43] "GET / HTTP/1.1" 200 -
d4e6f7396f0d0e85b3f9f2fad6b4987c 1234567890123456 before entering parent span
d4e6f7396f0d0e85b3f9f2fad6b4987c 1234567890123456 before entering child span
d4e6f7396f0d0e85b3f9f2fad6b4987c 1234567890123456 inside child span
d4e6f7396f0d0e85b3f9f2fad6b4987c 1234567890123456 after leaving child span
d4e6f7396f0d0e85b3f9f2fad6b4987c 1234567890123456 after leaving parent span
Read more comments on GitHub >

github_iconTop Results From Across the Web

Some Thoughts On Logging & API design - AgileVision
I'll will not be arguing here whether it is good or bad because the topic of checked & unchecked exceptions deserves a lengthy...
Read more >
System Design Logging Framework | Implementing Logger
In this video I have implemented a logging framework. Loggers are very common asked low level system design question.
Read more >
5 best practices for designing application logs - CSO Online
Better logs make it easier to distinguish between critical data and noise. Here's how to design logs with security in mind.
Read more >
Logging patterns from within library code
I am looking for a design pattern for logging from within library code. Suppose I have a function in a library file that...
Read more >
Integration monitoring, logging and documentation using BIP
Would you like to discuss how your business could benefit from a modern, future-proof approach to information management? – Contact us at Enfo!...
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