diff --git a/libs/e2e-tests/e2e_tests/test_utils/tracing.py b/libs/e2e-tests/e2e_tests/test_utils/tracing.py index f11ab8b73..24e952f13 100644 --- a/libs/e2e-tests/e2e_tests/test_utils/tracing.py +++ b/libs/e2e-tests/e2e_tests/test_utils/tracing.py @@ -1,17 +1,26 @@ import logging +import os import time from typing import Callable from langsmith import Client -LANGSMITH_CLIENT = Client() +if ( + os.getenv("LANGSMITH_API_KEY", "").strip() + or os.getenv("LANGCHAIN_API_KEY", "").strip() +): + LANGSMITH_CLIENT = Client() +else: + LANGSMITH_CLIENT = None def record_langsmith_sharelink( run_id: str, record_property: Callable, tries: int = 6 ) -> None: try: - sharelink = LANGSMITH_CLIENT.share_run(run_id) + sharelink = ( + LANGSMITH_CLIENT.share_run(run_id) if LANGSMITH_CLIENT else "deactivated" + ) record_property("langsmith_url", sharelink) logging.info("recorded langsmith link: %s", sharelink) except Exception: