Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/rapidata/rapidata_client/config/logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ def __init__(self, name: str = "rapidata"):
self._otlp_handler = None
self._otlp_enabled = True # Default to enabled
self._otlp_attached = False
self._environment = "rapidata.ai"

# Register this logger to receive configuration updates
register_config_handler(self._handle_config_update)
Expand Down Expand Up @@ -75,7 +76,7 @@ def _ensure_otlp_initialized(self) -> None:
set_logger_provider(logger_provider)

exporter = OTLPLogExporter(
endpoint="https://otlp-sdk.rapidata.ai/v1/logs",
endpoint=f"https://otlp-sdk.{self._environment}/v1/logs",
timeout=30,
)

Expand Down Expand Up @@ -104,6 +105,7 @@ def _update_logger(self, config: LoggingConfig) -> None:
"""Update the logger based on the new configuration."""
self._otlp_enabled = config.enable_otlp
self._otlp_attached = False
self._environment = config.environment

# Console handler with configurable level
console_handler = logging.StreamHandler()
Expand Down
3 changes: 3 additions & 0 deletions src/rapidata/rapidata_client/config/logging_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ class LoggingConfig(BaseModel):
silent_mode (bool): Whether to disable the prints and progress bars. Does NOT affect the logging. Defaults to False.
enable_otlp (bool): Whether to enable OpenTelemetry trace logs. Defaults to True.
Can also be disabled via the RAPIDATA_DISABLE_OTLP=1 environment variable.
environment (str): The API environment the client targets, used to derive the
OTLP collector host (``otlp-sdk.<environment>``). Set by RapidataClient.
"""

@model_validator(mode="before")
Expand All @@ -56,6 +58,7 @@ def _apply_env_vars(cls, data: Any) -> Any:
format: str = Field(default="%(asctime)s - %(name)s - %(levelname)s - %(message)s")
silent_mode: bool = Field(default=False)
enable_otlp: bool = Field(default_factory=_default_enable_otlp)
environment: str = Field(default="rapidata.ai")

def __init__(self, **kwargs):
super().__init__(**kwargs)
Expand Down
4 changes: 3 additions & 1 deletion src/rapidata/rapidata_client/config/tracer.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ def __init__(self, name: str = __name__):
self._real_tracer = None
self._no_op_tracer = NoOpTracer()
self._enabled = True # Default to enabled
self._environment = "rapidata.ai"
self.session_id: str | None = None
self.client_id: str | None = None
self.email: str | None = None
Expand All @@ -146,6 +147,7 @@ def _handle_config_update(self, config: LoggingConfig) -> None:
def _update_tracer(self, config: LoggingConfig) -> None:
"""Update the tracer based on the new configuration."""
self._enabled = config.enable_otlp
self._environment = config.environment

def _ensure_initialized(self) -> None:
"""Lazily initialize OTLP tracing on first use."""
Expand All @@ -168,7 +170,7 @@ def _ensure_initialized(self) -> None:
self._tracer_provider = TracerProvider(resource=resource)

exporter = OTLPSpanExporter(
endpoint="https://otlp-sdk.rapidata.ai/v1/traces",
endpoint=f"https://otlp-sdk.{self._environment}/v1/traces",
timeout=30,
)

Expand Down
11 changes: 9 additions & 2 deletions src/rapidata/rapidata_client/rapidata_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,11 @@ class _UserInfoCacheEntry:
_userinfo_cache: dict[tuple[str, str], _UserInfoCacheEntry] = {}
_userinfo_cache_lock = threading.Lock()

# Environments with a deployed SDK OTLP collector at otlp-sdk.<environment>.
# Other environments (e.g. local rapidata.dev) have no collector, so OTLP is
# left disabled there to avoid noisy failed exports.
_OTLP_COLLECTOR_ENVIRONMENTS = frozenset({"rapidata.ai", "rabbitdata.ch"})


class RapidataClient:
"""The Rapidata client is the main entry point for interacting with the Rapidata API. It allows you to create orders and validation sets."""
Expand Down Expand Up @@ -134,11 +139,13 @@ def __init__(
self._client_id = client_id
self._environment = environment

rapidata_config.logging.environment = environment
if environment not in _OTLP_COLLECTOR_ENVIRONMENTS:
rapidata_config.logging.enable_otlp = False

with tracer.start_as_current_span("RapidataClient.__init__"):
logger.debug("Checking version")
self._check_version()
if environment != "rapidata.ai":
rapidata_config.logging.enable_otlp = False

logger.debug("Initializing OpenAPIService")
self._openapi_service = OpenAPIService(
Expand Down
Loading