diff --git a/devenv/main.py b/devenv/main.py index 32db0da5..c136ae8d 100644 --- a/devenv/main.py +++ b/devenv/main.py @@ -2,6 +2,8 @@ import argparse import os +import subprocess +import sys from collections.abc import Sequence from devenv import bootstrap @@ -75,17 +77,77 @@ def devenv(argv: Sequence[str], config_path: str) -> ExitCode: def main() -> ExitCode: - import sys + # this is also used to see if we're the child process + script_logfile = os.environ.get("SCRIPT") + + if script_logfile: + return devenv(sys.argv, f"{home}/.config/sentry-devenv/config.ini") + + import tempfile + + _, fp = tempfile.mkstemp() + # script (macos/linux) runs the subcommand with a tty, and tees the output to a file. + # this way we can very easily capture all output from devenv and send it + # to sentry as an attachment if an error occurs. + cmd = ("/usr/bin/script", "-qe", fp, *sys.argv) + import sentry_sdk + from sentry_sdk.scope import Scope sentry_sdk.init( # https://sentry.sentry.io/settings/projects/sentry-dev-env/keys/ dsn="https://9bdb053cb8274ea69231834d1edeec4c@o1.ingest.sentry.io/5723503", - # enable performance monitoring enable_tracing=True, ) - return devenv(sys.argv, f"{home}/.config/sentry-devenv/config.ini") + scope = Scope.get_current_scope() + root_transaction = scope.start_transaction() + + # the reason we're subprocessing instead of os.execv(cmd[0], cmd) + # is that script must exit (so that the complete log file is committed to disk) + # before sentry sends the event... + with root_transaction.start_child(): + rc = subprocess.call(cmd) + + if rc == 0: + return rc + + #import getpass + + # would really like to be able to set filename to the python exception title + # because seeing KeyboardInterrupt vs CalledProcessError is more helpful than + # "tmp29387ldf", but see above comment + #scope.add_attachment(path=fp) + #print(fp) + +# client = Scope.get_client() + + #user = getpass.getuser() +# computer = client.options.get("server_name", "unknown") + + # events are grouped under user@computer + #scope.fingerprint = [f"{user}@test"] + + breakpoint() + event_id = root_transaction.finish() + + # trace + # https://sentry.sentry.io/performance/trace/d86e9d23141f41e2b335fc219e82d3e0 + + # event id feb696d0c83a44a1a73c69f31f10635e + # cant find this anywhere though + # this page doesnt load + # https://sentry.sentry.io/issues/5504551756/events/feb696d0c83a44a1a73c69f31f10635e/?project=5723503 + + # https://sentry.sentry.io/traces/?project=5723503&query=project%3Asentry-dev-env&statsPeriod=24h + # trace overview + + # so i dont think an issue is being created, despite an event being created + + print("trace id: ", root_transaction.trace_id) + print(event_id) + + return rc if __name__ == "__main__":