Skip to content
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

Change code.filepath frame picking logic #2568

Merged
merged 26 commits into from
Dec 12, 2023
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
77b3a14
Move `add_query_source` to `record_sql_queries`
sentrivana Dec 5, 2023
ea74fd9
wip
sentrivana Dec 5, 2023
4b75585
always look for a frame
sentrivana Dec 5, 2023
850b8d0
wip
sentrivana Dec 5, 2023
bb63c6e
Merge branch 'master' into ivana/change-frame-picking-logic
sentrivana Dec 5, 2023
46c859e
fix asyncpg
sentrivana Dec 5, 2023
a2cb3d8
Merge branch 'master' into ivana/change-frame-picking-logic
antonpirker Dec 6, 2023
5401dec
Merge branch 'master' into ivana/change-frame-picking-logic
sentrivana Dec 6, 2023
d522d2f
tweak frame finding logic
sentrivana Dec 7, 2023
fdce522
leave is_external_source be
sentrivana Dec 7, 2023
cc006d4
Merge branch 'master' into ivana/change-frame-picking-logic
antonpirker Dec 7, 2023
6ce6190
Merge branch 'master' into ivana/change-frame-picking-logic
sentrivana Dec 11, 2023
7bead91
Respect in_app_include, exclude
sentrivana Dec 11, 2023
e901f60
typo
sentrivana Dec 11, 2023
9ef3cbb
caution
sentrivana Dec 11, 2023
9feb06b
Merge branch 'master' into ivana/change-frame-picking-logic
sentrivana Dec 11, 2023
aefe488
more guards
sentrivana Dec 11, 2023
e8e0af1
maybe fix 2.7
sentrivana Dec 11, 2023
785e2f9
mypy
sentrivana Dec 11, 2023
1623d4f
compat
sentrivana Dec 11, 2023
a405aa9
small tweak
sentrivana Dec 11, 2023
f38607b
leftovers
sentrivana Dec 11, 2023
2e3c05a
better exclude test that actually does something
sentrivana Dec 11, 2023
10472be
trying something
sentrivana Dec 11, 2023
48d96df
another attempt
sentrivana Dec 11, 2023
c4dfd11
add some capture_internal_exceptions
sentrivana Dec 11, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 7 additions & 2 deletions sentry_sdk/integrations/asyncpg.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from sentry_sdk.consts import OP, SPANDATA
from sentry_sdk.integrations import Integration, DidNotEnable
from sentry_sdk.tracing import Span
from sentry_sdk.tracing_utils import record_sql_queries
from sentry_sdk.tracing_utils import add_query_source, record_sql_queries
from sentry_sdk.utils import parse_version, capture_internal_exceptions

try:
Expand Down Expand Up @@ -66,8 +66,12 @@ async def _inner(*args: Any, **kwargs: Any) -> T:
return await f(*args, **kwargs)

query = args[1]
with record_sql_queries(hub, None, query, None, None, executemany=False):
with record_sql_queries(
hub, None, query, None, None, executemany=False
) as span:
res = await f(*args, **kwargs)

add_query_source(hub, span)
antonpirker marked this conversation as resolved.
Show resolved Hide resolved
return res

return _inner
Expand Down Expand Up @@ -118,6 +122,7 @@ async def _inner(*args: Any, **kwargs: Any) -> T:
with _record(hub, None, query, params_list, executemany=executemany) as span:
_set_db_data(span, args[0])
res = await f(*args, **kwargs)

return res

return _inner
Expand Down
13 changes: 10 additions & 3 deletions sentry_sdk/integrations/django/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
from sentry_sdk.scope import add_global_event_processor
from sentry_sdk.serializer import add_global_repr_processor
from sentry_sdk.tracing import SOURCE_FOR_STYLE, TRANSACTION_SOURCE_URL
from sentry_sdk.tracing_utils import record_sql_queries
from sentry_sdk.tracing_utils import add_query_source, record_sql_queries
from sentry_sdk.utils import (
AnnotatedValue,
HAS_REAL_CONTEXTVARS,
Expand Down Expand Up @@ -638,7 +638,10 @@
self.mogrify,
options,
)
return real_execute(self, sql, params)
result = real_execute(self, sql, params)

Check warning on line 641 in sentry_sdk/integrations/django/__init__.py

