forked from open-telemetry/opentelemetry-ruby-contrib
-
Notifications
You must be signed in to change notification settings - Fork 0
feat: add FactoryBot instrumentation #5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
50aa9b6 to
f7c6748
Compare
2a87001 to
1d5a9fe
Compare
Adds OpenTelemetry instrumentation for FactoryBot gem via ActiveSupport::Notifications.
1d5a9fe to
6c404b2
Compare
andrejbl
reviewed
Oct 6, 2025
andrejbl
reviewed
Oct 6, 2025
andrejbl
approved these changes
Oct 6, 2025
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
Adds OpenTelemetry instrumentation for the FactoryBot gem to provide visibility into test data creation patterns.
Implementation Details
factory_bot.run_factoryeventscreate,build,build_stubbed,attributes_forcreate_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 usedfactory_bot.traits- Comma-separated list of traits applied (if any)Testing
Example Usage
Test plan
Notes
Upstream PR: open-telemetry#1721