getsentry / team-sdks

A meta repository for tracking work across all SDK teams.
0 stars 0 forks source link

Project Request: Query Source #40

Closed gggritso closed 6 months ago

gggritso commented 7 months ago

Description

People love the Starfish "Database" module, but everyone struggles to find the source of their SQL queries in their own codebase. We're hoping to attach the line of code that caused the query (AKA the "query source") to database spans. Laravel already does this, and it's invaluable! We'd love to see this in the Python and Ruby SDKs as well as a start.

The project document describes our idea in detail and addresses some likely objections. As a summary, here's what we're hoping for: For every query that takes longer than a threshold, attach the most recent in-app frame as a string property.

For example, with a threshold of 100ms, if a query takes 450ms, attach a property called code_source (name TBD) that shows where the query happened (e.g., /app/Http/Controllers/UserController.php:21)

We are open to suggestions and happy to contribute to the project in any way that is valuable!

### Tasks
- [x] Laravel (PoC) https://github.com/getsentry/sentry-laravel/pull/803
- [x] Python (PoC) https://github.com/getsentry/sentry-python/pull/2521

RFC

No response

Slack-Channel

discuss-starfish

Notion Document(s)

https://www.notion.so/sentry/Query-Source-c771873b972f4aac9504950f2f77741a?pvs=4

Stakeholder(s)

https://github.com/orgs/getsentry/teams/team-starfish

Team(s)

Web Backend

### Tasks
AbhiPrasad commented 7 months ago

The attributes should be named after the otel semantic conventions for code: https://opentelemetry.io/docs/specs/semconv/attributes-registry/code/

cleptric commented 7 months ago

@AbhiPrasad all of them? This would require some parsing logic, could we live with one combined attribute?

stephanie-anderson commented 7 months ago

@gggritso @sentrivana can have a look at this starting with next week - please reach out to her directly if you want to discuss anything sooner

AbhiPrasad commented 7 months ago

@AbhiPrasad all of them? This would require some parsing logic, could we live with one combined attribute?

Yeah a combined attribute is fine if we can't do the OTEL way in certain sdks/frameworks, we can even propose this upstream long term.

cleptric commented 7 months ago

We'll stick with Otel, WIP for Laravel at https://github.com/getsentry/sentry-laravel/pull/803

AbhiPrasad commented 6 months ago

It's shipped!

We'll open follow up issues for other SDKs in their respective repos - I'll also update develop to add query source as an expected feature of the sdks.