Skip to content

Conversation

@americodls
Copy link

@americodls americodls commented Oct 3, 2025

Summary

Adds OpenTelemetry instrumentation for the FactoryBot gem to provide visibility into test data creation patterns.

Implementation Details

  • Uses ActiveSupport::Notifications to subscribe to factory_bot.run_factory events
  • No monkey-patching required - leverages FactoryBot's built-in notification hooks
  • Captures all strategies: create, build, build_stubbed, attributes_for
  • Automatically handles batch operations: create_list, build_list, build_pair, etc.

Span Attributes

  • factory_bot.strategy - Internal strategy name (create, build, stub, attributes_for)
  • factory_bot.factory_name - Name of the factory being used
  • factory_bot.traits - Comma-separated list of traits applied (if any)

Testing

  • 17 tests, 22 assertions, all passing
  • 95% code coverage
  • Tests against FactoryBot versions 4.x, 5.x, and 6.x via Appraisals

Example Usage

OpenTelemetry::SDK.configure do |c|
  c.use 'OpenTelemetry::Instrumentation::FactoryBot'
end

FactoryBot.build(:user)  # Creates span: "FactoryBot.build(user)"

Test plan

  • All tests pass locally
  • CI tests pass
  • Integration test with Intercom monolith (It works, PR will come after merging this one)

Notes

  • Once approved I'll
  • Create a PR to add this to the monolith's Gemfile (which was already tested using this branch)
  • Send a PR to the upstream repo

Upstream PR: open-telemetry#1721

@americodls americodls force-pushed the ad/add-factorybot-instrumentation-fork branch 3 times, most recently from 50aa9b6 to f7c6748 Compare October 3, 2025 16:23
@americodls americodls changed the title Add FactoryBot OpenTelemetry instrumentation feat: add FactoryBot instrumentation Oct 3, 2025
@americodls americodls force-pushed the ad/add-factorybot-instrumentation-fork branch 3 times, most recently from 2a87001 to 1d5a9fe Compare October 3, 2025 17:22
Adds OpenTelemetry instrumentation for FactoryBot gem via ActiveSupport::Notifications.
@americodls americodls force-pushed the ad/add-factorybot-instrumentation-fork branch from 1d5a9fe to 6c404b2 Compare October 3, 2025 17:24
@americodls americodls requested a review from andrejbl October 6, 2025 09:18
@americodls americodls merged commit 74b69a5 into main Oct 6, 2025
71 checks passed
@americodls americodls deleted the ad/add-factorybot-instrumentation-fork branch October 6, 2025 09:41
americodls added a commit that referenced this pull request Oct 8, 2025
## Summary

Adds OpenTelemetry instrumentation for the FactoryBot gem to provide
visibility into test data creation patterns.

## Implementation Details

- Uses ActiveSupport::Notifications to subscribe to
`factory_bot.run_factory` events
- No monkey-patching required - leverages FactoryBot's built-in
notification hooks
- Captures all strategies: `create`, `build`, `build_stubbed`,
`attributes_for`
- Automatically handles batch operations: `create_list`, `build_list`,
`build_pair`, etc.

## Span Attributes

- `factory_bot.strategy` - Internal strategy name (create, build, stub,
attributes_for)
- `factory_bot.factory_name` - Name of the factory being used
- `factory_bot.traits` - Comma-separated list of traits applied (if any)

## Testing

- 17 tests, 22 assertions, all passing
- 95% code coverage
- Tests against FactoryBot versions 4.x, 5.x, and 6.x via Appraisals

## Example Usage

```ruby
OpenTelemetry::SDK.configure do |c|
  c.use 'OpenTelemetry::Instrumentation::FactoryBot'
end

FactoryBot.build(:user)  # Creates span: "FactoryBot.build(user)"
```

## Test plan

- [x] All tests pass locally
- [x] CI tests pass
- [x] Integration test with Intercom monolith (It works, PR will come
after merging this one)

## Notes

- Once approved I'll
- Create a PR to add this to the monolith's Gemfile (which was already
tested using this branch)
- Send a PR to the upstream repo
americodls added a commit that referenced this pull request Oct 12, 2025
## Summary

Adds OpenTelemetry instrumentation for the FactoryBot gem to provide
visibility into test data creation patterns.

## Implementation Details

- Uses ActiveSupport::Notifications to subscribe to
`factory_bot.run_factory` events
- No monkey-patching required - leverages FactoryBot's built-in
notification hooks
- Captures all strategies: `create`, `build`, `build_stubbed`,
`attributes_for`
- Automatically handles batch operations: `create_list`, `build_list`,
`build_pair`, etc.

## Span Attributes

- `factory_bot.strategy` - Internal strategy name (create, build, stub,
attributes_for)
- `factory_bot.factory_name` - Name of the factory being used
- `factory_bot.traits` - Comma-separated list of traits applied (if any)

## Testing

- 17 tests, 22 assertions, all passing
- 95% code coverage
- Tests against FactoryBot versions 4.x, 5.x, and 6.x via Appraisals

## Example Usage

```ruby
OpenTelemetry::SDK.configure do |c|
  c.use 'OpenTelemetry::Instrumentation::FactoryBot'
end

FactoryBot.build(:user)  # Creates span: "FactoryBot.build(user)"
```

## Test plan

- [x] All tests pass locally
- [x] CI tests pass
- [x] Integration test with Intercom monolith (It works, PR will come
after merging this one)

## Notes

- Once approved I'll
- Create a PR to add this to the monolith's Gemfile (which was already
tested using this branch)
- Send a PR to the upstream repo
americodls added a commit that referenced this pull request Oct 14, 2025
## Summary

Adds OpenTelemetry instrumentation for the FactoryBot gem to provide
visibility into test data creation patterns.

## Implementation Details

- Uses ActiveSupport::Notifications to subscribe to
`factory_bot.run_factory` events
- No monkey-patching required - leverages FactoryBot's built-in
notification hooks
- Captures all strategies: `create`, `build`, `build_stubbed`,
`attributes_for`
- Automatically handles batch operations: `create_list`, `build_list`,
`build_pair`, etc.

## Span Attributes

- `factory_bot.strategy` - Internal strategy name (create, build, stub,
attributes_for)
- `factory_bot.factory_name` - Name of the factory being used
- `factory_bot.traits` - Comma-separated list of traits applied (if any)

## Testing

- 17 tests, 22 assertions, all passing
- 95% code coverage
- Tests against FactoryBot versions 4.x, 5.x, and 6.x via Appraisals

## Example Usage

```ruby
OpenTelemetry::SDK.configure do |c|
  c.use 'OpenTelemetry::Instrumentation::FactoryBot'
end

FactoryBot.build(:user)  # Creates span: "FactoryBot.build(user)"
```

## Test plan

- [x] All tests pass locally
- [x] CI tests pass
- [x] Integration test with Intercom monolith (It works, PR will come
after merging this one)

## Notes

- Once approved I'll
- Create a PR to add this to the monolith's Gemfile (which was already
tested using this branch)
- Send a PR to the upstream repo
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.

3 participants