From 8f6c011db163efba3122f3ec55b2d7e118ccaff0 Mon Sep 17 00:00:00 2001 From: "Aaron (\"AJ\") Steers" Date: Wed, 13 Mar 2024 12:24:08 -0700 Subject: [PATCH] Chore: Add telemetry tracking flag for `langchain-airbyte`; Fix: incorrect telemetry URL printed in first-time execution (#125) --- airbyte/_util/meta.py | 14 ++++++++++++++ airbyte/_util/telemetry.py | 6 ++++-- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/airbyte/_util/meta.py b/airbyte/_util/meta.py index 92dc00db..ffd9ee55 100644 --- a/airbyte/_util/meta.py +++ b/airbyte/_util/meta.py @@ -30,6 +30,20 @@ def is_ci() -> bool: return "CI" in os.environ +@lru_cache +def is_langchain() -> bool: + """Return True if running in a Langchain environment. + + This checks for the presence of the 'langchain-airbyte' package. + + TODO: A more robust check would inspect the call stack or another flag to see if we are actually + being invoked via LangChain, vs being installed side-by-side. + + This is cached for performance reasons. + """ + return "langchain_airbyte" in sys.modules + + @lru_cache def is_colab() -> bool: return bool(get_colab_release_version()) diff --git a/airbyte/_util/telemetry.py b/airbyte/_util/telemetry.py index 4c9eabb0..92ab65ec 100644 --- a/airbyte/_util/telemetry.py +++ b/airbyte/_util/telemetry.py @@ -104,8 +104,9 @@ def _setup_analytics() -> str | bool: if not _ANALYTICS_FILE.exists(): # This is a one-time message to inform the user that we are tracking anonymous usage stats. print( - "Anonymous usage reporting is enabled. For more information or to opt out, please" - " see https://docs.airbyte.io/pyairbyte/anonymized-usage-statistics" + "Thank you for using PyAirbyte!\n" + "Anonymous usage reporting is currently enabled. For more information, please" + " see https://docs.airbyte.com/telemetry" ) if _ANALYTICS_FILE.exists(): @@ -227,6 +228,7 @@ def one_way_hash( def get_env_flags() -> dict[str, Any]: flags: dict[str, bool | str] = { "CI": meta.is_ci(), + "LANGCHAIN": meta.is_langchain(), "NOTEBOOK_RUNTIME": ( "GOOGLE_COLAB" if meta.is_colab()