Skip to content
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

Merged
merged 18 commits into from
Feb 8, 2023
Merged

Conversation

tannalynn
Copy link
Contributor

@tannalynn tannalynn commented Feb 7, 2023

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

@tannalynn tannalynn changed the base branch from dev to major-release-9 February 7, 2023 21:23
@tannalynn tannalynn marked this pull request as ready for review February 8, 2023 00:30
CHANGELOG.md Outdated Show resolved Hide resolved
lib/new_relic/agent/configuration/default_source.rb Outdated Show resolved Hide resolved
lib/new_relic/agent/instrumentation/fiber.rb Outdated Show resolved Hide resolved
newrelic.yml Outdated Show resolved Hide resolved
test/multiverse/suites/thread/Envfile Outdated Show resolved Hide resolved
tannalynn and others added 5 commits February 7, 2023 16:43
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?
Copy link
Contributor

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 😎

@github-actions
Copy link
Contributor

github-actions bot commented Feb 8, 2023

SimpleCov Report

Coverage Threshold
Line 93.94% 93%
Branch 85.37% 84%

@@ -410,9 +410,17 @@ def clear_state

alias_method :tl_clear, :clear_state

def current_segment_key
::Fiber.current.object_id
Copy link
Contributor Author

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
Copy link
Contributor Author

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.

@tannalynn tannalynn merged commit 137ecce into major-release-9 Feb 8, 2023
@tannalynn tannalynn deleted the add_fiber_instrumentation branch June 23, 2023 19:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants