Skip to content

Commit

Permalink
Fix nested_call edge case (#488)
Browse files Browse the repository at this point in the history
  • Loading branch information
kxmbrian committed Feb 5, 2024
1 parent a124643 commit 3b802ec
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 5 deletions.
2 changes: 1 addition & 1 deletion lib/scout_apm/auto_instrument/rails.rb
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ def on_hash(node)
key_node, value_node = pair.children
next unless key_node.type == :sym && value_node.type == :send
key = key_node.children[0]
next unless value_node.children[0].nil? && key == value_node.children[1]
next unless value_node.children.size == 2 && value_node.children[0].nil? && key == value_node.children[1]

# Extract useful metadata for instrumentation:
line = pair.location.line || 'line?'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,18 @@ def hash
non_nil_receiver: ::ScoutApm::AutoInstrument("non_nil_receiver.value",["ROOT/test/unit/auto_instrument/hash_shorthand_controller.rb:11:in `hash'"]){non_nil_receiver.value},
nested: {
shorthand: ::ScoutApm::AutoInstrument("shorthand:",["ROOT/test/unit/auto_instrument/hash_shorthand_controller.rb:13:in `hash'"]){shorthand},
}
},
nested_call: ::ScoutApm::AutoInstrument("nested_call(params[\"timestamp\"])",["ROOT/test/unit/auto_instrument/hash_shorthand_controller.rb:15:in `hash'"]){nested_call(params["timestamp"])}
}
::ScoutApm::AutoInstrument("render json:",["ROOT/test/unit/auto_instrument/hash_shorthand_controller.rb:16:in `hash'"]){render json:}
::ScoutApm::AutoInstrument("render json:",["ROOT/test/unit/auto_instrument/hash_shorthand_controller.rb:17:in `hash'"]){render json:}
end

private

def nested_call(noop)
noop
end

def shorthand
"shorthand"
end
Expand All @@ -31,6 +36,6 @@ def hash_rocket
end

def non_nil_receiver
::ScoutApm::AutoInstrument("OpenStruct.new(value: \"value\")",["ROOT/test/unit/auto_instrument/hash_shorthand_controller.rb:34:in `non_nil_receiver'"]){OpenStruct.new(value: "value")}
::ScoutApm::AutoInstrument("OpenStruct.new(value: \"value\")",["ROOT/test/unit/auto_instrument/hash_shorthand_controller.rb:39:in `non_nil_receiver'"]){OpenStruct.new(value: "value")}
end
end
7 changes: 6 additions & 1 deletion test/unit/auto_instrument/hash_shorthand_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,18 @@ def hash
non_nil_receiver: non_nil_receiver.value,
nested: {
shorthand:,
}
},
nested_call: nested_call(params["timestamp"])
}
render json:
end

private

def nested_call(noop)
noop
end

def shorthand
"shorthand"
end
Expand Down

0 comments on commit 3b802ec

Please sign in to comment.