Skip to content

Commit 8283d07

Browse files
Merge branch 'main' into http-semconv-span-names
2 parents 34a131a + e58ec51 commit 8283d07

File tree

3 files changed

+32
-1
lines changed

3 files changed

+32
-1
lines changed

.github/workflows/ossf-scorecard.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,6 @@ jobs:
4343
# Upload the results to GitHub's code scanning dashboard (optional).
4444
# Commenting out will disable upload of results to your repo's Code Scanning dashboard
4545
- name: "Upload to code-scanning"
46-
uses: github/codeql-action/upload-sarif@4e94bd11f71e507f7f87df81788dff88d1dacbfb # v4.31.0
46+
uses: github/codeql-action/upload-sarif@0499de31b99561a6d14a36a5f662c2a54f91beee # v4.31.2
4747
with:
4848
sarif_file: results.sarif

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ def example_group_finished(notification)
5858
def example_started(notification)
5959
example = notification.example
6060
attributes = {
61+
'rspec.example.id' => example.id.to_s,
6162
'rspec.example.location' => example.location.to_s,
6263
'rspec.example.full_description' => example.full_description.to_s,
6364
'rspec.example.described_class' => example.metadata[:described_class].to_s

instrumentation/rspec/test/opentelemetry/instrumentation/rspec/formatter_test.rb

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,10 @@ def run_example(...)
131131
_(subject.attributes['rspec.example.location']).must_match %r{\./test/opentelemetry/instrumentation/rspec/formatter_test.rb:\d+}
132132
end
133133

134+
it 'has an id attribute' do
135+
_(subject.attributes['rspec.example.id']).must_match %r{\./test/opentelemetry/instrumentation/rspec/formatter_test.rb\[\d+:\d+\]}
136+
end
137+
134138
it 'records when the example passes' do
135139
_(subject.attributes['rspec.example.result']).must_equal 'passed'
136140
end
@@ -326,6 +330,32 @@ def run_example(...)
326330
_(subject.events[1].attributes['exception.message']).must_equal 'another-error'
327331
end
328332
end
333+
334+
describe 'dynamic examples with same location' do
335+
it 'have unique example.id attributes' do
336+
spans = run_rspec_with_tracing do
337+
RSpec.describe('dynamic examples') do
338+
[1, 2, 3].each do |num|
339+
example("example #{num}") { expect(num).to be_positive }
340+
end
341+
end
342+
end
343+
344+
example_spans = spans.select { |span| span.name.start_with?('example ') }
345+
_(example_spans.size).must_equal 3
346+
347+
# All examples have the same location (same line in the loop)
348+
locations = example_spans.map { |span| span.attributes['rspec.example.location'] }
349+
_(locations.uniq.size).must_equal 1
350+
351+
# But each has a unique id
352+
ids = example_spans.map { |span| span.attributes['rspec.example.id'] }
353+
_(ids.uniq.size).must_equal 3
354+
ids.each do |id|
355+
_(id).must_match %r{\./test/opentelemetry/instrumentation/rspec/formatter_test.rb\[\d+:\d+\]}
356+
end
357+
end
358+
end
329359
end
330360

331361
describe 'using a custom tracer provider' do

0 commit comments

Comments
 (0)