Repository: microsoft/promptflow
File: src/promptflow-tracing/promptflow/tracing/_start_trace.py (Python)

Code before:
        # so we need to handle this with function signature check, and warn user on this
        if _kwargs_in_func(start_trace_with_devkit):
            logging.debug("compatible promptflow-devkit version, will pass `collection` and `kwargs`...")
            logging.debug("collection: %s", collection)
            logging.debug("kwargs: %s", kwargs)
            start_trace_with_devkit(collection=collection, **kwargs)
        else:
            warning_msg = (
                "incompatible `promptflow-devkit` version installed, which may lead to unexpected behavior; "
                "it is recommended to use 'promptflow-devkit>=1.9.0' for better trace experience."
            )
            logging.warning(warning_msg)
            print(warning_msg)
            logging.debug("will pass `collection`, `attributes`, and `run`...")
            _attributes = kwargs.get("attributes", None)
            _run = kwargs.get("run", None)
            logging.debug("collection: %s", collection)
            logging.debug("attributes: %s", _attributes)
            logging.debug("run: %s", _run)
            start_trace_with_devkit(collection=collection, attributes=_attributes, run=_run)


def setup_exporter_from_environ(only_inject_openai: bool = False) -> None:
    # openai instrumentation
    logging.debug("injecting OpenAI API...")
    inject_openai_api()
    logging.debug("OpenAI API injected.")

    if only_inject_openai:
        # only inject OpenAI API, skip the following setup, this is useful for serving scenario
        # because serving also support OTEL_EXPORTER_OTLP_ENDPOINT and have devkit installed now.
        return

    # Ignore all the setup if the endpoint is not set
    endpoint = os.getenv(OTEL_EXPORTER_OTLP_ENDPOINT)
    logging.debug("environ OTEL_EXPORTER_OTLP_ENDPOINT: %s", endpoint)
    if not endpoint:
        logging.info("environ OTEL_EXPORTER_OTLP_ENDPOINT is not set, will skip the following setup.")
        return

    if _is_devkit_installed():
        from promptflow._sdk._tracing import setup_exporter_to_pfs

        logging.debug("promptflow-devkit is installed, will continue local setup...")
        setup_exporter_to_pfs()


def _skip_tracing_local_setup() -> bool:
    return str(os.getenv(PF_TRACING_SKIP_LOCAL_SETUP_ENVIRON, "false")).lower() == "true"



Review comment (suggestion):
shall we move the inject_oepn_api out of the setup_exporter_from_environ function? 
So we don't need to add this strance bool parameter here


Code after:
        # so we need to handle this with function signature check, and warn user on this
        if _kwargs_in_func(start_trace_with_devkit):
            logging.debug("compatible promptflow-devkit version, will pass `collection` and `kwargs`...")
            logging.debug("collection: %s", collection)
            logging.debug("kwargs: %s", kwargs)
            start_trace_with_devkit(collection=collection, **kwargs)
        else:
            warning_msg = (
                "incompatible `promptflow-devkit` version installed, which may lead to unexpected behavior; "
                "it is recommended to use 'promptflow-devkit>=1.9.0' for better trace experience."
            )
            logging.warning(warning_msg)
            print(warning_msg)
            logging.debug("will pass `collection`, `attributes`, and `run`...")
            _attributes = kwargs.get("attributes", None)
            _run = kwargs.get("run", None)
            logging.debug("collection: %s", collection)
            logging.debug("attributes: %s", _attributes)
            logging.debug("run: %s", _run)
            start_trace_with_devkit(collection=collection, attributes=_attributes, run=_run)


def setup_exporter_from_environ() -> None:
    # openai instrumentation
    logging.debug("injecting OpenAI API...")
    inject_openai_api()
    logging.debug("OpenAI API injected.")

    # Ignore all the setup if the endpoint is not set
    endpoint = os.getenv(OTEL_EXPORTER_OTLP_ENDPOINT)
    logging.debug("environ OTEL_EXPORTER_OTLP_ENDPOINT: %s", endpoint)
    if not endpoint:
        logging.info("environ OTEL_EXPORTER_OTLP_ENDPOINT is not set, will skip the following setup.")
        return

    if _is_devkit_installed():
        from promptflow._sdk._tracing import setup_exporter_to_pfs

        logging.debug("promptflow-devkit is installed, will continue local setup...")
        setup_exporter_to_pfs()


def _skip_tracing_local_setup() -> bool:
    return str(os.getenv(PF_TRACING_SKIP_LOCAL_SETUP_ENVIRON, "false")).lower() == "true"


def _get_collection_from_cwd() -> str:
    """Try to use cwd folder name as collection name; will fall back to default value if run into exception."""
    cur_folder_name = ""
    try:
        cwd = os.getcwd()