Conversation
Co-authored-by: Moritz Lang <16192401+slashmo@users.noreply.github.com>
|
@ptoffy How do you expect this to look like once database drivers like |
|
@slashmo Yes my idea is to create child spans in the underlying drivers but that might still be a while off since I'm pretty sure those are all event loop based (see https://github.com/vapor/fluent-postgres-driver). Maybe @gwynne has some insight into this. |
I'm all for following the spec. However, there isn't one for ORMs, only for db drivers. So if we'd follow the DB driver conventions here we'd have duplicate spans between Fluent and the drivers. Gorm is just one example ORM where I found built-in tracing support, and they don't follow the DB driver conventions. |
|
@slashmo what do you think about emitting driver-agnostic traces (like the ones that are in the PR now) in fluent-kit and leaving db-specific traces up to the drivers to implement? The drivers rely on fluent-kit anyway so you'll always have both. The only pain about this approach I can think of is keeping track of which ones are where, but we can just decide it upfront |
|
|
||
| func withTracing<T>(_ closure: () async throws -> T) async rethrows -> T { | ||
| if shouldTrace { | ||
| try await withSpan("db.query", context: self.serviceContext, ofKind: .client) { span in |
There was a problem hiding this comment.
Depending on how strict observability backends are about the semantic conventions I could see this being a problem. For example, if they look for certain required attributes that we don't supply here I could imagine it breaking their visualization of database spans. I think I'd slightly be in favor of using non-spec operation name and attributes for FluentKit spans for that reason. I also think it shouldn't be up to the Vapor DB drivers to add spans but the underlying database libraries agnostic from Vapor, like postgres-nio. This way we'd also benefit from these spans in apps not using Vapor.
There was a problem hiding this comment.
While I do agree and did update the attributes to use fluent specific names, I did notice that gorm also uses the semantic conventions' attributes, here for example https://github.com/go-gorm/opentelemetry/blob/master/tracing/tracing.go#L264-L278. Anyway let me know what you think of the current ones
There was a problem hiding this comment.
Can we add more tests for:
- getting relations
- queries on relations
- first
- min
- plain aggregate call
- raw query
There was a problem hiding this comment.
Raw query is not currently traced since that requires tracing in SQLKit and/or in DBMS specific underlying -Kit library
There was a problem hiding this comment.
Ah yeah fair enough, we should look at adopting that after this, especially with PostgresNIO and see if we can migrate to the new Postgres stuff
There was a problem hiding this comment.
Migrating to PostgresClient is severely problematic because it's not really compatible with an ELF-based interface. One of the bigger issues is that it would require specific support in the fluent package to hook into the Application lifecycle, since in Vapor 4 there's no expectation of a ServiceGroup to attach a PostgresClient to. Except that such logic should really live in fluent-postgres-driver, but it can't because that's independent of Vapor. And so on. There are other issues also. It's not necesarily insurmountable, but my general mode of thought has been "let's just do pooling correctly in Fluent 5 and people who need PostgresClient in the meantime can use it with PostgresKit" (since PostgresKit now includes instructions for using it to replace the AsyncKit pooling; it's just that those instructions don't map onto something the FluentKit layer can do).
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #645 +/- ##
==========================================
+ Coverage 25.83% 26.48% +0.64%
==========================================
Files 148 148
Lines 8852 8869 +17
==========================================
+ Hits 2287 2349 +62
+ Misses 6565 6520 -45
🚀 New features to boost your workflow:
|
|
PS looks like the tests will need to be wrapped in a 6.1 check since traits aren't supported in 6.0 |
gwynne
left a comment
There was a problem hiding this comment.
One very tiny nit, otherwise lgtm.
These changes are now available in 1.55.0
This adopts tracing on
DatabaseQuery, only usingasync/awaitinterfaces and not on raw/sql-kit queries as those require tracing support in SQLKit or lower level packages like PostgresKit or MySQLNIO.This relies on #647