Skip to main content

OpenTelemetry extension for exception

Project description

OpenTelemetry extension for exception

PyPI version

This repository contains a set of utilities for OpenTelemetry's exception for Python.

Installation

pip install opentelemetry-exception-ext

Usage

Add local variables to attributes of exception's event

from opentelemetry.exception.ext import enable_local_variables_recording

enable_local_variables_recording()

When exception is raised, OpenTelemetry automatically creates an event for exception.
enable_local_variables_recording() adds local variables and its function information to the event's attributes automatically by decorating Span.record_exception().
This helps you find the situation where exception happened.

Attributes will be added like below.

{
    "name": "example for enable_local_variables_recording",
    ...,
    "status": {
        "status_code": "ERROR",
        "description": "Exception: exception: hello, 1234, True"
    },
    "events": [
        {
            "name": "exception",
            "attributes": {
                "exception.type": "Exception",
                "exception.message": "exception: hello, 1234, True",
                "exception.stacktrace": "Traceback (most recent call last) ...",
                "exception.escaped": "False",
                "local.var.text_arg": "hello",  // <= Added value for `text_arg`
                "local.var.int_arg": 1234,  // <= Added value for `int_arg`
                "local.var.bool_var": true,  // <= Added value for `bool_var`
                "local.function.filename": "/path/to/enable_local_variables_recording/sample.py",  // <= Added value for filename
                "local.function.name": "raise_exception",  // <= Added value for function name
                "local.function.lineno": 16  // <= Added value for line number of the file
            }
        }
    ]
}

You can see example here.

:warning: When using pre-fork server like Gunicorn, you should call enable_local_variables_recording() before fork to not run same thing multiple times.

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

opentelemetry_exception_ext-0.0.4.tar.gz (5.3 kB view hashes)

Uploaded Source

Built Distribution

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