more sentry performance tracing

This commit is contained in:
burnettk 2023-01-31 22:30:15 -05:00
parent 8a93fe0491
commit cd2ff49ea6
3 changed files with 56 additions and 4 deletions

View File

@ -157,6 +157,29 @@ def get_hacked_up_app_for_script() -> flask.app.Flask:
return app
def traces_sampler(sampling_context: Any) -> Any:
# always inherit
if sampling_context["parent_sampled"] is not None:
return sampling_context["parent_sampled"]
if "wsgi_environ" in sampling_context:
wsgi_environ = sampling_context["wsgi_environ"]
path_info = wsgi_environ.get("PATH_INFO")
request_method = wsgi_environ.get("REQUEST_METHOD")
# tasks_controller.task_submit
# this is the current pain point as of 31 jan 2023.
if (
path_info
and path_info.startswith("/v1.0/tasks/")
and request_method == "PUT"
):
return 1
# Default sample rate for all others (replaces traces_sample_rate)
return 0.01
def configure_sentry(app: flask.app.Flask) -> None:
"""Configure_sentry."""
import sentry_sdk
@ -193,5 +216,10 @@ def configure_sentry(app: flask.app.Flask) -> None:
# of transactions for performance monitoring.
# We recommend adjusting this value to less than 1(00%) in production.
traces_sample_rate=float(sentry_traces_sample_rate),
traces_sampler=traces_sampler,
# The profiles_sample_rate setting is relative to the traces_sample_rate setting.
_experiments={
"profiles_sample_rate": 1,
},
before_send=before_send,
)

View File

@ -94,8 +94,6 @@ def setup_config(app: Flask) -> None:
else:
print("base_permissions: no permissions file loaded")
# unversioned (see .gitignore) config that can override everything and include secrets.
# src/spiffworkflow_backend/config/secrets.py
app.config.from_pyfile(os.path.join("config", "secrets.py"), silent=True)

View File

@ -10,6 +10,7 @@ from typing import Union
import flask.wrappers
import jinja2
import sentry_sdk
from flask import current_app
from flask import g
from flask import jsonify
@ -326,13 +327,12 @@ def process_data_show(
)
def task_submit(
def task_submit_shared(
process_instance_id: int,
task_id: str,
body: Dict[str, Any],
terminate_loop: bool = False,
) -> flask.wrappers.Response:
"""Task_submit_user_data."""
principal = _find_principal_or_raise()
process_instance = _find_process_instance_by_id_or_raise(process_instance_id)
if not process_instance.can_submit_task():
@ -417,6 +417,32 @@ def task_submit(
return Response(json.dumps({"ok": True}), status=202, mimetype="application/json")
def task_submit(
process_instance_id: int,
task_id: str,
body: Dict[str, Any],
terminate_loop: bool = False,
) -> flask.wrappers.Response:
"""Task_submit_user_data."""
sentry_op = "controller_action"
sentry_transaction_name = "tasks_controller.task_submit"
transaction = sentry_sdk.Hub.current.scope.transaction
if transaction is None:
current_app.logger.debug(
"transaction was None. pretty sure this never happens."
)
with sentry_sdk.start_transaction(op=sentry_op, name=sentry_transaction_name):
return task_submit_shared(
process_instance_id, task_id, body, terminate_loop
)
else:
current_app.logger.debug("transaction existed.")
with transaction.start_child(op=sentry_op, description=sentry_transaction_name):
return task_submit_shared(
process_instance_id, task_id, body, terminate_loop
)
def _get_tasks(
processes_started_by_user: bool = True,
has_lane_assignment_id: bool = True,