Skip to main content

Jaeger Logger Reporter

Project description

Jaeger Logger Reporter

This packages enables a way to log your span in a simple way. It provides a LoggerReporter with some configurations. But enables a way to create custom logger reporters.

It extends the jaeger-client packages, change the configuration in a way it's possible use customer logger reporters.

Installation

Running the following command:

$ pip install jaeger-logger

Usage

It's very similar to the jaeger-client, the only difference will be the configuration.

import time
import logging
import sys
from jaeger_logger import LoggerTraceConfig
from jaeger_logger import LoggerTracerReporter


if __name__ == "__main__":

    config = LoggerTraceConfig(
        config={
            'sampler': {
                'type': 'const',
                'param': 1,
            },
            'local_agent': {
                'reporting_host': 'localhost',
                'reporting_port': '5775',
            },
            'logging': True,
            'max_tag_value_length': sys.maxsize
        },
        service_name='test',
        validate=True,
    )

    # define the logger to use, by default LoggerTracerReporter but can be changed.
    tracer = config.initialize_tracer(
        logger=LoggerTracerReporter())

    with tracer.start_span('TestSpan') as span:
        span.log_kv({'event': 'test message', 'life': 42})

        with tracer.start_span('ChildSpan', child_of=span) as child_span:
            child_span.log_kv({'event': 'down below'})

    # yield to IOLoop to flush the spans - https://github.com/jaegertracing/jaeger-client-python/issues/50
    time.sleep(2)
    tracer.close()  # flush any buffered spans

It will produce a logger output similar to:

[INFO][2020-10-12T12:51:25.784749] tracer.logger [TestSpan] STARTED
INFO:tracer.logger:
2020-10-12T12:51:25.784830
[INFO][2020-10-12T12:51:25.784830] tracer.logger [TestSpan][ChildSpan] STARTED
INFO:tracer.logger:
2020-10-12T12:51:25.784837
[DEBUG][2020-10-12T12:51:25.784837] tracer.logger [TestSpan][ChildSpan] LOG down below
DEBUG:tracer.logger:down below
2020-10-12T12:51:25.784852
[INFO][2020-10-12T12:51:25.784852] tracer.logger [TestSpan][ChildSpan] FINISHED  2.2172927856445312e-05s
INFO:tracer.logger: 2.2172927856445312e-05s
2020-10-12T12:51:25.784794
[DEBUG][2020-10-12T12:51:25.784794] tracer.logger [TestSpan] LOG test message 42
DEBUG:tracer.logger:test message 42
2020-10-12T12:51:25.784912
[INFO][2020-10-12T12:51:25.784912] tracer.logger [TestSpan] FINISHED  0.0001628398895263672s
INFO:tracer.logger: 0.0001628398895263672s

LoggerTracerReporter

LoggerTracerReporter have some configurations.

Span identifier

By default the span it's identifier by operation_name eg:

[get_user]

But can be changed:

def span_identifier(span):
    return f'**{span}**'

...
tracer = config.initialize_tracer(
    logger=LoggerTracerReporter(span_identifier=span_identifier))

And the output will be something like:

**79408c731416c394:55150307c2aa6ca8:0:1 test.TestSpan**

Note: if the span has a parent the parent identifier will be display before the span identifier:

[parent_id][span_id]

Logger formatter

The logger follows this formatter:

'%(levelname)s][%(date)s] %(name)s %(span)s %(event)s %(message)s'

Where:

  • levelname is the log level of message;
  • date is the time of event;
  • name is the logger name;
  • span is the span identifier;
  • event is the span event
  • message is the message of the log

The logger can be overrider on LoggerTracerReporterinstaciation.

Span life cycle

Defined tags

There are some Tags keys defined. Can be used to improve the log quality:

  • LOG_HTTP_METHOD
  • LOG_HTTP_URL
  • LOG_HTTP_STATUS_CODE
  • LOG_SPAN_ERROR
  • LOG_SPAN_HTML_DATA
  • LOG_SPAN_HTML_RESPONSE
  • LOG_SPAN_SERIALIZER_RESPONSE

Events

There's some different events types:

STARTED

Identify the start of the event. It will show:

  • date of the begin of the span
  • LOG_HTTP_METHOD and LOG_HTTP_URL if exist, as a message

TAG

Represent a value of a span tag (log_level = DEBUG)

LOG

Represent a value of a log_kv (log_level = DEBUG)`

FINISHED

Identify the end of the event. It will show:

  • date of the end of the span
  • LOG_HTTP_STATUS_CODE if exist, and the duration fo the span as a message

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

jaeger_logger_reporter-0.0.3.tar.gz (5.6 kB view details)

Uploaded Source

Built Distribution

jaeger_logger_reporter-0.0.3-py3-none-any.whl (10.0 kB view details)

Uploaded Python 3

File details

Details for the file jaeger_logger_reporter-0.0.3.tar.gz.

File metadata

  • Download URL: jaeger_logger_reporter-0.0.3.tar.gz
  • Upload date:
  • Size: 5.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/49.2.0 requests-toolbelt/0.9.1 tqdm/4.50.2 CPython/3.8.5

File hashes

Hashes for jaeger_logger_reporter-0.0.3.tar.gz
Algorithm Hash digest
SHA256 7b64f2d395d1051099a6f712056cda3bcfb3a99623ad96fc82c3f54e33e4a4ea
MD5 2ac091f40f93d1fac57c5d0838b35092
BLAKE2b-256 adc75c46f6c4b1437394295b61757ac5a30e8cc51fbdecdae002e32eeb9d3e23

See more details on using hashes here.

File details

Details for the file jaeger_logger_reporter-0.0.3-py3-none-any.whl.

File metadata

  • Download URL: jaeger_logger_reporter-0.0.3-py3-none-any.whl
  • Upload date:
  • Size: 10.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/49.2.0 requests-toolbelt/0.9.1 tqdm/4.50.2 CPython/3.8.5

File hashes

Hashes for jaeger_logger_reporter-0.0.3-py3-none-any.whl
Algorithm Hash digest
SHA256 60efc757c8d96cff00b344baa100c56f080b379dd8ea7b639c7635227e5af28b
MD5 9a18829521c1bede841cc2c3948d60ac
BLAKE2b-256 c9d9ec1e0a28e1255f89a6f3af5c65c2dbe2bd622377ea0c591d55fc938f970a

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page