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

feat(profiling): Support for multithreaded profiles #1570

Merged
merged 3 commits into from
Sep 12, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions sentry_sdk/_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
"attachment",
"session",
"internal",
"profile",
]
SessionStatus = Literal["ok", "exited", "crashed", "abnormal"]
EndpointType = Literal["store", "envelope"]
Expand Down
1 change: 1 addition & 0 deletions sentry_sdk/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -403,6 +403,7 @@ def capture_event(
if is_transaction:
if "profile" in event_opt:
event_opt["profile"]["transaction_id"] = event_opt["event_id"]
event_opt["profile"]["environment"] = event_opt.get("environment")
event_opt["profile"]["version_name"] = event_opt.get("release", "")
envelope.add_profile(event_opt.pop("profile"))
envelope.add_transaction(event_opt)
Expand Down
2 changes: 2 additions & 0 deletions sentry_sdk/envelope.py
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,8 @@ def data_category(self):
return "error"
elif ty == "client_report":
return "internal"
elif ty == "profile":
return "profile"
else:
return "default"

Expand Down
14 changes: 14 additions & 0 deletions sentry_sdk/integrations/profiling.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
from sentry_sdk.integrations import DidNotEnable, Integration
from sentry_sdk.profiler import _setup_profiler


class ProfilingIntegration(Integration):
identifier = "profiling"

@staticmethod
def setup_once():
# type: () -> None
try:
_setup_profiler()
except ValueError:
raise DidNotEnable("Profiling can only be enabled from the main thread.")
4 changes: 2 additions & 2 deletions sentry_sdk/integrations/wsgi.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from sentry_sdk.tracing import Transaction, TRANSACTION_SOURCE_ROUTE
from sentry_sdk.sessions import auto_session_tracking
from sentry_sdk.integrations._wsgi_common import _filter_headers
from sentry_sdk.profiler import profiling
from sentry_sdk.profiler import start_profiling

from sentry_sdk._types import MYPY

Expand Down Expand Up @@ -131,7 +131,7 @@ def __call__(self, environ, start_response):

with hub.start_transaction(
transaction, custom_sampling_context={"wsgi_environ": environ}
), profiling(transaction, hub):
), start_profiling(transaction, hub):
try:
rv = self.app(
environ,
Expand Down
Loading