-
Notifications
You must be signed in to change notification settings - Fork 509
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
ref: Event Type #2753
ref: Event Type #2753
Conversation
Will need to either:
|
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.
Great work @szokeasaurusrex looks great!
I have a few questions.
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.
Thank you for the feedback! I replied to your comments and made some changes
with capture_internal_exceptions(): | ||
contexts.setdefault("trace", {}).update(sentry_span.get_trace_context()) # type: ignore[attr-defined] |
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.
Added for same reason as above, and similarly we don't need it any more
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.
Typing rocks!
* ref: Improve scrub_dict typing (#2768) This change improves the typing of the scrub_dict method. Previously, the scrub_dict method's type hints indicated that only dict[str, Any] was accepted as the parameter. However, the method is actually implemented to accept any object, since it checks the types of the parameters at runtime. Therefore, object is a more appropriate type hint for the parameter. #2753 depends on this change for mypy to pass * Propagate sentry-trace and baggage to huey tasks (#2792) This PR enables passing `sentry-trace` and `baggage` headers to background tasks using the Huey task queue. This allows easily correlating what happens inside a background task with whatever transaction (e.g. a user request in a Django application) queued the task in the first place. Periodic tasks do not get these headers, because otherwise each execution of the periodic task would be tied to the same parent trace (the long-running worker process). --- Co-authored-by: Anton Pirker <[email protected]> * OpenAI integration (#2791) * OpenAI integration * Fix linting errors * Fix CI * Fix lint * Fix more CI issues * Run tests on version pinned OpenAI too * Fix pydantic issue in test * Import type in TYPE_CHECKING gate * PR feedback fixes * Fix tiktoken test variant * PII gate the request and response * Rename set_data tags * Move doc location * Add "exclude prompts" flag as optional * Change prompts to be excluded by default * Set flag in tests * Fix tiktoken tox.ini extra dash * Change strip PII semantics * More test coverage for PII * notiktoken --------- Co-authored-by: Anton Pirker <[email protected]> * Add a method for normalizing data passed to set_data (#2800) * Discard open spans after 10 minutes (#2801) OTel spans that are handled in the Sentry span processor can never be finished/closed. This leads to a memory leak. This change makes sure that open spans will be removed from memory after 10 minutes to prevent memory usage from growing constantly. Fixes #2722 --------- Co-authored-by: Daniel Szoke <[email protected]> * ref: Event Type (#2753) Implements type hinting for Event via a TypedDict. This commit mainly adjusts type hints; however, there are also some minor code changes to make the code type-safe following the new changes. Some items in the Event could have their types expanded by being defined as TypedDicts themselves. These items have been indicated with TODO comments. Fixes GH-2357 * Fix mypy in `client.py` * Fix functools import * Fix CI config problem ... by running `python scripts/split-tox-gh-actions/split-tox-gh-actions.py` --------- Co-authored-by: Christian Schneider <[email protected]> Co-authored-by: Anton Pirker <[email protected]> Co-authored-by: colin-sentry <[email protected]>
Looks like a breaking change. Is there a way to use functions with def before_send(event: dict[str, Any], _: dict[str, Any]) -> dict[str, Any]:
for frame in iter_event_frames(event):
do_smth(frame)
return event Now checking with mypy gives an errors:
I'd be happy to switch to using |
Hi @ods, thank you for reaching out!
We released However, because we need to maintain compatibility with old Python versions, we need to define the from typing import TYPE_CHECKING
if TYPE_CHECKING:
from sentry_sdk.typing import Event
def before_send(event: "Event", _: dict[str, Any]) -> "Event":
...
I understand your frustration, and while I certainly believe we made a mistake by using a private type on publicly exposed functions, our reasoning with this change is that it is not breaking because it only affects type hints, which are not evaluated at runtime and not enforced by the Python language. The code is fully backwards-compatible at runtime, and the runtime public API has remained the same as previously – any code written before this change will continue to work the same now after the change. |
Thanks for quick response!
Strictly speaking it's not the only option. The type can be defined unconditionally, but imported inside Ok, anyway we have to find some workaround. |
This is a good idea! I can certainly look into implementing a conditional import that ensures Event is always defined. |
Implements type hinting for
Event
via a TypedDict. This PR mainly adjusts type hints; however, there are also some minor code changes to make the code type-safe following the new changes.Some items in the
Event
could have their types expanded by being defined as TypedDicts themselves. These items have been indicated withTODO
comments.Fixes GH-2357