Skip to content

Instrument without a block? #541

@rmosolgo

Description

@rmosolgo

Hi! I'm working on improving the Scout integration for GraphQL-Ruby. My library sometimes spins up new Fibers, runs them for a while, then pauses them ... then resumes them again. I'd like a way to report the duration while the Fiber is running, but not while it's paused. I think the best approach here is to make two separate spans: one before the pause and one after it.

However, the catch is, the library doesn't know when (or where in the code) the Fiber will be paused. I can't wrap the before-part in a do ... end block -- instead, code runs ... then eventually it may yield. So I'm looking for a way to start a new span, then manually finish it when I observe that Fiber pause. Is there a supported way to do this?

For now, I'm going to use the internal implementation from .implement:

def self.instrument(type, name, options={}) # Takes a block
layer = ScoutApm::Layer.new(type, name)
layer.desc = options[:desc] if options[:desc]
layer.subscopable! if options[:scope]
req = ScoutApm::RequestManager.lookup
req.start_layer(layer)
req.ignore_children! if options[:ignore_children]
begin
yield
ensure
req.acknowledge_children! if options[:ignore_children]
req.stop_layer
end
end

Basically I'll separate those two parts -- before yield and after it -- and call them as needed. But if there's a better way, I'd like to use it! Thanks.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions