You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hello 👋 I've stumbled upon a behavior that may be not a bug per se but was a bit unexpected, at least for me. I'd like to instrument my Vapor application for OpenTelemetry (in accordance with https://github.com/apple/swift-distributed-tracing) and for that reason wanted to create a new OT span for each database query. My approach was to decorate Fluent's Database:
I could then do e.g. let myTracedDatabase = TracedDatabase(application.db) and use it as usual.
However, when performing MyModel.query(on: myTracedDatabase).with(.\$someParent).all() I could observe that:
the first database query's span got properly attached to the same trace as request's root span,
each of the following queries for MyModel's parents (.someParent in this case) got its own, new trace.
As I said before, this might be an expected behavior which would be fine too – it's easy enough to work around this by storing the context object beforehand and passing it to startSpan explicitly.
Describe the bug
Hello 👋 I've stumbled upon a behavior that may be not a bug per se but was a bit unexpected, at least for me. I'd like to instrument my Vapor application for OpenTelemetry (in accordance with https://github.com/apple/swift-distributed-tracing) and for that reason wanted to create a new OT span for each database query. My approach was to decorate Fluent's
Database
:I could then do e.g.
let myTracedDatabase = TracedDatabase(application.db)
and use it as usual.However, when performing
MyModel.query(on: myTracedDatabase).with(.\$someParent).all()
I could observe that:MyModel
's parents (.someParent
in this case) got its own, new trace.In other words, looking at https://github.com/apple/swift-distributed-tracing/blob/61c272fe72c9728c85952f0c6170cf491ac61dc0/Sources/Tracing/Tracer.swift#L47: parent model queries are executed with a different service context (so within separate tasks?) than the initial one.
As I said before, this might be an expected behavior which would be fine too – it's easy enough to work around this by storing the context object beforehand and passing it to
startSpan
explicitly.To Reproduce
ModelA
with a parent model.modelB: ModelB
,await ModelA.query(on: TracedDatabase(req.db)).with(\.$modelB).all()
, inspect the output.Expected behavior
The same service context object is printed twice.
Environment
swift:5.9
Docker imageThe app is running with PostgreSQL 16 database, with
fluent-postgres-driver
version 2.8.0.Additional context
Add any other context about the problem here.
The text was updated successfully, but these errors were encountered: