Skip to content

Implement OpenTelemetry instrumentation for Servactory call and action tracing#2

Merged
afuno merged 23 commits intomainfrom
feature/SRV-470/implementation
Feb 21, 2026
Merged

Implement OpenTelemetry instrumentation for Servactory call and action tracing#2
afuno merged 23 commits intomainfrom
feature/SRV-470/implementation

Conversation

@afuno
Copy link
Copy Markdown
Member

@afuno afuno commented Feb 20, 2026

No description provided.

**Summary of changes:**

- Implemented `Callable` patch to trace `call` and `call!` methods.
  - Traces span attributes (`code.namespace`, `code.function`, result statuses).
  - Handles success and failure states, including exceptions.
- Integrated result recording for spans, supporting both success and failure cases.
- Added methods to track input and output attribute names for spans.
- Developed unit tests in `callable_spec.rb`:
  - Validates span creation, attributes, and status for successful and failing services.
  - Confirms exception handling and span updates for unexpected errors.
**Summary of changes:**

- Introduced `Runner` patch to trace Servactory action executions.
  - Captures spans for Servactory service actions (`call_action`).
  - Records exceptions, updates span statuses, and ensures span completion.
- Added helper methods to create and manage spans:
  - `start_action_span` initializes spans with service names and attributes (`code.namespace`, `code.function`).
  - `tracer` retrieves the tracer instance for Servactory instrumentation.
**Summary of changes:**

- Introduced `compatible` block to validate minimum required Servactory version (`>= 2.16.0`).
- Added configuration options (`trace_actions`, `record_input_names`, `record_output_names`) with default values and validations.
- Implemented `present` block to check gem presence using `defined?`.
- Added dependency requirements for Callable and Runner patches.
- Introduced methods for patching (`patch_callable` and `patch_runner`), enabling instrumentation for Callable and Runner modules.
- Updated `install` block to conditionally apply patches based on configuration.
**Summary of changes:**

- Updated `call` and `call!` methods to use Ruby's `...` syntax for argument forwarding.
- Simplifies parameter handling while maintaining existing functionality.
- Preserves span creation and attribute building for OpenTelemetry instrumentation.
**Summary of changes:**

- Relaxed `opentelemetry-api` dependency to `~> 1.0` and `opentelemetry-instrumentation-base` to `~> 0.22` for broader compatibility.
- Added `opentelemetry-sdk` `~> 1.4` and `servactory` `>= 2.16.0` as development dependencies.
- Updated Ruby version to `3.4.8` in `.ruby-version` and `.tool-versions`.
- Refreshed `Gemfile.lock` to reflect updated dependencies including:
  - `activesupport` `8.1.2`, `json` `2.18.1`, and other minor version updates.
- Re-bundled with Bundler version `4.0.6`.
**Summary of changes:**

- Added `instrumentation_spec.rb` to validate the behavior of `OpenTelemetry::Instrumentation::Servactory::Instrumentation`:
  - Ensures the presence of name and version.
  - Validates default configurations (`trace_actions`, `record_input_names`, `record_output_names`).
  - Tests compatibility and Servactory presence detection.
- Introduced `support/fake_service.rb` with example services for testing:
  - `SuccessfulService`, `FailingService`, `MultiActionService`, and `ExceptionService`.
- Enhanced test coverage with executable service action validations and various edge-case scenarios.
**Summary of changes:**

- Added OpenTelemetry SDK setup with an in-memory span exporter.
- Configured RSpec to reset the exporter before each test run.
- Required supporting files under the `support` directory automatically.
- Set up OpenTelemetry instrumentation and error handling for Servactory.
**Summary of changes:**

- Renamed `fake_service.rb` to `example_services.rb` for improved naming clarity.
- Adjusted references to the renamed file in the support folder.
**Summary of changes:**

- Added unit tests for the `Runner` module in `runner_spec.rb`:
  - Verifies accurate span creation and attributes for multi-action services.
  - Validates exception handling and span updates when errors occur.
- Refactored `callable_spec.rb` for improved attribute validation:
  - Consolidated span verification using `subject` and helper variables.
  - Expanded tests to confirm span attributes, statuses, and exception handling.
- Simplified `instrumentation_spec.rb` by adopting one-liners for predicate checks.
- Updated `spec_helper.rb` to refine OpenTelemetry SDK initialization:
  - Improved readability by reordering configuration setup.
  - Streamlined file requiring and exporter setup.
@afuno afuno self-assigned this Feb 20, 2026
@afuno afuno added the feature label Feb 20, 2026
afuno added 14 commits February 21, 2026 00:32
**Summary of changes:**

