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

feat: /usr/bin/script wrapper to send full tty output to sentry #124

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
68 changes: 65 additions & 3 deletions devenv/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

import argparse
import os
import subprocess
import sys
from collections.abc import Sequence

from devenv import bootstrap
Expand Down Expand Up @@ -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://[email protected]/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__":
Expand Down