Index
provide.foundation.integrations.openobserve
¶
TODO: Add module docstring.
Classes¶
MetricMetadata
¶
Metadata for a metric.
Attributes:
| Name | Type | Description |
|---|---|---|
name |
str
|
Metric name |
type |
str
|
Metric type (counter, gauge, histogram, summary, etc.) |
help |
str
|
Help text describing the metric |
unit |
str
|
Unit of measurement |
Functions¶
from_dict
classmethod
¶
Create from dictionary.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
dict[str, Any]
|
Dictionary with metric metadata |
required |
Returns:
| Type | Description |
|---|---|
MetricMetadata
|
MetricMetadata instance |
Source code in provide/foundation/integrations/openobserve/metrics_models.py
MetricQueryResult
¶
Result from a Prometheus query.
Attributes:
| Name | Type | Description |
|---|---|---|
result_type |
str
|
Type of result (vector, matrix, scalar, string) |
result |
list[MetricSample]
|
List of metric samples |
status |
str
|
Query status (success, error) |
error_type |
str
|
Error type if query failed |
error |
str
|
Error message if query failed |
warnings |
list[str]
|
List of warnings |
Attributes¶
is_success
property
¶
sample_count
property
¶
Functions¶
from_dict
classmethod
¶
Create from dictionary.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
dict[str, Any]
|
Dictionary with query result from Prometheus API |
required |
Returns:
| Type | Description |
|---|---|
MetricQueryResult
|
MetricQueryResult instance |
Source code in provide/foundation/integrations/openobserve/metrics_models.py
to_dict
¶
Convert to dictionary.
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
Dictionary representation |
Source code in provide/foundation/integrations/openobserve/metrics_models.py
MetricSample
¶
A single metric sample with labels and value.
Attributes:
| Name | Type | Description |
|---|---|---|
metric |
dict[str, str]
|
Label name-value pairs |
value |
tuple[float, str] | None
|
Metric value (single value for instant queries) |
values |
list[tuple[float, str]]
|
List of [timestamp, value] pairs for range queries |
Functions¶
from_dict
classmethod
¶
Create from dictionary.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
dict[str, Any]
|
Dictionary with sample data from Prometheus API |
required |
Returns:
| Type | Description |
|---|---|
MetricSample
|
MetricSample instance |
Source code in provide/foundation/integrations/openobserve/metrics_models.py
OpenObserveAuthenticationError
¶
OpenObserveAuthenticationError(
message: str,
*,
code: str | None = None,
context: dict[str, Any] | None = None,
cause: Exception | None = None,
**extra_context: Any
)
Bases: OpenObserveError
Authentication failed with OpenObserve.
Source code in provide/foundation/errors/base.py
OpenObserveClient
¶
OpenObserveClient(
url: str,
username: str,
password: str,
organization: str = "default",
timeout: int = 30,
)
Bases: SearchOperationsMixin, MetricsOperationsMixin, OpenObserveClientBase
Async client for interacting with OpenObserve API.
Uses Foundation's transport system for all HTTP operations. Combines search/streams operations and Prometheus metrics API.
Source code in provide/foundation/integrations/openobserve/client_base.py
OpenObserveConfig
¶
Bases: RuntimeConfig
Configuration for OpenObserve integration.
Functions¶
get_otlp_endpoint
¶
Get OTLP endpoint derived from OpenObserve URL.
Returns:
| Type | Description |
|---|---|
str | None
|
OTLP endpoint URL or None if not configured |
Source code in provide/foundation/integrations/openobserve/config.py
is_available
¶
Test if OpenObserve is available and reachable.
Returns:
| Type | Description |
|---|---|
bool
|
True if connection test succeeds |
Source code in provide/foundation/integrations/openobserve/config.py
OpenObserveConfigError
¶
OpenObserveConfigError(
message: str,
*,
code: str | None = None,
context: dict[str, Any] | None = None,
cause: Exception | None = None,
**extra_context: Any
)
Bases: OpenObserveError
Configuration error for OpenObserve.
Source code in provide/foundation/errors/base.py
OpenObserveConnectionError
¶
OpenObserveConnectionError(
message: str,
*,
code: str | None = None,
context: dict[str, Any] | None = None,
cause: Exception | None = None,
**extra_context: Any
)
Bases: OpenObserveError
Error connecting to OpenObserve API.
Source code in provide/foundation/errors/base.py
OpenObserveError
¶
OpenObserveError(
message: str,
*,
code: str | None = None,
context: dict[str, Any] | None = None,
cause: Exception | None = None,
**extra_context: Any
)
Bases: FoundationError
Base exception for OpenObserve-related errors.
Source code in provide/foundation/errors/base.py
OpenObserveQueryError
¶
OpenObserveQueryError(
message: str,
*,
code: str | None = None,
context: dict[str, Any] | None = None,
cause: Exception | None = None,
**extra_context: Any
)
Bases: OpenObserveError
Error executing query in OpenObserve.
Source code in provide/foundation/errors/base.py
OpenObserveStreamingError
¶
OpenObserveStreamingError(
message: str,
*,
code: str | None = None,
context: dict[str, Any] | None = None,
cause: Exception | None = None,
**extra_context: Any
)
Bases: OpenObserveError
Error during streaming operations.
Source code in provide/foundation/errors/base.py
SearchQuery
¶
SearchResponse
¶
Response from OpenObserve search API.
Functions¶
from_dict
classmethod
¶
Create from API response.
Source code in provide/foundation/integrations/openobserve/models.py
StreamInfo
¶
Information about an OpenObserve stream.
Functions¶
from_dict
classmethod
¶
Create from API response.
Source code in provide/foundation/integrations/openobserve/models.py
Functions¶
aggregate_by_level
async
¶
aggregate_by_level(
stream: str = "default",
start_time: str | int | None = None,
end_time: str | int | None = None,
client: OpenObserveClient | None = None,
) -> dict[str, int]
Get count of logs by level.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
stream
|
str
|
Stream name to search in |
'default'
|
start_time
|
str | int | None
|
Start time |
None
|
end_time
|
str | int | None
|
End time |
None
|
client
|
OpenObserveClient | None
|
OpenObserve client |
None
|
Returns:
| Type | Description |
|---|---|
dict[str, int]
|
Dictionary mapping level to count |
Source code in provide/foundation/integrations/openobserve/search.py
format_csv
¶
Format response as CSV.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
response
|
SearchResponse
|
Search response |
required |
columns
|
list[str] | None
|
Specific columns to include (None for all) |
None
|
Returns:
| Type | Description |
|---|---|
str
|
CSV string |
Source code in provide/foundation/integrations/openobserve/formatters.py
format_json
¶
Format response as JSON.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
response
|
SearchResponse | dict[str, Any]
|
Search response or log entry |
required |
pretty
|
bool
|
If True, use pretty printing |
True
|
Returns:
| Type | Description |
|---|---|
str
|
JSON string |
Source code in provide/foundation/integrations/openobserve/formatters.py
format_log_line
¶
Format a log entry as a traditional log line.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
entry
|
dict[str, Any]
|
Log entry dictionary |
required |
Returns:
| Type | Description |
|---|---|
str
|
Formatted log line |
Source code in provide/foundation/integrations/openobserve/formatters.py
format_metric_output
¶
format_metric_output(
result: MetricQueryResult | list[str] | dict[str, Any],
format_type: str = "table",
pretty: bool = False,
) -> str
Format metrics output in specified format.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
result
|
MetricQueryResult | list[str] | dict[str, Any]
|
Data to format (query result, list of metrics, or metadata) |
required |
format_type
|
str
|
Output format ("table", "json", "csv", "chart", "summary") |
'table'
|
pretty
|
bool
|
Whether to pretty-print (for JSON) |
False
|
Returns:
| Type | Description |
|---|---|
str
|
Formatted string |
Source code in provide/foundation/integrations/openobserve/metrics_formatters.py
format_metrics_list
¶
Format list of metrics as a simple list.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
metrics
|
list[str]
|
List of metric names |
required |
show_count
|
bool
|
Whether to show count at the end |
True
|
Returns:
| Type | Description |
|---|---|
str
|
Formatted string |
Source code in provide/foundation/integrations/openobserve/metrics_formatters.py
format_output
¶
format_output(
response: SearchResponse | dict[str, Any],
format_type: str = "log",
**kwargs: Any
) -> str
Format output based on specified type.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
response
|
SearchResponse | dict[str, Any]
|
Search response or log entry |
required |
format_type
|
str
|
Output format (json, log, table, csv, summary) |
'log'
|
**kwargs
|
Any
|
Additional format-specific options |
{}
|
Returns:
| Type | Description |
|---|---|
str
|
Formatted string |
Source code in provide/foundation/integrations/openobserve/formatters.py
format_summary
¶
Format a summary of the search response.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
response
|
SearchResponse
|
Search response |
required |
Returns:
| Type | Description |
|---|---|
str
|
Summary string |
Source code in provide/foundation/integrations/openobserve/formatters.py
format_table
¶
Format response as a table.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
response
|
SearchResponse
|
Search response |
required |
columns
|
list[str] | None
|
Specific columns to include (None for all) |
None
|
Returns:
| Type | Description |
|---|---|
str
|
Table string |
Source code in provide/foundation/integrations/openobserve/formatters.py
get_current_trace_logs
async
¶
get_current_trace_logs(
stream: str = "default",
client: OpenObserveClient | None = None,
) -> SearchResponse | None
Get logs for the current active trace.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
stream
|
str
|
Stream name to search in |
'default'
|
client
|
OpenObserveClient | None
|
OpenObserve client |
None
|
Returns:
| Type | Description |
|---|---|
SearchResponse | None
|
SearchResponse with logs for current trace, or None if no active trace |
Source code in provide/foundation/integrations/openobserve/search.py
parse_relative_time
¶
Parse relative time strings like '-1h', '-30m' to microseconds since epoch.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
time_str
|
str
|
Time string (e.g., '-1h', '-30m', 'now') |
required |
now
|
datetime | None
|
Current time (for testing), defaults to datetime.now() |
None
|
Returns:
| Type | Description |
|---|---|
int
|
Microseconds since epoch |
Source code in provide/foundation/integrations/openobserve/models.py
search_by_level
async
¶
search_by_level(
level: str,
stream: str = "default",
start_time: str | int | None = None,
end_time: str | int | None = None,
size: int = 100,
client: OpenObserveClient | None = None,
) -> SearchResponse
Search for logs by level.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
level
|
str
|
Log level to filter (ERROR, WARN, INFO, DEBUG, etc.) |
required |
stream
|
str
|
Stream name to search in |
'default'
|
start_time
|
str | int | None
|
Start time |
None
|
end_time
|
str | int | None
|
End time |
None
|
size
|
int
|
Number of results |
100
|
client
|
OpenObserveClient | None
|
OpenObserve client |
None
|
Returns:
| Type | Description |
|---|---|
SearchResponse
|
SearchResponse with matching logs |
Source code in provide/foundation/integrations/openobserve/search.py
search_by_service
async
¶
search_by_service(
service: str,
stream: str = "default",
start_time: str | int | None = None,
end_time: str | int | None = None,
size: int = 100,
client: OpenObserveClient | None = None,
) -> SearchResponse
Search for logs by service name.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
service
|
str
|
Service name to filter |
required |
stream
|
str
|
Stream name to search in |
'default'
|
start_time
|
str | int | None
|
Start time |
None
|
end_time
|
str | int | None
|
End time |
None
|
size
|
int
|
Number of results |
100
|
client
|
OpenObserveClient | None
|
OpenObserve client |
None
|
Returns:
| Type | Description |
|---|---|
SearchResponse
|
SearchResponse with matching logs |
Source code in provide/foundation/integrations/openobserve/search.py
search_by_trace_id
async
¶
search_by_trace_id(
trace_id: str,
stream: str = "default",
client: OpenObserveClient | None = None,
) -> SearchResponse
Search for logs by trace ID.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
trace_id
|
str
|
Trace ID to search for |
required |
stream
|
str
|
Stream name to search in |
'default'
|
client
|
OpenObserveClient | None
|
OpenObserve client (creates new if not provided) |
None
|
Returns:
| Type | Description |
|---|---|
SearchResponse
|
SearchResponse with matching logs |
Source code in provide/foundation/integrations/openobserve/search.py
search_errors
async
¶
search_errors(
stream: str = "default",
start_time: str | int | None = None,
size: int = 100,
client: OpenObserveClient | None = None,
) -> SearchResponse
Search for error logs.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
stream
|
str
|
Stream name to search in |
'default'
|
start_time
|
str | int | None
|
Start time |
None
|
size
|
int
|
Number of results |
100
|
client
|
OpenObserveClient | None
|
OpenObserve client |
None
|
Returns:
| Type | Description |
|---|---|
SearchResponse
|
SearchResponse with error logs |
Source code in provide/foundation/integrations/openobserve/search.py
search_logs
async
¶
search_logs(
sql: str,
start_time: str | int | None = None,
end_time: str | int | None = None,
size: int = 100,
client: OpenObserveClient | None = None,
) -> SearchResponse
Search logs in OpenObserve.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
sql
|
str
|
SQL query to execute |
required |
start_time
|
str | int | None
|
Start time (relative like "-1h" or microseconds) |
None
|
end_time
|
str | int | None
|
End time (relative like "now" or microseconds) |
None
|
size
|
int
|
Number of results to return |
100
|
client
|
OpenObserveClient | None
|
OpenObserve client (creates new if not provided) |
None
|
Returns:
| Type | Description |
|---|---|
SearchResponse
|
SearchResponse with results |
Source code in provide/foundation/integrations/openobserve/search.py
stream_logs
¶
stream_logs(
sql: str,
start_time: str | int | None = None,
poll_interval: int = 5,
client: OpenObserveClient | None = None,
) -> Generator[dict[str, Any], None, None]
Stream logs from OpenObserve with polling.
Continuously polls for new logs and yields them as they arrive.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
sql
|
str
|
SQL query to execute |
required |
start_time
|
str | int | None
|
Initial start time |
None
|
poll_interval
|
int
|
Seconds between polls |
5
|
client
|
OpenObserveClient | None
|
OpenObserve client |
None
|
Yields:
| Type | Description |
|---|---|
dict[str, Any]
|
Log entries as they arrive |
Source code in provide/foundation/integrations/openobserve/streaming.py
stream_search_http2
¶
stream_search_http2(
sql: str,
start_time: str | int | None = None,
end_time: str | int | None = None,
client: OpenObserveClient | None = None,
) -> Generator[dict[str, Any], None, None]
Stream search results using HTTP/2 streaming endpoint (sync wrapper).
This is a sync wrapper around the async streaming function for CLI use.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
sql
|
str
|
SQL query to execute |
required |
start_time
|
str | int | None
|
Start time |
None
|
end_time
|
str | int | None
|
End time |
None
|
client
|
OpenObserveClient | None
|
OpenObserve client |
None
|
Yields:
| Type | Description |
|---|---|
dict[str, Any]
|
Log entries as they stream |
Source code in provide/foundation/integrations/openobserve/streaming.py
tail_logs
¶
tail_logs(
stream: str = "default",
filters: dict[str, str] | None = None,
follow: bool = True,
lines: int = 10,
client: OpenObserveClient | None = None,
) -> Generator[dict[str, Any], None, None]
Tail logs similar to 'tail -f' command.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
stream
|
str
|
Stream name to tail |
'default'
|
filters
|
dict[str, str] | None
|
Dictionary of key-value pairs for filtering |
None
|
follow
|
bool
|
If True, continue streaming new logs |
True
|
lines
|
int
|
Number of initial lines to show |
10
|
client
|
OpenObserveClient | None
|
OpenObserve client |
None
|
Yields:
| Type | Description |
|---|---|
dict[str, Any]
|
Log entries |