This is a library that allows you to send metrics and logs of scheduled jobs in python to otel-collector.
Project description
opentelemetry-python-instrumentation-jobs
This is a library that allows you to send metrics and logs of scheduled jobs in python to otel-collector.
Tested with python 3.12:
- schedule
- apscheduler
Installation
pip install opentelemetry-python-instrumentation-jobs
Usage
from opentelemetry_python_instrumentation_jobs import send_metrics
@send_metrics(job_name="job 1")
def job_1(job_name: str, update_progress: Callable):
total = 10
for i in range(total):
update_progress(1, total)
send_metrics decorator
parameters:
job_name(string): The name of the jobshow_progress(boolean): Whether to show the progress of the job in console(tqdm)
decorator injects job_name and update_progress parameters to the job function
update_progress is a function that takes two parameters:
- processed items count in the iteration (1 or batch size);
- total items count (10 in this example)
You can ignore job_name and update_progress parameters if you don't need them:
from opentelemetry_python_instrumentation_jobs import send_metrics
@send_metrics(job_name="job 1")
def job_1(*args, **kwargs):
for i in range(10):
pass
Environment Variables
OTEL_SERVICE_NAME(string): The name of the serviceOTEL_EXPORTER_OTLP_ENDPOINT(string): The endpoint of the otel-collectorOTEL_EXPORTER_OTLP_INSECURE(boolean): Whether to use insecure connectionSENDING_LOGS_AND_METRICS_ENABLED(boolean): Whether to send logs and metricsOTEL_EXPORT_INTERVAL(int): The interval in milliseconds at which to export metrics
Full example
import time
import schedule
from opentelemetry_python_instrumentation_jobs import send_metrics
@send_metrics(job_name="job 1")
def job_1(*args, update_progress: Callable, **kwargs):
total = 20
update_progress(0, total)
for i in range(total):
time.sleep(1)
update_progress(1, total)
@send_metrics(job_name="job 2", show_progress=False)
def job_2(*args, **kwargs):
for i in range(10):
time.sleep(1)
schedule.every(1).minutes.do(job_1)
schedule.every(20).seconds.do(job_2)
while True:
schedule.run_pending()
time.sleep(1)
Metrics that are sent
${METRIC_PREFIX}_job_run_count(counter): How many times the job has been run${METRIC_PREFIX}_job_status(counter): Job counter by status (success, error)${METRIC_PREFIX}_job_duration(gauge): Job execution duration in seconds${METRIC_PREFIX}_job_records(gauge): Number of records in job (processed, total)${METRIC_PREFIX}_job_last_status(gauge): Last job status (1, 0)${METRIC_PREFIX}_job_time(gauge): Job start and finish time in unix timestamp (started, finished)
License
MIT License
Copyright (c) 2024 Vano Atabegashvili
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
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file opentelemetry_python_instrumentation_jobs-0.3.2.tar.gz.
File metadata
- Download URL: opentelemetry_python_instrumentation_jobs-0.3.2.tar.gz
- Upload date:
- Size: 4.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.8.4 CPython/3.12.3 Linux/6.8.0-49-generic
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3168fe6909904cb027e02f6d5c544393c9a65b1700e79527b984d18fcf500481
|
|
| MD5 |
0fe8b508171914720bd4968581103b10
|
|
| BLAKE2b-256 |
b5fa0f61b513074800e88a7e654ce6319605100ccef74b133479ed456c0bd64d
|
File details
Details for the file opentelemetry_python_instrumentation_jobs-0.3.2-py3-none-any.whl.
File metadata
- Download URL: opentelemetry_python_instrumentation_jobs-0.3.2-py3-none-any.whl
- Upload date:
- Size: 6.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.8.4 CPython/3.12.3 Linux/6.8.0-49-generic
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c222d7d171fe26a1c61ef4a2ddda572be3a4710edcb850bd150af62b6599a2f3
|
|
| MD5 |
a4bff96edf78379f77afe4f8104545e8
|
|
| BLAKE2b-256 |
11059a5b4ec3b3ee62eb1c86d8d061f28da7893db5e8d6ab3ada3f08774058f4
|