Skip to content

Commit

Permalink
add docstring and rename functions
Browse files Browse the repository at this point in the history
  • Loading branch information
hubertdeng123 committed Feb 19, 2025
1 parent 7ef2304 commit 01e550d
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 7 deletions.
2 changes: 1 addition & 1 deletion devservices/commands/up.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ def _up(
service=service,
remote_dependencies=sorted_remote_dependencies,
current_env=current_env,
command="upd",
command="up",
options=["-d", "--pull", "always"],
service_config_file_path=service_config_file_path,
mode_dependencies=mode_dependencies,
Expand Down
24 changes: 18 additions & 6 deletions devservices/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,15 +47,27 @@
error_trace_ids = set()


# This is a hack to get the trace_id from the errors we care about
def set_error_status(event: Event, hint: Hint) -> Event:
"""Gets the trace_id from the errors we care about.
This function is used as a before_send callback for Sentry to track error trace IDs.
It adds the trace_id to error_trace_ids set for non-info level events.
"""


def before_send_error(event: Event, hint: Hint) -> Event:
if event["level"] != "info":
error_trace_ids.add(event["contexts"]["trace"]["trace_id"])
return event


# This sets the status of a transaction to unknown if it's not an error we care about
def set_transaction_status(event: Event, hint: Hint) -> Event:
"""Manually sets the status of a transaction.
This function is used as a before_send_transaction callback for Sentry to mark transaction status
as unknown if they don't correspond to errors we care about.
"""


def before_send_transaction(event: Event, hint: Hint) -> Event:
if event["contexts"]["trace"]["trace_id"] not in error_trace_ids:
event["contexts"]["trace"]["status"] = "unknown"
return event
Expand All @@ -69,8 +81,8 @@ def set_transaction_status(event: Event, hint: Hint) -> Event:
enable_tracing=True,
integrations=[ArgvIntegration()],
environment=sentry_environment,
before_send=set_error_status,
before_send_transaction=set_transaction_status,
before_send=before_send_error,
before_send_transaction=before_send_transaction,
release=current_version,
)
username = getpass.getuser()
Expand Down

0 comments on commit 01e550d

Please sign in to comment.