Skip to content

Conversation

@Vadman97
Copy link
Contributor

@Vadman97 Vadman97 commented Oct 17, 2025

Summary

Updates the Ruby OpenTelemetry tracing hook to comply with the latest OpenTelemetry semantic conventions specification for feature flag instrumentation. This brings the Ruby SDK in line with other LaunchDarkly SDKs (Java, Go, .NET).

Link to Devin run: https://app.devin.ai/sessions/00115de67e494cc999f5c247414cd9b1
Requested by: @Vadman97

Changes

Attribute Name Updates (Breaking for Observability Consumers)

  • feature_flag.context.keyfeature_flag.context.id
  • feature_flag.provider_namefeature_flag.provider.name
  • feature_flag.variantfeature_flag.result.value

New Configuration Options

  • include_value: Replaces deprecated include_variant option. Controls whether flag values are included in telemetry.
  • environment_id: Optional string parameter that adds feature_flag.set.id attribute. Validates non-empty strings and logs warnings for invalid input.

New Optional Attributes

  • feature_flag.result.reason.inExperiment: Set to true when evaluation is part of an experiment
  • feature_flag.result.variationIndex: Includes variation index when available

Backward Compatibility

  • include_variant option continues to work via fallback logic: opts.fetch(:include_value, opts.fetch(:include_variant, false))
  • Added test coverage for deprecated option to ensure backward compatibility

Bug Fixes

  • Fixed initialization order bug where validate_environment_id was called before @logger was initialized, causing NoMethodError on Ruby 3.0/3.1

Testing

  • All existing tests updated to use new attribute names
  • New test contexts added for:
    • include_value configuration
    • include_variant backward compatibility
    • environment_id configuration (valid and invalid cases)
    • inExperiment and variationIndex attributes
  • All CI checks passing on Ruby 3.0, 3.1, 3.2, jruby-9.4, and Windows

Review Checklist

Requirements

  • I have added test coverage for new or changed functionality
  • I have followed the repository's pull request submission guidelines
  • I have validated my changes against all supported platform versions

⚠️ Critical Review Items

  1. Test logic for inExperiment (line 221 in spec): The test "includes inExperiment when evaluation is part of experiment" verifies the attribute is NOT present (.to be false). Please verify this is correct behavior - is the test setup actually creating an experiment scenario, or is this testing the default case?

  2. Backward compatibility: Verify the nested fallback pattern opts.fetch(:include_value, opts.fetch(:include_variant, false)) works correctly for all combinations of options.

  3. Initialization order: The constructor now sets @logger before calling validate_environment_id. Verify this doesn't break any assumptions about initialization sequence.

  4. Environment validation: The environment_id validation only checks for non-empty strings. Confirm this matches the spec requirements (no format/character restrictions needed?).

Related Issues

Additional Context

  • Unable to run Rubocop locally due to missing Ruby development headers in environment. All lint verification was done via CI.
  • Changes are focused on the ruby-server-sdk-otel package; the main ruby-server-sdk package does not require updates.

- Rename feature_flag.context.key to feature_flag.context.id
- Fix feature_flag.provider_name to feature_flag.provider.name (add missing dot)
- Rename feature_flag.variant to feature_flag.result.value
- Add include_value configuration option (keep include_variant as deprecated)
- Add feature_flag.result.reason.inExperiment attribute
- Add feature_flag.result.variationIndex attribute
- Add feature_flag.set.id attribute with environment_id configuration support
- Update all tests to use new attribute names
- Add tests for new attributes

Follows OpenTelemetry semantic conventions specification:
https://raw.githubusercontent.com/launchdarkly/sdk-specs/refs/heads/main/specs/OTEL-openteletry-integration/README.md

Reference implementations:
- Go SDK: launchdarkly/go-server-sdk#292
- .NET SDK: launchdarkly/dotnet-core#148

Co-Authored-By: Vadim Korolik <[email protected]>
@devin-ai-integration
Copy link
Contributor

🤖 Devin AI Engineer

I'll be helping with this pull request! Here's what you should know:

✅ I will automatically:

  • Address comments on this PR. Add '(aside)' to your comment to have me ignore it.
  • Look at CI failures and help fix them

Note: I can only respond to comments from users who have write access to this repository.

⚙️ Control Options:

  • Disable automatic comment and CI monitoring

devin-ai-integration bot and others added 3 commits October 17, 2025 16:07
The validate_environment_id method needs @logger to be initialized
before it can log warnings about invalid environment_id values.
Fixed by reordering initialization in TracingHookOptions constructor.

Co-Authored-By: Vadim Korolik <[email protected]>
The environment_id and inExperiment/variationIndex test contexts
are nested inside 'with add_spans' and need 4-space indentation.

Co-Authored-By: Vadim Korolik <[email protected]>
Both environment_id and inExperiment contexts are nested inside
'with add_spans' context and need consistent 4-space indentation.
Also removed trailing whitespace from blank lines.

Co-Authored-By: Vadim Korolik <[email protected]>
@Vadman97 Vadman97 requested a review from a team October 17, 2025 16:21
@Vadman97 Vadman97 marked this pull request as ready for review October 17, 2025 16:55
@Vadman97 Vadman97 requested a review from a team as a code owner October 17, 2025 16:55
- Use inline private modifier for validate_environment_id
- Refactor to guarded return style for better readability

Co-Authored-By: Vadim Korolik <[email protected]>
@devin-ai-integration
Copy link
Contributor

Thanks for the code review @keelerm84! I've applied both style suggestions:

  1. ✅ Changed to inline private modifier: private def validate_environment_id(env_id)
  2. ✅ Refactored to guarded return style for better readability

All CI checks are passing with these changes.

@Vadman97 Vadman97 merged commit f58c6e3 into main Oct 17, 2025
7 checks passed
@Vadman97 Vadman97 deleted the devin/1760716742-update-semantic-conventions branch October 17, 2025 17:26
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