diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index 10af2696a848..9f1f1e87c3a9 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -124,6 +124,7 @@ jobs: env: DD_SERVICE: weave-python DD_ENV: ci + WEAVE_SENTRY_ENV: ci # PARQUET_ENABLED: true # TODO: Enable parquet after available in CI run: CI=1 WB_SERVER_HOST=http://wandbservice WF_CLICKHOUSE_HOST=weave_clickhouse WEAVE_SERVER_DISABLE_ECOSYSTEM=1 source /root/venv/bin/activate && cd weave && pytest --job-num=${{ matrix.job_num }} --timeout=90 ./tests ./ops_arrow ./ecosystem ./trace_server/tests ./trace/tests --ddtrace --durations=5 diff --git a/weave/trace_sentry.py b/weave/trace_sentry.py index ab39446ecf04..50fce3e08e15 100644 --- a/weave/trace_sentry.py +++ b/weave/trace_sentry.py @@ -14,8 +14,10 @@ import functools import pathlib import sys +import os from types import TracebackType from typing import Any, Callable, Dict, Optional, Tuple, Type, Union +import site if sys.version_info >= (3, 8): @@ -67,11 +69,17 @@ def __init__(self) -> None: @property def environment(self) -> str: """Return the environment we're running in.""" - # check if we're in a git repo - is_git = pathlib.Path(__file__).parent.parent.parent.joinpath(".git").exists() + set_env = os.environ.get("WEAVE_SENTRY_ENV", None) + if set_env: + return set_env - # these match the environments for gorilla - return "development" if is_git else "production" + import weave + + is_dev = _is_local_dev_install(weave) + if is_dev: + return "development" + + return "production" @_safe_noop def setup(self) -> None: @@ -213,6 +221,19 @@ def wrapper(*args: Any, **kwargs: Any) -> Any: return watch_dec +def _is_local_dev_install(module: Any) -> bool: + # Check if the __file__ attribute exists + if hasattr(module, "__file__"): + module_path = module.__file__ + # Check if the path is within any of the site-packages directories + for directory in site.getsitepackages(): + if directory in module_path: + return False + return True + else: + return False + + global_trace_sentry = Sentry() global_trace_sentry.setup() global_trace_sentry.configure_scope()