Skip to content
Open
Show file tree
Hide file tree
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
12 changes: 12 additions & 0 deletions sentry_sdk/integrations/bottle.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from typing import TYPE_CHECKING

import sentry_sdk
from sentry_sdk.consts import SPANDATA
Comment thread
alexander-alderman-webb marked this conversation as resolved.
from sentry_sdk.integrations import (
_DEFAULT_FAILED_REQUEST_STATUS_CODES,
DidNotEnable,
Expand Down Expand Up @@ -104,6 +105,17 @@ def _patched_handle(self: "Bottle", environ: "Dict[str, Any]") -> "Any":
)
res = old_handle(self, environ)

server_span = sentry_sdk.get_current_scope()._server_segment_span
if server_span is not None:
route_path = None
try:
route_path = bottle_request.route.rule
except RuntimeError:
pass

if route_path is not None:
server_span.set_attribute(SPANDATA.HTTP_ROUTE, route_path)

if has_span_streaming_enabled(sentry_sdk.get_client().options):
_set_segment_name_and_source(
transaction_style=integration.transaction_style
Expand Down
27 changes: 27 additions & 0 deletions tests/integrations/bottle/test_bottle.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

import sentry_sdk
from sentry_sdk import capture_message
from sentry_sdk.consts import SPANDATA
from sentry_sdk.integrations.bottle import BottleIntegration
from sentry_sdk.integrations.logging import LoggingIntegration
from sentry_sdk.serializer import MAX_DATABAG_BREADTH
Expand Down Expand Up @@ -662,6 +663,32 @@ def named_hi():
assert segment["attributes"]["sentry.segment.name.source"] == expected_source


def test_http_route(
sentry_init,
capture_items,
):
sentry_init(
integrations=[BottleIntegration()],
traces_sample_rate=1.0,
trace_lifecycle="stream",
)
items = capture_items("span")

app = Bottle()

@app.route("/message/<message_id>")
def hi_with_id(message_id):
return "ok"

client = Client(app)
client.get("/message/123456")

sentry_sdk.flush()

(segment,) = (item.payload for item in items if item.payload.get("is_segment"))
assert segment["attributes"][SPANDATA.HTTP_ROUTE] == "/message/<message_id>"


def test_span_streaming_with_error(sentry_init, capture_items):
sentry_init(
integrations=[BottleIntegration()],
Expand Down
Loading