Skip to content

Support for cross thread span tracing (e.g. via concurrent-ruby) #415

Closed

Description

We have a few places in our application with multiple independent slow ActiveRecord queries that we use concurrent-ruby's Concurrent::Future class to parallelize, then block on the combined results. Here's some pseudo-code

scope = MyModel.slow_sql_query
# Start both queries in parallel
future_a_1 = Concurrent::Future.execute { scope.where(a: 1).to_a }
future_a_2 = Concurrent::Future.execute { scope.where(a: 2).to_a } 
# Blocks, ensuring we don't attempt to render before the queries are complete
@a_1 = future_a_1.value
@a_2 = future_a_2.value
render :show

To my surprise, the traces of the queries executed in the Future don't appear in DD. I'm assuming this has something to do with the trace ID being stored in Thread.current, or the Future threads in some other way being unaware of the trace ID.

What can I do to ensure these query spans are included in my trace?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

Labels

communityWas opened by a community memberquestionGeneral inquiry that may or may not involve changes

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions