-
-
Notifications
You must be signed in to change notification settings - Fork 0
Reproduction for sentry-python#5349 #9
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
sl0thentr0py
wants to merge
1
commit into
main
Choose a base branch
from
repro/sentry-python-5349
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 |
|---|---|---|
| @@ -0,0 +1,52 @@ | ||
| # Reproduction for sentry-python#5349 | ||
|
|
||
| **Issue:** https://github.com/getsentry/sentry-python/issues/5349 | ||
|
|
||
| ## Description | ||
|
|
||
| This reproduces the issue where `requests` library calls show incorrect/very short timing (< 1ms) in `http.client` spans with sentry-sdk 2.x. In version 1.45, the spans correctly measured the actual HTTP request duration. | ||
|
|
||
| The user reports that after upgrading from sentry-sdk 1.45 to 2.49, the `http.client` spans show impossibly short durations that don't reflect the actual I/O time spent on HTTP requests. | ||
|
|
||
| ## Steps to Reproduce | ||
|
|
||
| 1. Install dependencies: | ||
| ```bash | ||
| uv sync | ||
| ``` | ||
|
|
||
| 2. Set your Sentry DSN: | ||
| ```bash | ||
| export SENTRY_DSN=your_dsn_here | ||
| ``` | ||
|
|
||
| 3. Run the reproduction: | ||
| ```bash | ||
| uv run python main.py | ||
| ``` | ||
|
|
||
| 4. Make requests to the endpoints: | ||
| ```bash | ||
| # Single request (should take ~1 second) | ||
| curl http://localhost:8000/ | ||
|
|
||
| # Multiple requests (should take ~3 seconds total) | ||
| curl http://localhost:8000/multiple-requests | ||
| ``` | ||
|
|
||
| 5. Check the traces in Sentry | ||
|
|
||
| ## Expected Behavior | ||
|
|
||
| The `http.client` spans for requests to `httpbin.org/delay/1` should show approximately 1000ms duration, reflecting the actual time spent on the HTTP request. | ||
|
|
||
| ## Actual Behavior | ||
|
|
||
| The `http.client` spans show impossibly short times (< 1ms) that don't reflect the real I/O time spent on the request. | ||
|
|
||
| ## Environment | ||
|
|
||
| - Python: 3.9+ | ||
| - sentry-sdk: 2.49.0+ | ||
| - fastapi: 0.115.0+ | ||
| - requests: 2.32.0+ |
This file contains hidden or 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 |
|---|---|---|
| @@ -0,0 +1,100 @@ | ||
| """ | ||
| Reproduction for sentry-python#5349 | ||
| https://github.com/getsentry/sentry-python/issues/5349 | ||
|
|
||
| This reproduces the issue where requests library calls show incorrect/very short | ||
| timing (< 1ms) in http.client spans with sentry-sdk 2.x, compared to version 1.45 | ||
| where it correctly measured the actual HTTP request duration. | ||
|
|
||
| Expected: http.client spans should show the actual time spent on HTTP requests | ||
| Actual: http.client spans show impossibly short times (< 1ms) that don't reflect | ||
| the real I/O time spent on the request | ||
| """ | ||
|
|
||
| import os | ||
| import requests | ||
| import sentry_sdk | ||
| from sentry_sdk.integrations.fastapi import FastApiIntegration | ||
| from sentry_sdk.integrations.starlette import StarletteIntegration | ||
| from fastapi import FastAPI | ||
|
|
||
| # Initialize Sentry - set SENTRY_DSN environment variable before running | ||
| sentry_dsn = os.environ.get("SENTRY_DSN", "") | ||
|
|
||
| if sentry_dsn: | ||
| sentry_sdk.init( | ||
| dsn=sentry_dsn, | ||
| integrations=[ | ||
| FastApiIntegration(middleware_spans=True), | ||
| StarletteIntegration(middleware_spans=True), | ||
| ], | ||
| traces_sample_rate=1.0, | ||
| debug=True, # Enable debug to see span info in console | ||
| ) | ||
| print(f"Sentry initialized with DSN: {sentry_dsn[:20]}...") | ||
| else: | ||
| print("WARNING: SENTRY_DSN not set. Set it to see traces in Sentry.") | ||
| print("Run: export SENTRY_DSN=your_dsn_here") | ||
|
|
||
| app = FastAPI() | ||
|
|
||
|
|
||
| @app.get("/") | ||
| def root(): | ||
| """ | ||
| Root endpoint that makes an external HTTP request using the requests library. | ||
|
|
||
| The http.client span for this request should show the actual time taken | ||
| (typically 100-500ms for a real HTTP request), but with the bug it shows | ||
| impossibly short times like < 1ms. | ||
| """ | ||
| # Make a request to a real external API that takes measurable time | ||
| # httpbin.org/delay/1 will delay the response by 1 second | ||
| response = requests.get("https://httpbin.org/delay/1") | ||
|
|
||
| return { | ||
| "message": "Check Sentry traces - the http.client span should show ~1000ms", | ||
| "status_code": response.status_code, | ||
| "external_url": "https://httpbin.org/delay/1", | ||
| } | ||
|
|
||
|
|
||
| @app.get("/multiple-requests") | ||
| def multiple_requests(): | ||
| """ | ||
| Endpoint that makes multiple external HTTP requests. | ||
|
|
||
| This makes it easier to see the timing discrepancy - if each request | ||
| to /delay/1 actually takes ~1 second, but spans show < 1ms, | ||
| the bug is confirmed. | ||
| """ | ||
| results = [] | ||
|
|
||
| # Make 3 requests, each should take ~1 second | ||
| for i in range(3): | ||
| response = requests.get(f"https://httpbin.org/delay/1") | ||
| results.append({ | ||
| "request": i + 1, | ||
| "status": response.status_code, | ||
| }) | ||
|
|
||
| return { | ||
| "message": "Made 3 requests to httpbin.org/delay/1 - each should show ~1000ms in traces", | ||
| "results": results, | ||
| } | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| import uvicorn | ||
| print("\n" + "=" * 60) | ||
| print("Starting FastAPI server for sentry-python#5349 reproduction") | ||
| print("=" * 60) | ||
| print("\nEndpoints:") | ||
| print(" GET / - Single request to httpbin.org/delay/1") | ||
| print(" GET /multiple-requests - Three requests to httpbin.org/delay/1") | ||
| print("\nExpected behavior:") | ||
| print(" http.client spans should show ~1000ms (actual request time)") | ||
| print("\nActual behavior (bug):") | ||
| print(" http.client spans show < 1ms (incorrect/impossible timing)") | ||
| print("\n" + "=" * 60 + "\n") | ||
| uvicorn.run(app, host="0.0.0.0", port=8000) | ||
This file contains hidden or 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 |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| [project] | ||
| name = "repro-sentry-python-5349" | ||
| version = "0.1.0" | ||
| description = "Reproduction for sentry-python#5349 - Missing instrumentation for requests lib calls" | ||
| requires-python = ">=3.9" | ||
| dependencies = [ | ||
| "fastapi>=0.115.0", | ||
| "uvicorn>=0.34.0", | ||
| "requests>=2.32.0", | ||
| "sentry-sdk[fastapi]>=2.49.0", | ||
| ] | ||
|
|
||
| [dependency-groups] | ||
| dev = [] |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unnecessary f-string with no variable interpolation
Low Severity
The f-string
f"https://httpbin.org/delay/1"on line 75 doesn't interpolate any variables, making thefprefix unnecessary. The loop variableiis available but not used in the URL. This is inconsistent with line 53, which correctly uses a plain string"https://httpbin.org/delay/1"for the same URL.