-
Notifications
You must be signed in to change notification settings - Fork 599
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
Add fiber instrumentation #1802
Conversation
always uses correct state
Co-authored-by: James Bunch <fallwith@gmail.com>
Co-authored-by: James Bunch <fallwith@gmail.com>
Co-authored-by: James Bunch <fallwith@gmail.com>
Co-authored-by: James Bunch <fallwith@gmail.com>
Co-authored-by: James Bunch <fallwith@gmail.com>
def thread_block_with_current_transaction(*args, segment_name:, parent: nil, &block) | ||
parent ||= current_segment | ||
current_txn = ::Thread.current[:newrelic_tracer_state].current_transaction if ::Thread.current[:newrelic_tracer_state] && ::Thread.current[:newrelic_tracer_state].is_execution_traced? | ||
current_txn = ::Thread.current[:newrelic_tracer_state]&.current_transaction if ::Thread.current[:newrelic_tracer_state]&.is_execution_traced? |
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.
nice use of >2.3 syntax 😎
SimpleCov Report
|
@@ -410,9 +410,17 @@ def clear_state | |||
|
|||
alias_method :tl_clear, :clear_state | |||
|
|||
def current_segment_key | |||
::Fiber.current.object_id |
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.
Using the fiber id instead of the thread id (which is what we did before), still totally works with threads, because every new thread is a new fiber as well, but it also allows us to accurately track multiple fibers that exist inside of a single thread.
@@ -260,20 +257,26 @@ def initialize(category, options) | |||
end | |||
end | |||
|
|||
def parent_thread_id | |||
::Thread.current.nr_parent_thread_id if ::Thread.current.respond_to?(:nr_parent_thread_id) | |||
def state |
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.
This just makes sense the transaction is always using the correct state object. we were storing the state on the transaction originally, which wasn't causing any issues, but this is just a preemptive safety change for just in case situations.
Adds instrumentation to the Fiber class.
This will allow the agent to treat fibers the same way it is currently treating threads, making it possible to automatically record spans created inside of fibers and will create a fiber spans.
This will share the
instrumentation.thread.tracing
config to control whether the current transaction is carried over to the new fiber. It made more sense to use the same config as threads for this behavior, since there isn't any reason only one would need to be disabled.closes #1756