Skip to content

Commit 2839dd0

Browse files
committed
Batch span attributes to reduce lock contention
Using add_attributes instead of two separate set_attribute calls reduces lock acquisition overhead, since each attribute update requires locking the span.
1 parent 2cd4633 commit 2839dd0

File tree

1 file changed

+4
-2
lines changed
  • instrumentation/rspec/lib/opentelemetry/instrumentation/rspec

1 file changed

+4
-2
lines changed

instrumentation/rspec/lib/opentelemetry/instrumentation/rspec/formatter.rb

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,10 @@ def example_finished(notification)
7474

7575
# Update name and full_description for one-liner examples where description is generated after execution
7676
span.name = example.description
77-
span.set_attribute('rspec.example.full_description', example.full_description.to_s)
78-
span.set_attribute('rspec.example.result', result.status.to_s)
77+
span.add_attributes(
78+
'rspec.example.full_description' => example.full_description.to_s,
79+
'rspec.example.result' => result.status.to_s
80+
)
7981

8082
add_exception_and_failures(span, result.exception)
8183
end

0 commit comments

Comments
 (0)