Skip to content

Commit

Permalink
fix: Reduce Hash Allocations in PG Instrumentation (#232)
Browse files Browse the repository at this point in the history
* chore: enable Style/CollectionCompact

* chore: Minimize object allocation

This change removes allocation of 2 additional hashes per PG SQL span.
  • Loading branch information
arielvalentin authored Jan 14, 2023
1 parent 5aabcf2 commit 53a5b26
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
2 changes: 0 additions & 2 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -55,5 +55,3 @@ Layout/LineLength:
Max: 250
Lint/RedundantRequireStatement:
Enabled: false
Style/CollectionCompact:
Enabled: false
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ def span_attrs(kind, *args)
attrs = { 'db.operation' => validated_operation(operation), 'db.postgresql.prepared_statement_name' => statement_name }
attrs['db.statement'] = sql unless config[:db_statement] == :omit
attrs.merge!(OpenTelemetry::Instrumentation::PG.attributes)
attrs.reject! { |_, v| v.nil? }
attrs.compact!

[span_name(operation), client_attributes.merge(attrs)]
end
Expand Down Expand Up @@ -131,7 +131,9 @@ def client_attributes
}
attributes['peer.service'] = config[:peer_service] if config[:peer_service]

attributes.merge(transport_attrs).reject { |_, v| v.nil? }
attributes.merge!(transport_attrs)
attributes.compact!
attributes
end

def transport_addr
Expand Down

0 comments on commit 53a5b26

Please sign in to comment.