mirror of
https://github.com/sartography/spiff-arena.git
synced 2025-02-27 16:40:32 +00:00
more sentry performance tracing
This commit is contained in:
parent
8d2aac16c5
commit
3abe82af4a
@ -157,6 +157,29 @@ def get_hacked_up_app_for_script() -> flask.app.Flask:
|
|||||||
return app
|
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:
|
def configure_sentry(app: flask.app.Flask) -> None:
|
||||||
"""Configure_sentry."""
|
"""Configure_sentry."""
|
||||||
import sentry_sdk
|
import sentry_sdk
|
||||||
@ -193,5 +216,10 @@ def configure_sentry(app: flask.app.Flask) -> None:
|
|||||||
# of transactions for performance monitoring.
|
# of transactions for performance monitoring.
|
||||||
# We recommend adjusting this value to less than 1(00%) in production.
|
# We recommend adjusting this value to less than 1(00%) in production.
|
||||||
traces_sample_rate=float(sentry_traces_sample_rate),
|
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,
|
before_send=before_send,
|
||||||
)
|
)
|
||||||
|
@ -94,8 +94,6 @@ def setup_config(app: Flask) -> None:
|
|||||||
else:
|
else:
|
||||||
print("base_permissions: no permissions file loaded")
|
print("base_permissions: no permissions file loaded")
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# unversioned (see .gitignore) config that can override everything and include secrets.
|
# unversioned (see .gitignore) config that can override everything and include secrets.
|
||||||
# src/spiffworkflow_backend/config/secrets.py
|
# src/spiffworkflow_backend/config/secrets.py
|
||||||
app.config.from_pyfile(os.path.join("config", "secrets.py"), silent=True)
|
app.config.from_pyfile(os.path.join("config", "secrets.py"), silent=True)
|
||||||
|
@ -10,6 +10,7 @@ from typing import Union
|
|||||||
|
|
||||||
import flask.wrappers
|
import flask.wrappers
|
||||||
import jinja2
|
import jinja2
|
||||||
|
import sentry_sdk
|
||||||
from flask import current_app
|
from flask import current_app
|
||||||
from flask import g
|
from flask import g
|
||||||
from flask import jsonify
|
from flask import jsonify
|
||||||
@ -326,13 +327,12 @@ def process_data_show(
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
def task_submit(
|
def task_submit_shared(
|
||||||
process_instance_id: int,
|
process_instance_id: int,
|
||||||
task_id: str,
|
task_id: str,
|
||||||
body: Dict[str, Any],
|
body: Dict[str, Any],
|
||||||
terminate_loop: bool = False,
|
terminate_loop: bool = False,
|
||||||
) -> flask.wrappers.Response:
|
) -> flask.wrappers.Response:
|
||||||
"""Task_submit_user_data."""
|
|
||||||
principal = _find_principal_or_raise()
|
principal = _find_principal_or_raise()
|
||||||
process_instance = _find_process_instance_by_id_or_raise(process_instance_id)
|
process_instance = _find_process_instance_by_id_or_raise(process_instance_id)
|
||||||
if not process_instance.can_submit_task():
|
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")
|
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(
|
def _get_tasks(
|
||||||
processes_started_by_user: bool = True,
|
processes_started_by_user: bool = True,
|
||||||
has_lane_assignment_id: bool = True,
|
has_lane_assignment_id: bool = True,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user