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

Add support for adding callables as extra tags and some major improvements #37

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

piotrmaslanka
Copy link

@piotrmaslanka piotrmaslanka commented Mar 20, 2024

Support was added for specifying callables as extra fields. This is super useful if we're trying to attach span_id and trace_id to a log entry in order to cross-match it with a tracing system, such as Jaeger, and we need that data dynamically rather than statically at startup.

Example:

get_context = lambda: tracer.active_span.context
add_trace_id = lambda: hex(get_context().trace_id)[2:] if tracer is not None and tracer.active_span is not None else None
add_span_id = lambda: hex(get_context().span_id)[2:] if tracer is not None and tracer.active_span else None

handler = logging_loki.LokiQueueHandler(
    Queue(-1),
    url="https://my-loki-instance/loki/api/v1/push", 
    tags={"application": "my-app", 'span_id': add_span_id, 'trace_id': add_trace_id},
    auth=("username", "password"),
    version="1"
)

As an added extra, I've added submission of extra logging data, in order to enable more structured logging in the system. The extra data, such as tags, will be attached to

"values": [
    [ "<unix epoch in nanoseconds>", "<log line>", {"trace_id": "0242ac120002", "user_id": "superUser123"}]
]

Additionally, empty tags will be discarded. Previously you had positions like exc_text=None. They won't be sent now.

Please note that labels will be sent only using the V1 Loki protocol.

@piotrmaslanka piotrmaslanka changed the title Add support for adding callables as extra tags Add support for adding callables as extra tags and some major improvements Mar 21, 2024
@piotrmaslanka piotrmaslanka changed the title Add support for adding callables as extra tags and some major improvements Draft: Add support for adding callables as extra tags and some major improvements Mar 21, 2024
@piotrmaslanka piotrmaslanka changed the title Draft: Add support for adding callables as extra tags and some major improvements Add support for adding callables as extra tags and some major improvements Mar 21, 2024
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

Successfully merging this pull request may close these issues.

1 participant