-
Notifications
You must be signed in to change notification settings - Fork 473
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(falcon): Update of Falcon Integration (#1733)
Update Falcon Integration to support Falcon 3.x --------- Co-authored-by: bartolootrit <bartolootrit@users.noreply.github.com>
- Loading branch information
1 parent
f21fc0f
commit f62c83d
Showing
8 changed files
with
141 additions
and
85 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,68 +1,83 @@ | ||
import asyncio | ||
|
||
import pytest | ||
import httpx | ||
import responses | ||
|
||
from sentry_sdk import capture_message, start_transaction | ||
from sentry_sdk.integrations.httpx import HttpxIntegration | ||
|
||
|
||
def test_crumb_capture_and_hint(sentry_init, capture_events): | ||
@pytest.mark.parametrize( | ||
"httpx_client", | ||
(httpx.Client(), httpx.AsyncClient()), | ||
) | ||
def test_crumb_capture_and_hint(sentry_init, capture_events, httpx_client): | ||
def before_breadcrumb(crumb, hint): | ||
crumb["data"]["extra"] = "foo" | ||
return crumb | ||
|
||
sentry_init(integrations=[HttpxIntegration()], before_breadcrumb=before_breadcrumb) | ||
clients = (httpx.Client(), httpx.AsyncClient()) | ||
for i, c in enumerate(clients): | ||
with start_transaction(): | ||
events = capture_events() | ||
|
||
url = "https://httpbin.org/status/200" | ||
if not asyncio.iscoroutinefunction(c.get): | ||
response = c.get(url) | ||
else: | ||
response = asyncio.get_event_loop().run_until_complete(c.get(url)) | ||
|
||
assert response.status_code == 200 | ||
capture_message("Testing!") | ||
|
||
(event,) = events | ||
# send request twice so we need get breadcrumb by index | ||
crumb = event["breadcrumbs"]["values"][i] | ||
assert crumb["type"] == "http" | ||
assert crumb["category"] == "httplib" | ||
assert crumb["data"] == { | ||
"url": url, | ||
"method": "GET", | ||
"http.fragment": "", | ||
"http.query": "", | ||
"status_code": 200, | ||
"reason": "OK", | ||
"extra": "foo", | ||
} | ||
|
||
|
||
def test_outgoing_trace_headers(sentry_init): | ||
|
||
url = "http://example.com/" | ||
responses.add(responses.GET, url, status=200) | ||
|
||
with start_transaction(): | ||
events = capture_events() | ||
|
||
if asyncio.iscoroutinefunction(httpx_client.get): | ||
response = asyncio.get_event_loop().run_until_complete( | ||
httpx_client.get(url) | ||
) | ||
else: | ||
response = httpx_client.get(url) | ||
|
||
assert response.status_code == 200 | ||
capture_message("Testing!") | ||
|
||
(event,) = events | ||
|
||
crumb = event["breadcrumbs"]["values"][0] | ||
assert crumb["type"] == "http" | ||
assert crumb["category"] == "httplib" | ||
assert crumb["data"] == { | ||
"url": url, | ||
"method": "GET", | ||
"http.fragment": "", | ||
"http.query": "", | ||
"status_code": 200, | ||
"reason": "OK", | ||
"extra": "foo", | ||
} | ||
|
||
|
||
@pytest.mark.parametrize( | ||
"httpx_client", | ||
(httpx.Client(), httpx.AsyncClient()), | ||
) | ||
def test_outgoing_trace_headers(sentry_init, httpx_client): | ||
sentry_init(traces_sample_rate=1.0, integrations=[HttpxIntegration()]) | ||
clients = (httpx.Client(), httpx.AsyncClient()) | ||
for i, c in enumerate(clients): | ||
with start_transaction( | ||
name="/interactions/other-dogs/new-dog", | ||
op="greeting.sniff", | ||
# make trace_id difference between transactions | ||
trace_id=f"012345678901234567890123456789{i}", | ||
) as transaction: | ||
url = "https://httpbin.org/status/200" | ||
if not asyncio.iscoroutinefunction(c.get): | ||
response = c.get(url) | ||
else: | ||
response = asyncio.get_event_loop().run_until_complete(c.get(url)) | ||
|
||
request_span = transaction._span_recorder.spans[-1] | ||
assert response.request.headers[ | ||
"sentry-trace" | ||
] == "{trace_id}-{parent_span_id}-{sampled}".format( | ||
trace_id=transaction.trace_id, | ||
parent_span_id=request_span.span_id, | ||
sampled=1, | ||
|
||
url = "http://example.com/" | ||
responses.add(responses.GET, url, status=200) | ||
|
||
with start_transaction( | ||
name="/interactions/other-dogs/new-dog", | ||
op="greeting.sniff", | ||
trace_id="01234567890123456789012345678901", | ||
) as transaction: | ||
if asyncio.iscoroutinefunction(httpx_client.get): | ||
response = asyncio.get_event_loop().run_until_complete( | ||
httpx_client.get(url) | ||
) | ||
else: | ||
response = httpx_client.get(url) | ||
|
||
request_span = transaction._span_recorder.spans[-1] | ||
assert response.request.headers[ | ||
"sentry-trace" | ||
] == "{trace_id}-{parent_span_id}-{sampled}".format( | ||
trace_id=transaction.trace_id, | ||
parent_span_id=request_span.span_id, | ||
sampled=1, | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.