|
11 | 11 | ) |
12 | 12 | from sentry_sdk.integrations._wsgi_common import RequestExtractor |
13 | 13 | from sentry_sdk.integrations.wsgi import SentryWsgiMiddleware |
14 | | -from sentry_sdk.traces import SOURCE_FOR_STYLE as SEGMENT_SOURCE_FOR_STYLE |
| 14 | +from sentry_sdk.traces import SegmentNameSource |
15 | 15 | from sentry_sdk.utils import ( |
16 | 16 | capture_internal_exceptions, |
17 | 17 | ensure_integration_enabled, |
18 | 18 | event_from_exception, |
19 | 19 | parse_version, |
20 | | - transaction_from_function, |
21 | 20 | ) |
22 | 21 |
|
23 | 22 | if TYPE_CHECKING: |
|
45 | 44 | raise DidNotEnable("Bottle not installed or incompatible") |
46 | 45 |
|
47 | 46 |
|
48 | | -TRANSACTION_STYLE_VALUES = ("endpoint", "url") |
49 | | - |
50 | | - |
51 | 47 | class BottleIntegration(Integration): |
52 | 48 | identifier = "bottle" |
53 | 49 | origin = f"auto.http.{identifier}" |
54 | 50 |
|
55 | | - transaction_style = "" |
56 | | - |
57 | 51 | def __init__( |
58 | 52 | self, |
59 | | - transaction_style: str = "endpoint", |
60 | 53 | *, |
61 | 54 | failed_request_status_codes: "Set[int]" = _DEFAULT_FAILED_REQUEST_STATUS_CODES, |
62 | 55 | ) -> None: |
63 | | - if transaction_style not in TRANSACTION_STYLE_VALUES: |
64 | | - raise ValueError( |
65 | | - "Invalid value for transaction_style: %s (must be in %s)" |
66 | | - % (transaction_style, TRANSACTION_STYLE_VALUES) |
67 | | - ) |
68 | | - self.transaction_style = transaction_style |
69 | 56 | self.failed_request_status_codes = failed_request_status_codes |
70 | 57 |
|
71 | 58 | @staticmethod |
@@ -127,9 +114,12 @@ def _patched_handle(self: "Bottle", environ: "Dict[str, Any]") -> "Any": |
127 | 114 | if route_path is not None: |
128 | 115 | server_span.set_attribute(SPANDATA.HTTP_ROUTE, route_path) |
129 | 116 |
|
130 | | - _set_segment_name_and_source( |
131 | | - transaction_style=integration.transaction_style |
132 | | - ) |
| 117 | + name = _get_transaction_name(bottle_request) |
| 118 | + if name: |
| 119 | + sentry_sdk.get_current_scope().set_transaction_name( |
| 120 | + name, |
| 121 | + source=SegmentNameSource.ROUTE, |
| 122 | + ) |
133 | 123 |
|
134 | 124 | return res |
135 | 125 |
|
@@ -192,38 +182,20 @@ def size_of_file(self, file: "FileUpload") -> int: |
192 | 182 | return file.content_length |
193 | 183 |
|
194 | 184 |
|
195 | | -def _get_transaction_name(transaction_style: str, request: "Any") -> str: |
| 185 | +def _get_transaction_name(request: "Any") -> str: |
196 | 186 | try: |
197 | | - if transaction_style == "url": |
198 | | - return request.route.rule or "bottle request" |
199 | | - else: |
200 | | - return ( |
201 | | - request.route.name |
202 | | - or transaction_from_function(request.route.callback) |
203 | | - or "bottle request" |
204 | | - ) |
| 187 | + return request.route.rule or "bottle request" |
205 | 188 | except RuntimeError: |
206 | 189 | return "bottle request" |
207 | 190 |
|
208 | 191 |
|
209 | | -def _set_segment_name_and_source(transaction_style: str) -> None: |
210 | | - name = _get_transaction_name(transaction_style, bottle_request) |
211 | | - if name: |
212 | | - sentry_sdk.get_current_scope().set_transaction_name( |
213 | | - name, |
214 | | - source=SEGMENT_SOURCE_FOR_STYLE[transaction_style], |
215 | | - ) |
216 | | - |
217 | | - |
218 | 192 | def _make_request_event_processor( |
219 | 193 | app: "Bottle", request: "LocalRequest", integration: "BottleIntegration" |
220 | 194 | ) -> "EventProcessor": |
221 | 195 | def event_processor(event: "Event", hint: "dict[str, Any]") -> "Event": |
222 | | - name = _get_transaction_name(integration.transaction_style, request) |
| 196 | + name = _get_transaction_name(request) |
223 | 197 | event["transaction"] = name |
224 | | - event["transaction_info"] = { |
225 | | - "source": SEGMENT_SOURCE_FOR_STYLE[integration.transaction_style] |
226 | | - } |
| 198 | + event["transaction_info"] = {"source": SegmentNameSource.ROUTE} |
227 | 199 |
|
228 | 200 | with capture_internal_exceptions(): |
229 | 201 | BottleRequestExtractor(request).extract_into_event(event) |
|
0 commit comments