NOTICE: All information contained herein is, and remains
the property of TechnoCore.
ObjOpenObserve is a Python class designed to facilitate the sending of logs and metrics to an OpenObserve instance. It provides a simple interface for sending data to the OpenObserve API, making it easy to integrate OpenObserve into your Python applications.
Before using ObjOpenObserve, you need to have the following:
requests library installed in your Python environment.To use ObjOpenObserve, you first need to create an instance of the class, providing the necessary connection details for your OpenObserve instance.
from ObjOpenObserve import ObjOpenObserve
# Create an instance of ObjOpenObserve
openobserve = ObjOpenObserve(
host="localhost",
port=5080,
user="user",
password="password",
organization="default"
)
Once you have an instance of ObjOpenObserve, you can use the send_log and send_metric methods to send data to OpenObserve.
To send a single log entry, you can use the send_log method:
# Send a single log
log_entry = {"message": "This is a test log message"}
openobserve.send_log("my_stream", log_entry)
To send multiple log entries in a batch, you can use the send_logs method:
# Send multiple logs
log_entries = [
{"message": "Log message 1"},
{"message": "Log message 2"},
]
openobserve.send_logs("my_stream", log_entries)
To send a single metric, you can use the send_metric method:
# Send a single metric
metric = {
"name": "my_metric",
"value": 123.45,
"labels": {"label1": "value1"},
}
openobserve.send_metric(metric)
To send multiple metrics in a batch, you can use the send_metrics method:
# Send multiple metrics
metrics = [
{
"name": "my_metric_1",
"value": 1,
"labels": {"label1": "value1"},
},
{
"name": "my_metric_2",
"value": 2,
"labels": {"label2": "value2"},
},
]
openobserve.send_metrics(metrics)
ObjOpenObserve uses the requests library for making HTTP requests to the OpenObserve API. If an error occurs during the request, a requests.exceptions.HTTPError will be raised. You can handle these exceptions using a try...except block.
try:
openobserve.send_log("my_stream", {"message": "This is a test log message"})
except requests.exceptions.HTTPError as e:
print(f"An error occurred: {e}")
cythonize -3 -a -i ObjOpenObserve.py
Compiling /home/axion/projects/axion/factory.core/ObjOpenObserve.py because it changed..[1/1] Cythonizing /home/axion/projects/axion/factory.core/ObjOpenObserve.py
Updated : 2025-09-10