Skip to content

Commit

Permalink
Add tracing routes exclusion
Browse files Browse the repository at this point in the history
  • Loading branch information
gi0baro committed May 4, 2023
1 parent 306f382 commit 9e2bb74
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 16 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ Here is the complete list of parameters of the extension configuration:
| sample\_rate | 1 | Error sampling rate |
| traces\_sample\_rate | | Traces sampling rate |
| trace\_websockets | `False` | Enable tracing on websocket routes |
| tracing\_exclude\_routes | | List of specific routes to exclude from tracing |

## Usage

Expand Down
2 changes: 1 addition & 1 deletion emmett_sentry/__version__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "0.3.0"
__version__ = "0.4.0"
4 changes: 3 additions & 1 deletion emmett_sentry/ext.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ class Sentry(Extension):
enable_tracing=False,
sample_rate=1.0,
traces_sample_rate=None,
trace_websockets=False
trace_websockets=False,
tracing_exclude_routes=[]
)
_initialized = False
_errmsg = "You need to configure Sentry extension before using its methods"
Expand All @@ -42,6 +43,7 @@ def on_load(self):
self._before_send_callbacks = []
if not self.config.dsn:
return
self._tracing_excluded_routes = set(self.config.tracing_exclude_routes)
sentry_sdk.init(
dsn=self.config.dsn,
environment=self.config.environment,
Expand Down
30 changes: 17 additions & 13 deletions emmett_sentry/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -200,33 +200,37 @@ async def wrap(*args, **kwargs):


def _build_routing_rec_http(ext, rec_cls):
wrapper = (
_build_http_dispatcher_wrapper_txn if ext.config.enable_tracing else
_build_http_dispatcher_wrapper_err
)

def _routing_rec_http(router, name, match, dispatch):
wrapper = (
_build_http_dispatcher_wrapper_txn if (
ext.config.enable_tracing and
name not in ext._tracing_excluded_routes
) else _build_http_dispatcher_wrapper_err
)

return rec_cls(
name=name,
match=match,
dispatch=wrapper(ext, dispatch)
dispatch=wrapper(ext, name, dispatch)
)

return _routing_rec_http


def _build_routing_rec_ws(ext, rec_cls):
wrapper = (
_build_ws_dispatcher_wrapper_txn if (
ext.config.enable_tracing and ext.config.trace_websockets
) else _build_ws_dispatcher_wrapper_err
)

def _routing_rec_ws(router, name, match, dispatch, flow_recv, flow_send):
wrapper = (
_build_ws_dispatcher_wrapper_txn if (
ext.config.enable_tracing and
ext.config.trace_websockets and
name not in ext._tracing_excluded_routes
) else _build_ws_dispatcher_wrapper_err
)

return rec_cls(
name=name,
match=match,
dispatch=wrapper(ext, dispatch),
dispatch=wrapper(ext, name, dispatch),
flow_recv=flow_recv,
flow_send=flow_send
)
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "emmett-sentry"
version = "0.3.0"
version = "0.4.0"
description = "Sentry extension for Emmett framework"
authors = ["Giovanni Barillari <g@baro.dev>"]
license = "BSD-3-Clause"
Expand Down

0 comments on commit 9e2bb74

Please sign in to comment.