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 details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

opentelemetry_exception_ext-0.0.4-py3-none-any.whl (4.8 kB view details)

Uploaded Python 3

File details

Details for the file opentelemetry_exception_ext-0.0.4.tar.gz.

File metadata

File hashes

Hashes for opentelemetry_exception_ext-0.0.4.tar.gz
Algorithm Hash digest
SHA256 651e78f6a1f50e3acb57e5dae278cbda43fb530383d6935a1d7450bfb20baa19
MD5 4025ff7585deb28fb87faeb129920d93
BLAKE2b-256 7c4b826800fed30de253857209a4d368edf0d43bf2f403be95d100ffcb4d0763

See more details on using hashes here.

File details

Details for the file opentelemetry_exception_ext-0.0.4-py3-none-any.whl.

File metadata

File hashes

Hashes for opentelemetry_exception_ext-0.0.4-py3-none-any.whl
Algorithm Hash digest
SHA256 b94492ab7f69e3883d6ecf25d57ef373e35082ca12039ddfee05e960246adbfa
MD5 35a1108430a3172738f747673db22ab3
BLAKE2b-256 bdba1cfb37e4e38196ca5e9afe04ff9db9e90730456026182f7eee1802cf80bb

See more details on using hashes here.

Supported by

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