Repository: microsoft/promptflow
File: src/promptflow-azure/promptflow/azure/_utils/_tracing.py (Python)

Code before:
            # ignore request error and continue to poll in next iteration
            pass
        # set a timeout here to prevent the potential infinite loop
        if int(time.time() - start_time) > COSMOS_INIT_POLL_TIMEOUT_SECOND:
            break
        prompt_msg = "The workspace Cosmos DB initialization is still in progress..."
        _logger.info(prompt_msg)
        time.sleep(COSMOS_INIT_POLL_INTERVAL_SECOND)
    # initialization does not finish in time, we need to ensure the Cosmos resource is ready
    # so print error log and raise error here
    error_msg = (
        "The workspace Cosmos DB initialization is still in progress "
        f"after {COSMOS_INIT_POLL_TIMEOUT_SECOND} seconds, "
        "please wait for a while and retry."
    )
    _logger.error(error_msg)
    raise Exception(error_msg)


def validate_trace_provider(value: str) -> None:
    """Validate `trace.provider` in pf config.

    1. the value is a valid ARM resource ID for workspace/project
    2. the resource exists
    3. the resource is an Azure ML workspace or AI project
    4. the workspace Cosmos DB is initialized
    """
    # valid workspace/project ARM resource ID; otherwise, a ValueError will be raised
    _logger.debug("Validating trace provider value...")
    try:
        workspace_triad = extract_workspace_triad_from_trace_provider(value)
    except ValueError as e:
        raise _create_trace_provider_value_user_error(str(e))

    # the resource exists
    _logger.debug("Validating resource exists...")
    ml_client = MLClient(
        credential=_get_credential(),
        subscription_id=workspace_triad.subscription_id,
        resource_group_name=workspace_triad.resource_group_name,
        workspace_name=workspace_triad.workspace_name,
    )
    try:
        workspace = ml_client.workspaces.get(name=workspace_triad.workspace_name)
    except ResourceNotFoundError as e:
        raise _create_trace_provider_value_user_error(str(e))
    _logger.debug("Resource exists.")

    # Azure ML workspace or AI project
    _logger.debug("Validating resource type...")
    if is_hub(workspace):

Review comment (bug):
I feel like the debug info is not really printed when using `--debug` in cli command, could you double confirm that?

Code after:
    error_msg = (
        "The workspace Cosmos DB initialization is still in progress "
        f"after {COSMOS_INIT_POLL_TIMEOUT_SECOND} seconds, "
        "please wait for a while and retry."
    )
    _logger.error(error_msg)
    raise Exception(error_msg)


def validate_trace_provider(value: str) -> None:
    """Validate `trace.provider` in pf config.

    1. the value is a valid ARM resource ID for workspace/project
    2. the resource exists
    3. the resource is an Azure ML workspace or AI project
    4. the workspace Cosmos DB is initialized
    """
    # valid workspace/project ARM resource ID; otherwise, a ValueError will be raised
    _logger.debug("Validating trace provider value...")
    try:
        workspace_triad = extract_workspace_triad_from_trace_provider(value)
    except ValueError as e:
        raise _create_trace_provider_value_user_error(str(e))

    # the resource exists
    _logger.debug("Validating resource exists...")
    ml_client = MLClient(
        credential=get_credentials_for_cli(),
        subscription_id=workspace_triad.subscription_id,
        resource_group_name=workspace_triad.resource_group_name,
        workspace_name=workspace_triad.workspace_name,
    )
    try:
        workspace = ml_client.workspaces.get(name=workspace_triad.workspace_name)
    except ResourceNotFoundError as e:
        raise _create_trace_provider_value_user_error(str(e))
    _logger.debug("Resource exists.")

    # Azure ML workspace or AI project
    _logger.debug("Validating resource type...")
    if AzureWorkspaceKind.is_hub(workspace):
        error_msg = (
            f"{workspace.name!r} is an Azure AI hub, which is not a valid type. "
            "Currently we support Azure ML workspace and AI project as trace provider."
        )
        raise _create_trace_provider_value_user_error(error_msg)
    _logger.debug("Resource type is valid.")

    # the workspace Cosmos DB is initialized
    # try to retrieve the token from PFS; if failed, call PFS init API and start polling
    _logger.debug("Validating workspace Cosmos DB is initialized...")