Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add sentry session tracking #4157

Merged
merged 12 commits into from
Sep 6, 2022
30 changes: 30 additions & 0 deletions tests/functional_tests/t0_main/debug/t7_sentry_session.py
@@ -0,0 +1,30 @@
#!/usr/bin/env python
"""Base case - main process init/finish.

---
plugin:
- wandb
tag:
shard: standalone-cpu
var:
- num_sentry_sessions:
:fn:len: :wandb:sentry_sessions
assert:
- :wandb:runs_len: 1
- :wandb:runs[0][config]: {}
- :wandb:runs[0][summary]:
m1: 1
m2: 2
- :wandb:runs[0][exitcode]: 0
- :num_sentry_sessions: 2
"""

import time

import wandb

wandb.init()
wandb.log(dict(m1=1))
wandb.log(dict(m2=2))
# sleep needed for sentry to capture sentry session info
time.sleep(80)
20 changes: 20 additions & 0 deletions tests/unit_tests_old/utils/mock_server.py
Expand Up @@ -97,6 +97,7 @@ def default_ctx():
"n_sweep_runs": 0,
"code_saving_enabled": True,
"sentry_events": [],
"sentry_sessions": [],
"run_cuda_version": None,
# relay mode, keep track of upsert runs for validation
"relay_run_info": {},
Expand Down Expand Up @@ -2227,6 +2228,21 @@ def sentry_put():
ctx["sentry_events"].append(data)
return ""

@app.route("/api/5288891/envelope/", methods=["POST"])
def sentry_session_put():
ctx = get_ctx()
data = request.get_data()
data = gzip.decompress(data)
data = str(data, "utf-8")
envelope = []
for line in data.splitlines():
if not line:
continue
line = json.loads(line)
envelope.append(line)
ctx["sentry_sessions"].append(envelope)
return ""

@app.errorhandler(404)
def page_not_found(e):
print(f"Got request to: {request.url} ({request.method})")
Expand Down Expand Up @@ -2456,6 +2472,10 @@ def alerts(self):
def sentry_events(self):
return self._ctx.get("sentry_events") or []

@property
def sentry_sessions(self):
return self._ctx.get("sentry_sessions") or []

def _debug(self):
if not self._run_id:
items = {"run_ids": "run_ids", "artifacts": "artifacts"}
Expand Down
2 changes: 1 addition & 1 deletion tox.ini
Expand Up @@ -15,7 +15,7 @@ envlist=

[base]
setenv =
YEA_WANDB_VERSION = 0.8.12
YEA_WANDB_VERSION = 0.8.13

[unitbase]
deps =
Expand Down
4 changes: 4 additions & 0 deletions wandb/util.py
Expand Up @@ -257,6 +257,10 @@ def get(key: str) -> Any:
if value is not None and value != "":
scope.set_tag(tag, value)

# Track session so we can get metrics about error free rate
if sentry_hub:
sentry_hub.start_session()
dmitryduev marked this conversation as resolved.
Show resolved Hide resolved


def vendor_setup() -> Callable:
"""This enables us to use the vendor directory for packages we don't depend on
Expand Down