Skip to content

Commit

Permalink
chore(weave): Properly set weave sentry environment #1596
Browse files Browse the repository at this point in the history
  • Loading branch information
tssweeney authored May 2, 2024
1 parent 37cd79c commit a10f525
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 4 deletions.
1 change: 1 addition & 0 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
29 changes: 25 additions & 4 deletions weave/trace_sentry.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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()

0 comments on commit a10f525

Please sign in to comment.