View check run for this annotation

Codecov / codecov/patch

sentry_sdk/integrations/django/__init__.py#L641

Added line #L641 was not covered by tests

add_query_source(hub, span)
return result

Check warning on line 644 in sentry_sdk/integrations/django/__init__.py

View check run for this annotation

Codecov / codecov/patch

sentry_sdk/integrations/django/__init__.py#L643-L644

Added lines #L643 - L644 were not covered by tests

def executemany(self, sql, param_list):
# type: (CursorWrapper, Any, List[Any]) -> Any
Expand All @@ -650,7 +653,11 @@
hub, self.cursor, sql, param_list, paramstyle="format", executemany=True
) as span:
_set_db_data(span, self)
return real_executemany(self, sql, param_list)

result = real_executemany(self, sql, param_list)

Check warning on line 657 in sentry_sdk/integrations/django/__init__.py

View check run for this annotation

Codecov / codecov/patch

sentry_sdk/integrations/django/__init__.py#L657

Added line #L657 was not covered by tests

add_query_source(hub, span)
antonpirker marked this conversation as resolved.
Show resolved Hide resolved
return result

Check warning on line 660 in sentry_sdk/integrations/django/__init__.py

View check run for this annotation

Codecov / codecov/patch

sentry_sdk/integrations/django/__init__.py#L659-L660

Added lines #L659 - L660 were not covered by tests

def connect(self):
# type: (BaseDatabaseWrapper) -> None
Expand Down
10 changes: 9 additions & 1 deletion sentry_sdk/integrations/sqlalchemy.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from sentry_sdk.db.explain_plan.sqlalchemy import attach_explain_plan_to_span
from sentry_sdk.hub import Hub
from sentry_sdk.integrations import Integration, DidNotEnable
from sentry_sdk.tracing_utils import record_sql_queries
from sentry_sdk.tracing_utils import add_query_source, record_sql_queries

from sentry_sdk.utils import parse_version

Expand Down Expand Up @@ -84,6 +84,10 @@

def _after_cursor_execute(conn, cursor, statement, parameters, context, *args):
# type: (Any, Any, Any, Any, Any, *Any) -> None
hub = Hub.current
if hub.get_integration(SqlalchemyIntegration) is None:
return

Check warning on line 89 in sentry_sdk/integrations/sqlalchemy.py

View check run for this annotation

Codecov / codecov/patch

sentry_sdk/integrations/sqlalchemy.py#L89

Added line #L89 was not covered by tests

ctx_mgr = getattr(
context, "_sentry_sql_span_manager", None
) # type: Optional[ContextManager[Any]]
Expand All @@ -92,6 +96,10 @@
context._sentry_sql_span_manager = None
ctx_mgr.__exit__(None, None, None)

span = context._sentry_sql_span
if span is not None:
add_query_source(hub, span)


def _handle_error(context, *args):
# type: (Any, *Any) -> None
Expand Down
2 changes: 0 additions & 2 deletions sentry_sdk/tracing.py
Original file line number Diff line number Diff line change
Expand Up @@ -488,7 +488,6 @@ def finish(self, hub=None, end_timestamp=None):
self.timestamp = datetime_utcnow()

maybe_create_breadcrumbs_from_span(hub, self)
add_additional_span_data(hub, self)

return None

Expand Down Expand Up @@ -1021,7 +1020,6 @@ async def my_async_function():
from sentry_sdk.tracing_utils import (
Baggage,
EnvironHeaders,
add_additional_span_data,
extract_sentrytrace_data,
has_tracing_enabled,
maybe_create_breadcrumbs_from_span,
Expand Down
9 changes: 0 additions & 9 deletions sentry_sdk/tracing_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -250,15 +250,6 @@ def add_query_source(hub, span):
span.set_data(SPANDATA.CODE_FUNCTION, frame.f_code.co_name)


def add_additional_span_data(hub, span):
# type: (sentry_sdk.Hub, sentry_sdk.tracing.Span) -> None
"""
Adds additional data to the span
"""
if span.op == OP.DB:
add_query_source(hub, span)


def extract_sentrytrace_data(header):
# type: (Optional[str]) -> Optional[Dict[str, Union[str, bool, None]]]
"""
Expand Down