-
Notifications
You must be signed in to change notification settings - Fork 554
feat: Send to Spotlight sidecar #2524
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
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
0377afb
feat: Send to sidecar
HazAT ed34e07
ref: Add Spotlight option
HazAT e36249f
ref: Url or Bool
HazAT 2469b1f
fix: Only create pool once
HazAT 2c0687c
Fix linting
HazAT 56dfcd4
Fix and tests
sl0thentr0py c36c13a
Apply suggestions from code review
HazAT 0516ff0
CR
HazAT 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
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
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,51 @@ | ||
import io | ||
import urllib3 | ||
|
||
from sentry_sdk._types import TYPE_CHECKING | ||
|
||
if TYPE_CHECKING: | ||
from typing import Any | ||
from typing import Dict | ||
from typing import Optional | ||
|
||
from sentry_sdk.utils import logger | ||
from sentry_sdk.envelope import Envelope | ||
|
||
|
||
class SpotlightClient(object): | ||
def __init__(self, url): | ||
# type: (str) -> None | ||
self.url = url | ||
self.http = urllib3.PoolManager() | ||
|
||
def capture_envelope(self, envelope): | ||
# type: (Envelope) -> None | ||
body = io.BytesIO() | ||
envelope.serialize_into(body) | ||
try: | ||
req = self.http.request( | ||
url=self.url, | ||
body=body.getvalue(), | ||
method="POST", | ||
headers={ | ||
"Content-Type": "application/x-sentry-envelope", | ||
}, | ||
) | ||
req.close() | ||
except Exception as e: | ||
logger.exception(str(e)) | ||
|
||
|
||
def setup_spotlight(options): | ||
# type: (Dict[str, Any]) -> Optional[SpotlightClient] | ||
|
||
url = options.get("spotlight") | ||
|
||
if isinstance(url, str): | ||
pass | ||
elif url is True: | ||
url = "http://localhost:8969/stream" | ||
else: | ||
return None | ||
|
||
return SpotlightClient(url) |
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,56 @@ | ||
import pytest | ||
|
||
from sentry_sdk import Hub, capture_exception | ||
|
||
|
||
@pytest.fixture | ||
def capture_spotlight_envelopes(monkeypatch): | ||
def inner(): | ||
envelopes = [] | ||
test_spotlight = Hub.current.client.spotlight | ||
old_capture_envelope = test_spotlight.capture_envelope | ||
|
||
def append_envelope(envelope): | ||
envelopes.append(envelope) | ||
return old_capture_envelope(envelope) | ||
|
||
monkeypatch.setattr(test_spotlight, "capture_envelope", append_envelope) | ||
return envelopes | ||
|
||
return inner | ||
|
||
|
||
def test_spotlight_off_by_default(sentry_init): | ||
sentry_init() | ||
assert Hub.current.client.spotlight is None | ||
|
||
|
||
def test_spotlight_default_url(sentry_init): | ||
sentry_init(spotlight=True) | ||
|
||
spotlight = Hub.current.client.spotlight | ||
assert spotlight is not None | ||
assert spotlight.url == "http://localhost:8969/stream" | ||
|
||
|
||
def test_spotlight_custom_url(sentry_init): | ||
sentry_init(spotlight="http://[email protected]/132") | ||
|
||
spotlight = Hub.current.client.spotlight | ||
assert spotlight is not None | ||
assert spotlight.url == "http://[email protected]/132" | ||
|
||
|
||
def test_spotlight_envelope(sentry_init, capture_spotlight_envelopes): | ||
sentry_init(spotlight=True) | ||
envelopes = capture_spotlight_envelopes() | ||
|
||
try: | ||
raise ValueError("aha!") | ||
except Exception: | ||
capture_exception() | ||
|
||
(envelope,) = envelopes | ||
payload = envelope.items[0].payload.json | ||
|
||
assert payload["exception"]["values"][0]["value"] == "aha!" |
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.
Uh oh!
There was an error while loading. Please reload this page.