Skip to content

Conversation

@americodls
Copy link
Contributor

@americodls americodls commented Oct 2, 2025

RSpec one-liner examples (e.g., it { is_expected.not_to be_nil }) generate descriptions after execution.

Updated formatter to capture the final description in example_finished instead of relying on the incomplete description at example_started.

RSpec one-liner examples (e.g., `it { is_expected.not_to be_nil }`)
generate descriptions after execution. Updated formatter to capture
the final description in `example_finished` instead of relying on
the incomplete description at `example_started`.
@linux-foundation-easycla
Copy link

linux-foundation-easycla bot commented Oct 2, 2025

CLA Signed

The committers listed above are authorized under a signed CLA.

@americodls americodls marked this pull request as ready for review October 2, 2025 12:03
@americodls americodls changed the title Fix RSpec one-liner example descriptions fix: Capture correct descriptions for RSpec one-liner examples Oct 2, 2025
americodls added a commit to intercom/opentelemetry-ruby-contrib that referenced this pull request Oct 2, 2025
## Why?

Span names and full descriptions for RSpec one-liner syntax (like `it {
is_expected.not_to be_nil }`) were incorrectly showing file locations
instead of the matcher-generated descriptions. This made tracing output
less useful for tests using the concise one-liner syntax.

## How?

RSpec generates descriptions for one-liner examples after execution,
when the matcher runs. The formatter was capturing `description` and
`full_description` at `example_started` time, before these values were
populated.

The fix updates both the span name and `full_description` attribute in
the `example_finished` callback, after RSpec has generated the proper
description from the matcher. This ensures accurate span names and
descriptions for both one-liner and traditional examples.

We need to point Intercom's Gemfile to this repo so that we get those
updates without waiting for the upstream repo to accept them.

---

**Note:** Upstream PR created at
open-telemetry#1712
Copy link
Contributor

@kaylareopelle kaylareopelle left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @americodls, thanks for catching this and providing a fix!

americodls added a commit to intercom/opentelemetry-ruby-contrib that referenced this pull request Oct 8, 2025
## Why?

Span names and full descriptions for RSpec one-liner syntax (like `it {
is_expected.not_to be_nil }`) were incorrectly showing file locations
instead of the matcher-generated descriptions. This made tracing output
less useful for tests using the concise one-liner syntax.

## How?

RSpec generates descriptions for one-liner examples after execution,
when the matcher runs. The formatter was capturing `description` and
`full_description` at `example_started` time, before these values were
populated.

The fix updates both the span name and `full_description` attribute in
the `example_finished` callback, after RSpec has generated the proper
description from the matcher. This ensures accurate span names and
descriptions for both one-liner and traditional examples.

We need to point Intercom's Gemfile to this repo so that we get those
updates without waiting for the upstream repo to accept them.

---

**Note:** Upstream PR created at
open-telemetry#1712
@arielvalentin
Copy link
Contributor

@chrisholmes may I ask for a review please?

@chrisholmes
Copy link
Contributor

@chrisholmes may I ask for a review please?

I'm away from computer so I can't test it myself, but the change is simple enough and it makes sense to me.

@arielvalentin
Copy link
Contributor

Please review at your leisure. With your approval I will merge this PR.

americodls added a commit to intercom/opentelemetry-ruby-contrib that referenced this pull request Oct 12, 2025
## Why?

Span names and full descriptions for RSpec one-liner syntax (like `it {
is_expected.not_to be_nil }`) were incorrectly showing file locations
instead of the matcher-generated descriptions. This made tracing output
less useful for tests using the concise one-liner syntax.

## How?

RSpec generates descriptions for one-liner examples after execution,
when the matcher runs. The formatter was capturing `description` and
`full_description` at `example_started` time, before these values were
populated.

The fix updates both the span name and `full_description` attribute in
the `example_finished` callback, after RSpec has generated the proper
description from the matcher. This ensures accurate span names and
descriptions for both one-liner and traditional examples.

We need to point Intercom's Gemfile to this repo so that we get those
updates without waiting for the upstream repo to accept them.

---

**Note:** Upstream PR created at
open-telemetry#1712
americodls added a commit to intercom/opentelemetry-ruby-contrib that referenced this pull request Oct 14, 2025
## Why?

Span names and full descriptions for RSpec one-liner syntax (like `it {
is_expected.not_to be_nil }`) were incorrectly showing file locations
instead of the matcher-generated descriptions. This made tracing output
less useful for tests using the concise one-liner syntax.

## How?

RSpec generates descriptions for one-liner examples after execution,
when the matcher runs. The formatter was capturing `description` and
`full_description` at `example_started` time, before these values were
populated.

The fix updates both the span name and `full_description` attribute in
the `example_finished` callback, after RSpec has generated the proper
description from the matcher. This ensures accurate span names and
descriptions for both one-liner and traditional examples.

We need to point Intercom's Gemfile to this repo so that we get those
updates without waiting for the upstream repo to accept them.

---

**Note:** Upstream PR created at
open-telemetry#1712

# Update name and full_description for one-liner examples where description is generated after execution
span.name = example.description
span.set_attribute('rspec.example.full_description', example.full_description.to_s)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💁🏼 Use add_attributes as opposed to setting each attribute separately because each call requires a lock when changing a span

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great catch. I agree. @americodls, can you update the method call to combine the attributes on line 76 and 77 into one add_attributes call?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for the feedback. I just fixed that.

Using add_attributes instead of two separate set_attribute calls
reduces lock acquisition overhead, since each attribute update requires
locking the span.
@arielvalentin arielvalentin merged commit 1cfaeb4 into open-telemetry:main Nov 3, 2025
35 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants