Observability: Logging, Tracing, and Metrics

Observability is seamlessly integrated into Oracle AI Data Platform Workbench applications via the aidp_observability package, enabling automatic telemetry (logs, traces, metrics) collection with minimal setup.

Initialization

Import and initialize as shown:

from observability.aidp_observability import AIDPObservability
from observability.config import CollectorConfig

config = CollectorConfig()
config.service_name = "dummy_name"
observability = AIDPObservability(config)
observability.initialize()
Upon initialization:
  • OpenTelemetry exporters for traces, metrics, and logs are created.
  • The collector endpoint is configured for all telemetry data (port 4317, GRpc protocol).
  • Application loggers are set up.
  • Playground mode enables in-memory exporter for instant trace display.
  • The collector is pre-configured for log rotation, buffering, and includes a sink for telemetry exporting.
  • Default metrics, logs, and AI Data Platform Workbench metadata are included in all telemetry signals.
  • Default span/session attributes (e.g., sessionId, traceId) are set for correlation.

Usage pattern:

No changes are needed in application logic to emit telemetry. As a user:
  • Use the OpenTelemetry Meter for metrics.
  • Use Python's standard `logging` for logs.
  • Use the OpenTelemetry Tracer for traces.

Example

import logging
import time
from opentelemetry import trace, metrics

tracer = trace.get_tracer(__name__)
meter = metrics.get_meter(__name__)

request_counter = meter.create_counter(
    name="requests_total",
    description="Number of requests processed",
    unit="1",
)

logging.basicConfig(level=logging.INFO)
logger = logging.getLogger("sample-app")

def process_request(user_id: str):
    logger.info("Processing request for user %s", user_id)
    request_counter.add(1, {"user.id": user_id})
    with tracer.start_as_current_span("process_request") as span:
        span.set_attribute("user.id", user_id)
        time.sleep(0.1)
        span.add_event("request_completed", {"status": "ok"})

if __name__ == "__main__":
    for i in range(3):
        process_request(f"user-{i}")
        time.sleep(1)

Note:

Application telemetry is automatically exported; no instrumentation changes are required by the user. The observability package auto-instruments LLM frameworks and LangGraph applications for trace reporting.