-
Notifications
You must be signed in to change notification settings - Fork 550
[Hackweek] Add explain plan to db spans. #2315
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
Conversation
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.
One nit: if we add the new experiment to
sentry-python/sentry_sdk/consts.py
Lines 35 to 49 in 692c0e9
Experiments = TypedDict( | |
"Experiments", | |
{ | |
"max_spans": Optional[int], | |
"record_sql_params": Optional[bool], | |
# TODO: Remove these 2 profiling related experiments | |
"profiles_sample_rate": Optional[float], | |
"profiler_mode": Optional[ProfilerMode], | |
"otel_powered_performance": Optional[bool], | |
"transport_zlib_compression_level": Optional[int], | |
"enable_metrics": Optional[bool], | |
"before_emit_metric": Optional[Callable[[str, MetricTags], bool]], | |
}, | |
total=False, | |
) |
And one thing regarding the cache. If I read it right, once a key is in the cache, it'll never get deleted if it's never accessed again. Is this what we want? Let's say my app does 50 one-time SELECTs at startup which I'm not that interested in, but they'll then occupy the cache, so this will always apply for any future SELECTS
if len(EXPLAIN_CACHE.keys()) >= explain_cache_size:
return False
and we won't run any additional explains.
You are right about the cache! Good catch. (how did I pass our coding interviews? ;-) ) |
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.
LGTM, left a couple of comments.
Co-authored-by: Ivana Kellyerova <ivana.kellyerova@sentry.io>
Co-authored-by: Ivana Kellyerova <ivana.kellyerova@sentry.io>
This is a proof of concept of adding the explain plan to db spans. The explain plan will be added to the span in the
db.explain_plan
data item.There is a cache to make sure that the explain plan for each db query is only executed ever X seconds and there is also a max number of elements that are cached. To make sure we do not put to much strain on CPU or memory.
Usage:
If you then look at the
db
span in Sentry.io it looks like this: