Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master' into potel-base
Browse files Browse the repository at this point in the history
  • Loading branch information
sl0thentr0py committed Jun 27, 2024
2 parents 27e9e82 + c210ad6 commit 4f9257d
Show file tree
Hide file tree
Showing 8 changed files with 72 additions and 18 deletions.
23 changes: 23 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,28 @@
# Changelog

## 2.7.0

- Add `origin` to spans and transactions (#3133) by @antonpirker
- OTel: Set up typing for OTel (#3168) by @sentrivana
- OTel: Auto instrumentation skeleton (#3143) by @sentrivana
- OpenAI: If there is an internal error, still return a value (#3192) by @colin-sentry
- MongoDB: Add MongoDB collection span tag (#3182) by @0Calories
- MongoDB: Change span operation from `db.query` to `db` (#3186) by @0Calories
- MongoDB: Remove redundant command name in query description (#3189) by @0Calories
- Apache Spark: Fix spark driver integration (#3162) by @seyoon-lim
- Apache Spark: Add Spark test suite to tox.ini and to CI (#3199) by @sentrivana
- Codecov: Add failed test commits in PRs (#3190) by @antonpirker
- Update library, Python versions in tests (#3202) by @sentrivana
- Remove Hub from our test suite (#3197) by @antonpirker
- Use env vars for default CA cert bundle location (#3160) by @DragoonAethis
- Create a separate test group for AI (#3198) by @sentrivana
- Add additional stub packages for type checking (#3122) by @Daverball
- Proper naming of requirements files (#3191) by @antonpirker
- Pinning pip because new version does not work with some versions of Celery and Httpx (#3195) by @antonpirker
- build(deps): bump supercharge/redis-github-action from 1.7.0 to 1.8.0 (#3193) by @dependabot
- build(deps): bump actions/checkout from 4.1.6 to 4.1.7 (#3171) by @dependabot
- build(deps): update pytest-asyncio requirement (#3087) by @dependabot

## 2.6.0

- Introduce continuous profiling mode (#2830) by @Zylphrex
Expand Down
2 changes: 1 addition & 1 deletion docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
copyright = "2019-{}, Sentry Team and Contributors".format(datetime.now().year)
author = "Sentry Team and Contributors"

release = "2.6.0"
release = "2.7.0"
version = ".".join(release.split(".")[:2]) # The short X.Y version.


Expand Down
2 changes: 1 addition & 1 deletion sentry_sdk/consts.py
Original file line number Diff line number Diff line change
Expand Up @@ -529,4 +529,4 @@ def _get_default_options():
del _get_default_options


VERSION = "2.6.0"
VERSION = "2.7.0"
8 changes: 2 additions & 6 deletions sentry_sdk/integrations/django/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -325,14 +325,10 @@ def sentry_patched_drf_initial(self, request, *args, **kwargs):
def _patch_channels():
# type: () -> None
try:
# Django < 3.0
from channels.http import AsgiHandler # type: ignore
except ImportError:
try:
# DJango 3.0+
from django.core.handlers.asgi import ASGIHandler as AsgiHandler
except ImportError:
return
return

if not HAS_REAL_CONTEXTVARS:
# We better have contextvars or we're going to leak state between
# requests.
Expand Down
2 changes: 1 addition & 1 deletion sentry_sdk/integrations/django/asgi.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,8 +134,8 @@ async def sentry_patched_get_response_async(self, request):

def patch_channels_asgi_handler_impl(cls):
# type: (Any) -> None

import channels # type: ignore

from sentry_sdk.integrations.django import DjangoIntegration

if channels.__version__ < "3.0.0":
Expand Down
12 changes: 9 additions & 3 deletions sentry_sdk/integrations/starlette.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,14 +73,20 @@ class StarletteIntegration(Integration):

transaction_style = ""

def __init__(self, transaction_style="url", failed_request_status_codes=None):
# type: (str, Optional[list[HttpStatusCodeRange]]) -> None
def __init__(
self,
transaction_style="url",
failed_request_status_codes=None,
middleware_spans=True,
):
# type: (str, Optional[list[HttpStatusCodeRange]], bool) -> None
if transaction_style not in TRANSACTION_STYLE_VALUES:
raise ValueError(
"Invalid value for transaction_style: %s (must be in %s)"
% (transaction_style, TRANSACTION_STYLE_VALUES)
)
self.transaction_style = transaction_style
self.middleware_spans = middleware_spans
self.failed_request_status_codes = failed_request_status_codes or [
range(500, 599)
]
Expand Down Expand Up @@ -110,7 +116,7 @@ def _enable_span_for_middleware(middleware_class):
async def _create_span_call(app, scope, receive, send, **kwargs):
# type: (Any, Dict[str, Any], Callable[[], Awaitable[Dict[str, Any]]], Callable[[Dict[str, Any]], Awaitable[None]], Any) -> None
integration = sentry_sdk.get_client().get_integration(StarletteIntegration)
if integration is None:
if integration is None or not integration.middleware_spans:
return await old_call(app, scope, receive, send, **kwargs)

middleware_name = app.__class__.__name__
Expand Down
4 changes: 2 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def get_file_text(file_name):

setup(
name="sentry-sdk",
version="2.6.0",
version="2.7.0",
author="Sentry Team and Contributors",
author_email="hello@sentry.io",
url="https://github.com/getsentry/sentry-python",
Expand Down Expand Up @@ -129,7 +129,7 @@ def get_file_text(file_name):
"sqlalchemy": ["sqlalchemy>=1.2"],
"starlette": ["starlette>=0.19.1"],
"starlite": ["starlite>=1.48"],
"tornado": ["tornado>=5"],
"tornado": ["tornado>=6"],
},
classifiers=[
"Development Status :: 5 - Production/Stable",
Expand Down
37 changes: 33 additions & 4 deletions tests/integrations/starlette/test_starlette.py
Original file line number Diff line number Diff line change
Expand Up @@ -637,20 +637,49 @@ def test_middleware_spans(sentry_init, capture_events):

(_, transaction_event) = events

expected = [
expected_middleware_spans = [
"ServerErrorMiddleware",
"AuthenticationMiddleware",
"ExceptionMiddleware",
"AuthenticationMiddleware", # 'op': 'middleware.starlette.send'
"ServerErrorMiddleware", # 'op': 'middleware.starlette.send'
"AuthenticationMiddleware", # 'op': 'middleware.starlette.send'
"ServerErrorMiddleware", # 'op': 'middleware.starlette.send'
]

assert len(transaction_event["spans"]) == len(expected_middleware_spans)

idx = 0
for span in transaction_event["spans"]:
if span["op"] == "middleware.starlette":
assert span["description"] == expected[idx]
assert span["tags"]["starlette.middleware_name"] == expected[idx]
if span["op"].startswith("middleware.starlette"):
assert (
span["tags"]["starlette.middleware_name"]
== expected_middleware_spans[idx]
)
idx += 1


def test_middleware_spans_disabled(sentry_init, capture_events):
sentry_init(
traces_sample_rate=1.0,
integrations=[StarletteIntegration(middleware_spans=False)],
)
starlette_app = starlette_app_factory(
middleware=[Middleware(AuthenticationMiddleware, backend=BasicAuthBackend())]
)
events = capture_events()

client = TestClient(starlette_app, raise_server_exceptions=False)
try:
client.get("/message", auth=("Gabriela", "hello123"))
except Exception:
pass

(_, transaction_event) = events

assert len(transaction_event["spans"]) == 0


def test_middleware_callback_spans(sentry_init, capture_events):
sentry_init(
traces_sample_rate=1.0,
Expand Down

0 comments on commit 4f9257d

Please sign in to comment.