def _attributes_from_client()

in instrumentation/elastic-opentelemetry-instrumentation-openai/src/opentelemetry/instrumentation/openai/helpers.py [0:0]


def _attributes_from_client(client) -> Attributes:
    span_attributes = {}

    if base_url := getattr(client, "_base_url", None):
        if host := getattr(base_url, "host", None):
            span_attributes[SERVER_ADDRESS] = host
        if port := getattr(base_url, "port", None):
            span_attributes[SERVER_PORT] = port
        elif scheme := getattr(base_url, "scheme", None):
            if scheme == "http":
                span_attributes[SERVER_PORT] = 80
            elif scheme == "https":
                span_attributes[SERVER_PORT] = 443

    return span_attributes