Skip to content

Commit

Permalink
url.full
Browse files Browse the repository at this point in the history
  • Loading branch information
sentrivana committed Nov 14, 2024
1 parent 126c3e3 commit c3fe091
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions sentry_sdk/integrations/wsgi.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,9 @@ def __call__(self, environ, start_response):
name=DEFAULT_TRANSACTION_NAME,
source=TRANSACTION_SOURCE_ROUTE,
origin=self.span_origin,
attributes=_prepopulate_attributes(environ),
attributes=_prepopulate_attributes(
environ, self.use_x_forwarded_for
),
)
if should_trace
else nullcontext()
Expand Down Expand Up @@ -313,14 +315,16 @@ def event_processor(event, hint):

ENVIRON_TO_ATTRIBUTE = {
"PATH_INFO": "url.path",
"QUERY_STRING": "url.query",
"REQUEST_METHOD": "http.request.method",
"SERVER_NAME": "server.address",
"SERVER_PORT": "server.port",
"url_scheme": "url.scheme",
"wsgi.url_scheme": "url.scheme",
}


def _prepopulate_attributes(wsgi_environ):
def _prepopulate_attributes(wsgi_environ, use_x_forwarded_for=False):
"""Extract span attributes from the WSGI environment."""
attributes = {}

for property, attr in ENVIRON_TO_ATTRIBUTE.items():
Expand All @@ -336,7 +340,9 @@ def _prepopulate_attributes(wsgi_environ):
attributes["network.protocol.name"] = wsgi_environ["SERVER_PROTOCOL"]

try:
attributes["url.full"] = ""
url = get_request_url(wsgi_environ, use_x_forwarded_for)
query = wsgi_environ.get("QUERY_STRING")
attributes["url.full"] = f"{url}?{query}"
except Exception:
pass

Expand Down

0 comments on commit c3fe091

Please sign in to comment.