Skip to content

Add OpenTelemetry Instrumenter with PII Filtering and Argument Tracking - #1

Merged
johngallagher merged 5 commits into
mainfrom
terragon/port-observable-instrumentation
Sep 6, 2025
Merged

Add OpenTelemetry Instrumenter with PII Filtering and Argument Tracking#1
johngallagher merged 5 commits into
mainfrom
terragon/port-observable-instrumentation

Conversation

@johngallagher

Copy link
Copy Markdown
Contributor

Summary

  • Introduces a new Observable::Instrumenter class for automated OpenTelemetry instrumentation of Ruby methods
  • Supports configurable serialization depth, PII filtering, and tracking of method arguments and return values
  • Adds comprehensive test coverage for instrumentation features
  • Provides example usage demonstrating instrumentation of instance and class methods
  • Updates gemspec with new dependencies and Ruby version requirement

Changes

Core Functionality

  • Added lib/observable/instrumenter.rb implementing the Instrumenter with:
    • Extraction of caller method and class information
    • Span creation with attributes for method name, namespace, file path, line number, arguments, and return values
    • PII filtering based on configurable regex patterns
    • Serialization of arguments and return values with depth limits
    • Exception capturing and span error status setting
  • Updated lib/observable.rb to expose a convenience method for creating an instrumenter instance

Configuration

  • Added Observable::Configuration using dry-configurable for:
    • Transport type, app namespace, attribute namespace
    • Tracer names and formatters
    • PII filters and max serialization depth
    • Option to track return values

Example and Tests

  • Added example.rb demonstrating configuration and usage of the instrumenter
  • Added test/instrumenter_test.rb with tests covering:
    • Instrumenter existence and basic instrumentation
    • Capturing method names and namespaces
    • Span creation and attribute verification
    • Argument capturing and return value tracking
    • Exception recording
    • Configuration overrides

Test Support

  • Added support classes for span and trace persistence and querying in test/support/persistence
  • Added test/support/tracing_test_helper.rb for OpenTelemetry test setup and span access
  • Updated test/test_helper.rb to configure OpenTelemetry SDK for tests

Miscellaneous

  • Updated observable.gemspec to:
    • Change summary and description to reflect new instrumentation features
    • Require Ruby >= 3.0.0
    • Add runtime dependencies on opentelemetry-sdk, dry-configurable, and dry-struct
    • Add development dependencies for testing and linting

Test plan

  • All new tests in test/instrumenter_test.rb pass successfully
  • Manual verification of example usage outputs and span creation
  • Confirmed PII filtering and argument serialization behavior
  • Verified exception capturing and span error status
  • Ensured configuration options apply correctly

This PR lays the foundation for robust OpenTelemetry instrumentation in Ruby applications with flexible configuration and strong test coverage.

🌿 Generated by Terry


ℹ️ Tag @terragon-labs to ask questions and address PR feedback

📎 Task: https://www.terragonlabs.com/task/ab86460c-5aff-431c-a974-508e612c6b26

… method instrumentation

- Introduce Observable::Instrumenter class with configuration support
- Automatically capture method name, namespace, arguments, and return values
- Support PII filtering and configurable serialization depth
- Create OpenTelemetry spans with error recording
- Add example usage demonstrating instrumentation
- Add comprehensive tests for instrumenter functionality
- Add persistence support classes for spans and traces
- Update gemspec with dependencies and metadata
- Add test helpers for OpenTelemetry span inspection
- Add example.rb demonstrating usage of the instrumenter

This feature enables automatic instrumentation of Ruby methods with OpenTelemetry, providing detailed tracing information including method arguments and return values, with privacy filtering and error tracking.

Co-authored-by: terragon-labs[bot] <terragon-labs[bot]@users.noreply.github.com>
@johngallagher
johngallagher marked this pull request as ready for review September 6, 2025 22:48
@johngallagher
johngallagher merged commit 98182fc into main Sep 6, 2025
1 check 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.

1 participant