Distributed tracing made easy for python
Project description
PyTraceKit
PyTraceKit, is a low code solution designed to simplify the integration of distributed tracing into Python microservices through the power of OpenTelemetry. This package provides straightforward approach to enrich your logging with trace IDs and allowing detailed tracing with minimal setup.
The package comes with inbuilt support for Falcon, FastAPI , Flask ,redis , MongoDB
Key Features
- Simplified Tracing: Easily integrate distributed tracing into FastAPI, Flask, or Falcon applications with just one line of code.
- Function-Level Tracing with Customization: Add detailed tracing to any function, specifying custom operation names and span attributes for in-depth observability.
- Advanced Logging: Each log message includes a trace ID for easy correlation, with customizable logging settings such as file paths, sizes, and rotation.
- Framework Agnostic: Automatically detects and integrates with your Python web framework, offering out-of-the-box support for FastAPI, Flask, and Falcon.
- Extensibility: Adapt and extend PyTraceKit to suit your specific tracing and logging needs.
Installation
To install PyTraceKit, run the following command in your terminal:
pip install pytracekit
Getting Started
Setup the environment variables (These environment varaibles are mandatory)
export TRACE_SERVICE_NAME=your service name
export TRACING_ENDPOINT=http://localhost:4317/api/traces # your collector endpoint
export ENABLE_TRACING=true
For FastAPI or Flask:
from pytracekit import instrument
# Assuming `app` is your FastAPI or Flask application instance
instrument(app)
For Falcon
from pytracekit import instrument
# Instrument before defining your Falcon app
instrument()
app = falcon.App() # Now define your Falcon app
Add Function-Level Tracing
PyTraceKit allows you to add tracing to specific functions using the @instrument_with_tracing decorator. You can specify a custom operation name and additional span attributes for detailed tracing:
Simple Function Level Tracing
from pytracekit import instrument_with_tracing
@instrument_with_tracing()
def process_data():
# Your function logic here
Function level tracing with custom operation name and custom span attributes
from pytracekit import instrument_with_tracing
@instrument_with_tracing(operation_name="custom_operation", span_attrs={"key": "value"})
def process_data():
# Your function logic here
Setup Enhanced Logging
To take advantage of PyTraceKit's enhanced logging capabilities, use the get_logger function. This allows you to create a logger that includes trace IDs in log messages, making it easier to correlate logs with traces:
Standard Logger
from pytracekit import get_logger
logger = get_logger()
# Now you can use `logger` to log messages that include trace IDs
logger.info("This log entry includes a trace ID.")
Logger with User Arguments
from pytracekit import get_logger
logger = get_logger(name='my_service_logger', log_file_path='logs/my_service.log', max_bytes=10*1024*1024, backup_count=5)
# Now you can use `logger` to log messages that include trace IDs
logger.info("This will push the logs into logs/my_service.log")
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file pytracekit-0.1.1.tar.gz
.
File metadata
- Download URL: pytracekit-0.1.1.tar.gz
- Upload date:
- Size: 7.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.0.0 CPython/3.9.19
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | a61279446eaec9d17ed60a3e76487ad1b4dc6858680b4ecf6d5fd7fcca6a5bca |
|
MD5 | 0abfb722f610bcf0ea2d38cfb1c6589f |
|
BLAKE2b-256 | b6e382b3292fca3a089647d100442879459538deaafe4376f2f9a04e48ceedce |
File details
Details for the file pytracekit-0.1.1-py3-none-any.whl
.
File metadata
- Download URL: pytracekit-0.1.1-py3-none-any.whl
- Upload date:
- Size: 8.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.0.0 CPython/3.9.19
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | b909b7d1cc5c34581bb482da4316c57950976fed448bf8a7afc69ecba358ea91 |
|
MD5 | 85e488f4e552628b681d8ada39de9df5 |
|
BLAKE2b-256 | 0ab446a546a34faa09a965c7048bc08dd3407f79ce43cc1f4d2d64b43a097ad9 |