- Updated `opentelemetry-sdk` development dependency from `~> 1.4` to `>= 1.4` in the gemspec.
- Synchronized the dependency update in `Gemfile.lock` for consistency.
- Ensures compatibility with future `opentelemetry-sdk` versions while maintaining minimum version requirements.
**Summary of changes:**

- Added a detailed description of the Servactory instrumentation, its purpose, and functionality.
- Documented installation instructions for RubyGems and Bundler.
- Introduced a new requirements section specifying required versions for Servactory (`>= 2.16.0`) and Ruby (`>= 3.2`).
- Expanded usage examples with configuration options (`trace_actions`, `record_input_names`, `record_output_names`).
- Explained the structure and attributes of spans, as well as failure event handling.
- Provided example span structures for better clarity on instrumentation behavior.
**Summary of changes:**

- Updated code examples in the README to use parentheses for method arguments, enhancing consistency and clarity.
- Reformatted multi-line `c.use` blocks for better alignment and visual structure.
**Summary of changes:**

- Updated `opentelemetry-api` dependency from `~> 1.0` to `>= 1.0`.
- Updated `opentelemetry-instrumentation-base` dependency from `~> 0.22` to `>= 0.22`.
- Synchronized changes in the `Gemfile.lock` file for consistency.
- Ensures better flexibility with future OpenTelemetry versions while retaining minimum compatibility.
**Summary of changes:**

- Updated `Runner` and `Callable` modules to include `servactory.system` and `servactory.version` attributes in spans.
- Extracted span attribute construction logic into dedicated methods for `build_action_attributes` and `build_span_attributes`.
- Updated test cases in `runner_spec.rb` and `callable_spec.rb` to validate new attributes.
- Extended README documentation to describe new span attributes (`servactory.system`, `servactory.version`).
- Rename 11 private methods in Patches::Callable to avoid
  namespace pollution on service class singletons
- Rename 3 private methods in Patches::Runner for consistency
- Public override methods (call, call!, call_action) unchanged
**Summary of changes:**

- Updated `opentelemetry-api` dependency from `>= 1.0` to `~> 1.0`.
- Updated `opentelemetry-instrumentation-base` dependency from `>= 0.22` to `~> 0.22`.
- Updated `opentelemetry-sdk` development dependency from `>= 1.4` to `~> 1.4`.
- Synchronized changes in `Gemfile.lock` for consistency.
- Applies stricter version constraints to improve dependency compatibility control.
**Summary of changes:**

- Updated `call` method in `Patches::Callable` to explicitly manage span lifecycle with `span.start`, `with_span`, and `span.finish`.
- Added exception handling to record errors on spans using `_otel_record_exception_on_span`.
- Enhanced error handling in `_otel_input_names` and `_otel_output_names` to log exceptions via `OpenTelemetry.handle_error`.
- Fixed potential nil reference issue in `Patches::Runner` by safely accessing `@context&.class&.name`.
- Improved resilience and traceability for Servactory instrumentation.
**Summary of changes:**

- Added tests for handling unexpected exceptions in `Patches::Callable`.
- Verified exception logging on spans using `exception` events.
- Ensured error results are set as `servactory.result` attribute in spans.
- Confirmed exceptions are re-raised after being recorded.
- Improved coverage for exception scenarios in Servactory instrumentation.
**Summary of changes:**

- Updated test assertions to use parentheses with boolean values for consistency (e.g., `to be(true)`).
- Modified expectations in `#compatible?` and `#install` spec blocks.
- Improved readability and alignment with testing conventions.
**Summary of changes:**
- Reformatted test expectations to improve multi-line readability.
- Introduced `let` variables (`root_span`, `step_one_span`, `exception_event`, etc.) for clearer span referencing.
- Applied consistent indentation and aggregate failures pattern across specs.
- Enhanced readability and maintainability for `Patches::Runner`, `Patches::Callable`, and general instrumentation tests.
**Summary of changes:**

- Deleted the addition of the `servactory.system` attribute from spans in `Patches::Callable` and `Patches::Runner`.
- Updated associated tests in `runner_spec.rb` and `callable_spec.rb` to reflect the removal of the attribute.
- Simplified span attribute setup by retaining only relevant attributes (`servactory.version`, etc.).
- Improved code and test clarity by eliminating redundant attributes.
**Summary of changes:**

- Deleted the `servactory.system` attribute from the spans table in the README.
- Updated documentation to reflect the attribute's removal for consistency with recent code changes.
@afuno afuno marked this pull request as ready for review February 21, 2026 11:19
@afuno afuno merged commit 63b9081 into main Feb 21, 2026
34 checks passed
@afuno afuno deleted the feature/SRV-470/implementation branch February 21, 2026 11:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant