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): Introduce continuous profiling mode #2830

Open
wants to merge 31 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
984695e
feat(profiling): Introduce continuous profiling mode
Zylphrex Mar 15, 2024
92e3263
fix up import and a few things
Zylphrex Mar 15, 2024
455778b
set timestamp accordingly
Zylphrex Mar 15, 2024
3452c7e
ensure thread running at start of transaction
Zylphrex Mar 15, 2024
12cfee6
fix import
Zylphrex Mar 15, 2024
b1be566
format json
Zylphrex Mar 21, 2024
60efea7
some basic tests + teardown
Zylphrex Mar 26, 2024
fd1fa37
Merge branch 'master' into txiao/feat/introduce-continuous-profiling-…
Zylphrex Mar 27, 2024
dea4987
send envelope
Zylphrex Mar 27, 2024
ca4594c
run black
Zylphrex Mar 27, 2024
94e77cd
add another test but it doesnt work yet
Zylphrex Mar 27, 2024
bf81ab2
test should work now
Zylphrex Mar 27, 2024
96b1807
run lint
Zylphrex Mar 27, 2024
420d5b8
should be chunk id
Zylphrex Mar 27, 2024
c59adb1
single timestamp per profiler id
Zylphrex Mar 27, 2024
ec1240d
lint
Zylphrex Mar 27, 2024
fa5e0d4
ensure chunks are flushed
Zylphrex Mar 27, 2024
988f609
add profiler id to span data
Zylphrex Apr 4, 2024
719dc1a
fix circular import
Zylphrex Apr 5, 2024
f7f488e
fix lint
Zylphrex Apr 11, 2024
aa177de
Merge branch 'master' of github.com:getsentry/sentry-python into txia…
Zylphrex Apr 11, 2024
f70a04a
Merge branch 'master' into txiao/feat/introduce-continuous-profiling-…
Zylphrex Apr 25, 2024
c1e2bb5
lint
Zylphrex Apr 25, 2024
02cbba2
expose start/stop apis
Zylphrex Apr 26, 2024
dff3b9c
autostart profiler once per process
Zylphrex Apr 26, 2024
e4289aa
Merge branch 'master' into txiao/feat/introduce-continuous-profiling-…
Zylphrex May 7, 2024
d0b7704
Merge branch 'master' into txiao/feat/introduce-continuous-profiling-…
Zylphrex May 17, 2024
af4e370
change to auto start and manual start api
Zylphrex May 17, 2024
7ec70c7
fix test
Zylphrex May 17, 2024
0937dd2
fix test
Zylphrex May 17, 2024
10f38bc
run black
Zylphrex May 17, 2024
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
4 changes: 3 additions & 1 deletion sentry_sdk/_types.py
Expand Up @@ -153,12 +153,14 @@
"session",
"internal",
"profile",
"profile_chunk",
"metric_bucket",
"monitor",
]
SessionStatus = Literal["ok", "exited", "crashed", "abnormal"]

ProfilerMode = Literal["sleep", "thread", "gevent", "unknown"]
ContinuousProfilerMode = Literal["thread", "gevent", "unknown"]
ProfilerMode = Union[ContinuousProfilerMode, Literal["sleep"]]

# Type of the metric.
MetricType = Literal["d", "s", "g", "c"]
Expand Down
9 changes: 9 additions & 0 deletions sentry_sdk/client.py
Expand Up @@ -7,6 +7,7 @@
from importlib import import_module

from sentry_sdk._compat import PY37, check_uwsgi_thread_support
from sentry_sdk.continuous_profiler import setup_continuous_profiler
from sentry_sdk.utils import (
capture_internal_exceptions,
current_stacktrace,
Expand Down Expand Up @@ -378,6 +379,14 @@ def _capture_envelope(envelope):
setup_profiler(self.options)
except Exception as e:
logger.debug("Can not set up profiler. (%s)", e)
else:
try:
setup_continuous_profiler(
self.options,
capture_func=_capture_envelope,
)
except Exception as e:
logger.debug("Can not set up continuous profiler. (%s)", e)

finally:
_client_init_debug.set(old_debug)
Expand Down
9 changes: 9 additions & 0 deletions sentry_sdk/consts.py
Expand Up @@ -34,6 +34,7 @@ class EndpointType(Enum):

from sentry_sdk._types import (
BreadcrumbProcessor,
ContinuousProfilerMode,
Event,
EventProcessor,
Hint,
Expand All @@ -55,6 +56,8 @@ class EndpointType(Enum):
"attach_explain_plans": dict[str, Any],
"max_spans": Optional[int],
"record_sql_params": Optional[bool],
"continuous_profiling_auto_start": Optional[bool],
"continuous_profiling_mode": Optional[ContinuousProfilerMode],
"otel_powered_performance": Optional[bool],
"transport_zlib_compression_level": Optional[int],
"transport_num_pools": Optional[int],
Expand Down Expand Up @@ -346,6 +349,12 @@ class SPANDATA:
Example: "MainThread"
"""

PROFILER_ID = "profiler.id"
"""
Label identifying the profiler id that the span occurred in. This should be a string.
Example: "5249fbada8d5416482c2f6e47e337372"
"""


class OP:
ANTHROPIC_MESSAGES_CREATE = "ai.messages.create.anthropic"
Expand Down