Otlp adapter
provide.foundation.integrations.openobserve.otlp_adapter
¶
OpenObserve-specific OTLP adapter extending generic client.
Provides OpenObserveOTLPClient that extends OTLPLogClient with OpenObserve-specific configuration and customizations.
Classes¶
OpenObserveOTLPClient
¶
OpenObserveOTLPClient(
endpoint: str,
headers: dict[str, str] | None = None,
service_name: str = "foundation",
service_version: str | None = None,
environment: str | None = None,
timeout: float = 30.0,
use_circuit_breaker: bool = True,
)
Bases: OTLPLogClient
OpenObserve-specific OTLP client with vendor customizations.
Extends the generic OTLPLogClient with OpenObserve-specific configuration and header management.
Examples:
>>> from provide.foundation.integrations.openobserve.config import OpenObserveConfig
>>> from provide.foundation.logger.config.telemetry import TelemetryConfig
>>> oo_config = OpenObserveConfig.from_env()
>>> telemetry_config = TelemetryConfig.from_env()
>>> client = OpenObserveOTLPClient.from_openobserve_config(
... oo_config, telemetry_config
... )
>>> client.send_log("Hello OpenObserve!")
True
Source code in provide/foundation/logger/otlp/client.py
Functions¶
from_env
classmethod
¶
Create client from environment variables.
Returns:
| Type | Description |
|---|---|
OpenObserveOTLPClient | None
|
Configured client if OpenObserve is configured, None otherwise |
Examples:
>>> # With env vars set:
>>> # OPENOBSERVE_URL=https://api.openobserve.ai
>>> # OPENOBSERVE_ORG=my-org
>>> # OPENOBSERVE_USER=admin
>>> # OPENOBSERVE_PASSWORD=secret
>>> client = OpenObserveOTLPClient.from_env()
>>> if client:
... client.send_log("Hello!")
Source code in provide/foundation/integrations/openobserve/otlp_adapter.py
from_openobserve_config
classmethod
¶
from_openobserve_config(
oo_config: OpenObserveConfig,
telemetry_config: TelemetryConfig,
) -> OpenObserveOTLPClient
Create OTLP client configured for OpenObserve.
Derives OTLP settings from OpenObserve configuration: - Builds OTLP endpoint from OpenObserve URL - Adds OpenObserve headers (organization, stream) - Configures Basic auth from credentials
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
oo_config
|
OpenObserveConfig
|
OpenObserve configuration |
required |
telemetry_config
|
TelemetryConfig
|
Telemetry configuration |
required |
Returns:
| Type | Description |
|---|---|
OpenObserveOTLPClient
|
Configured OpenObserveOTLPClient |
Raises:
| Type | Description |
|---|---|
ValueError
|
If OpenObserve URL is not set |
Examples:
>>> oo_config = OpenObserveConfig(
... url="https://api.openobserve.ai",
... org="my-org",
... user="admin",
... password="secret",
... )
>>> telemetry_config = TelemetryConfig(service_name="my-service")
>>> client = OpenObserveOTLPClient.from_openobserve_config(
... oo_config, telemetry_config
... )
Source code in provide/foundation/integrations/openobserve/otlp_adapter.py
Functions¶
build_openobserve_headers
¶
build_openobserve_headers(
oo_config: OpenObserveConfig,
base_headers: dict[str, str] | None = None,
) -> dict[str, str]
Build headers with OpenObserve-specific metadata.
Adds: - organization header - stream-name header - Basic auth header (from user/password)
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
oo_config
|
OpenObserveConfig
|
OpenObserve configuration |
required |
base_headers
|
dict[str, str] | None
|
Base headers to include |
None
|
Returns:
| Type | Description |
|---|---|
dict[str, str]
|
Complete headers dict with OpenObserve metadata |
Examples:
>>> config = OpenObserveConfig(
... org="my-org",
... stream="logs",
... user="admin",
... password="secret"
... )
>>> headers = build_openobserve_headers(config)
>>> "authorization" in headers
True
Source code in provide/foundation/integrations/openobserve/otlp_adapter.py
get_openobserve_otlp_endpoint
¶
get_openobserve_otlp_endpoint(
base_url: str,
org: str | None = None,
endpoint_type: str = "logs",
) -> str
Derive OTLP endpoint from OpenObserve base URL.
Handles: - URLs with /api/{org}/ path - URLs without /api/ path - Trailing slashes - Both logs and metrics endpoints
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
base_url
|
str
|
OpenObserve base URL |
required |
org
|
str | None
|
Organization name (defaults to "default") |
None
|
endpoint_type
|
str
|
Type of endpoint ("logs" or "metrics", defaults to "logs") |
'logs'
|
Returns:
| Type | Description |
|---|---|
str
|
OTLP endpoint URL |
Examples:
>>> get_openobserve_otlp_endpoint("https://api.openobserve.ai", "my-org")
'https://api.openobserve.ai/api/my-org/v1/logs'
>>> get_openobserve_otlp_endpoint("https://api.openobserve.ai/api/my-org/")
'https://api.openobserve.ai/api/my-org/v1/logs'
>>> get_openobserve_otlp_endpoint("https://api.openobserve.ai", "my-org", "metrics")
'https://api.openobserve.ai/api/my-org/v1/metrics'
Source code in provide/foundation/integrations/openobserve/otlp_adapter.py
get_openobserve_otlp_metrics_endpoint
¶
Derive OTLP metrics endpoint from OpenObserve base URL.
Convenience function that calls get_openobserve_otlp_endpoint with endpoint_type="metrics".
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
base_url
|
str
|
OpenObserve base URL |
required |
org
|
str | None
|
Organization name (defaults to "default") |
None
|
Returns:
| Type | Description |
|---|---|
str
|
OTLP metrics endpoint |
Examples:
>>> get_openobserve_otlp_metrics_endpoint("https://api.openobserve.ai", "my-org")
'https://api.openobserve.ai/api/my-org/v1/metrics'