Skip to content

fix: structured stacktrace capture in Ruby observability plugin#427

Merged
ccschmitz-launchdarkly merged 8 commits intomainfrom
ccschmitz/ruby-o11y-plugin-improvements
Mar 26, 2026
Merged

fix: structured stacktrace capture in Ruby observability plugin#427
ccschmitz-launchdarkly merged 8 commits intomainfrom
ccschmitz/ruby-o11y-plugin-improvements

Conversation

@ccschmitz-launchdarkly
Copy link
Contributor

@ccschmitz-launchdarkly ccschmitz-launchdarkly commented Mar 23, 2026

Summary

Improve the Ruby observability plugin in two areas:

  • Structured stacktraces on exceptions: Both the Rack Middleware and the Rails record_launchdarkly_exception helper now attach an exception.structured_stacktrace JSON attribute (via SourceContext.build_structured_stacktrace) when recording exceptions on spans. This enables richer error display in the observability UI.
  • Standalone logger for non-Rails apps: New LaunchDarklyObservability.logger module method returns an OtelLogBridge that writes to both a local IO (e.g. $stdout) and the OTel Logs pipeline with trace/span correlation. Falls back to a plain Logger if the OTel logger provider isn't available yet. The OtelLogBridge now accepts an optional io: parameter and propagates level/formatter changes to the local logger.

The Sinatra demo app is updated to use the new logger, and the demo Gemfile.lock picks up the OpenTelemetry log exporter/SDK dependencies.

How did you test this change?

  • Added unit tests for LaunchDarklyObservability.logger covering OTel bridge return, plain Logger fallback, and IO output verification (module_methods_test.rb)
  • Added unit tests for OtelLogBridge dual-output mode covering IO + OTel emission, OTel-only mode, level propagation, and hash message handling (otel_log_bridge_test.rb)

Are there any deployment considerations?

None. These are additive changes to the Ruby gem with no breaking API changes.


Note

Low Risk
Low risk: changes are additive and primarily enrich telemetry (extra exception attributes and optional dual-output logging) without altering core SDK behavior or request handling flow.

Overview
Adds a new LaunchDarklyObservability.logger helper for non-Rails apps that returns an OtelLogBridge capable of writing to a local IO (e.g. $stdout) and exporting OTLP log records with trace/span correlation, falling back to a plain Logger if the OTel logger provider isn’t ready.

Improves exception telemetry by consistently attaching a JSON exception.structured_stacktrace attribute when recording exceptions (module record_exception, Rack Middleware, and Rails record_launchdarkly_exception) via a new SourceContext.exception_attributes helper, and expands tests/docs/demo app accordingly (including adding OTLP logs dependencies in the Sinatra demo lockfile).

Written by Cursor Bugbot for commit d345ed5. This will update automatically on new commits. Configure here.

@ccschmitz-launchdarkly ccschmitz-launchdarkly requested a review from a team as a code owner March 23, 2026 15:09
@ccschmitz-launchdarkly ccschmitz-launchdarkly changed the title Fix structured stacktrace capture in Ruby observability plugin fix: structured stacktrace capture in Ruby observability plugin Mar 23, 2026
@ccschmitz-launchdarkly ccschmitz-launchdarkly enabled auto-merge (squash) March 23, 2026 15:21
…tput

Expose `LaunchDarklyObservability.logger` so Sinatra, Grape, and plain
Ruby applications get a logger that writes to a local IO (e.g. $stdout)
and exports every entry as an OTLP LogRecord with trace/span correlation.

The OtelLogBridge now accepts an optional `io:` parameter to support this
dual-output mode while preserving the existing broadcast-only behavior
used by the Rails integration.
Copy link
Contributor

@SpennyNDaJets SpennyNDaJets left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code makes sense to me!

Copy link

@cursor cursor bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, have a team admin enable autofix in the Cursor dashboard.

@ccschmitz-launchdarkly ccschmitz-launchdarkly merged commit 1dae61e into main Mar 26, 2026
22 checks passed
@ccschmitz-launchdarkly ccschmitz-launchdarkly deleted the ccschmitz/ruby-o11y-plugin-improvements branch March 26, 2026 21:33
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.

2 participants