Skip to content

Commit 04d72cc

Browse files
committed
refactor: use the galileo config
1 parent b71679e commit 04d72cc

File tree

3 files changed

+117
-118
lines changed

3 files changed

+117
-118
lines changed

poetry.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/galileo/otel.py

Lines changed: 23 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
from typing import Any, NoReturn, Optional
55
from urllib.parse import urljoin
66

7+
from galileo.config import GalileoPythonConfig
8+
79
logger = logging.getLogger(__name__)
810

911
INSTALL_ERR_MSG = (
@@ -46,22 +48,9 @@ class GalileoOTLPExporter(OTLPSpanExporter):
4648
This exporter extends the standard OTLPSpanExporter with Galileo-specific
4749
configuration and authentication. For most applications, consider using
4850
GalileoSpanProcessor instead, which provides a complete tracing solution.
49-
50-
Supported Environment Variables:
51-
GALILEO_API_KEY: Authentication key for Galileo platform access
52-
GALILEO_CONSOLE_URL: Galileo Console base URL (default: https://api.galileo.ai)
53-
GALILEO_PROJECT: Target project name for trace data
54-
GALILEO_LOGSTREAM: Target logstream name for trace organization
5551
"""
5652

57-
def __init__(
58-
self,
59-
project: Optional[str] = None,
60-
logstream: Optional[str] = None,
61-
api_key: Optional[str] = None,
62-
base_url: Optional[str] = None,
63-
**kwargs: Any,
64-
) -> None:
53+
def __init__(self, project: Optional[str] = None, logstream: Optional[str] = None, **kwargs: Any) -> None:
6554
"""
6655
Initialize the Galileo OTLP exporter with authentication and endpoint configuration.
6756
@@ -71,24 +60,30 @@ def __init__(
7160
Target Galileo project name. Falls back to GALILEO_PROJECT environment variable.
7261
logstream : str, optional
7362
Target logstream for trace organization. Uses default logstream if not specified.
74-
base_url : str, optional
75-
Base URL for OTLP endpoint. Constructs {base_url}/otel/traces as the final endpoint.
76-
api_key : str, optional
77-
Galileo platform API key. Falls back to GALILEO_API_KEY environment variable.
7863
**kwargs
7964
Additional configuration options passed to the underlying OTLPSpanExporter.
8065
8166
Raises
8267
------
8368
ValueError
84-
When no API key is provided via parameter or environment variable.
69+
When configuration is not properly initialized with required credentials.
8570
"""
86-
processed_base_url = str(base_url or os.environ.get("GALILEO_CONSOLE_URL", "https://api.galileo.ai"))
71+
# Get configuration from GalileoPythonConfig
72+
config = GalileoPythonConfig.get()
73+
74+
if not config.api_url:
75+
# This should never happen, but we'll raise an error just in case
76+
raise ValueError("API URL is required.")
77+
78+
# Get API URL and construct OTLP endpoint
79+
base_url = str(config.api_url)
8780
# Ensure base_url ends with / for proper joining
88-
if not processed_base_url.endswith("/"):
89-
processed_base_url += "/"
90-
endpoint: str = urljoin(processed_base_url, "/otel/traces")
91-
api_key = api_key or os.environ.get("GALILEO_API_KEY")
81+
if not base_url.endswith("/"):
82+
base_url += "/"
83+
endpoint: str = urljoin(base_url, "/otel/traces")
84+
85+
if not config.api_key:
86+
raise ValueError("API key is required.")
9287

9388
# Resolve project and logstream from parameters or environment variables
9489
self.project = project or os.environ.get("GALILEO_PROJECT")
@@ -100,12 +95,7 @@ def __init__(
10095
if not self.logstream:
10196
self.logstream = "default"
10297

103-
if not api_key:
104-
raise ValueError(
105-
"API key is required. Provide it via api_key parameter or GALILEO_API_KEY environment variable."
106-
)
107-
108-
exporter_headers = {"Galileo-API-Key": api_key, "project": self.project, "logstream": self.logstream}
98+
exporter_headers = {"Galileo-API-Key": config.api_key, "project": self.project, "logstream": self.logstream}
10999

110100
super().__init__(endpoint=endpoint, headers=exporter_headers, **kwargs)
111101

@@ -124,12 +114,7 @@ class GalileoSpanProcessor(SpanProcessor):
124114
"""
125115

126116
def __init__(
127-
self,
128-
project: Optional[str] = None,
129-
logstream: Optional[str] = None,
130-
api_key: Optional[str] = None,
131-
api_url: Optional[str] = None,
132-
SpanProcessor: Optional[type] = None,
117+
self, project: Optional[str] = None, logstream: Optional[str] = None, SpanProcessor: Optional[type] = None
133118
) -> None:
134119
"""
135120
Initialize the Galileo span processor with export configuration.
@@ -140,10 +125,6 @@ def __init__(
140125
Target Galileo project for trace data. Falls back to GALILEO_PROJECT environment variable.
141126
logstream : str, optional
142127
Target logstream for trace organization. Uses default logstream if not specified.
143-
api_key : str, optional
144-
Galileo platform API key. Falls back to GALILEO_API_KEY environment variable.
145-
api_url : str, optional
146-
Base URL for Galileo API endpoints. Falls back to GALILEO_API_URL environment variable.
147128
SpanProcessor : type, optional
148129
Custom span processor class. Defaults to BatchSpanProcessor for optimal performance.
149130
@@ -158,9 +139,8 @@ def __init__(
158139
"Install optional OpenTelemetry dependencies with: pip install galileo[otel]"
159140
)
160141

161-
# Create the exporter
162-
# Convert api_url to the full endpoint URL that GalileoOTLPExporter expects
163-
self._exporter = GalileoOTLPExporter(base_url=api_url, api_key=api_key, project=project, logstream=logstream)
142+
# Create the exporter using the config-based approach
143+
self._exporter = GalileoOTLPExporter(project=project, logstream=logstream)
164144

165145
if SpanProcessor is None:
166146
SpanProcessor = BatchSpanProcessor

0 commit comments

Comments
 (0)