Skip to content

fix: Handle missing config in middleware when OTEL_SDK_DISABLED=true#2231

Open
hannahramadan wants to merge 4 commits intoopen-telemetry:mainfrom
hannahramadan:rack_handle_unconfiged_middleware
Open

fix: Handle missing config in middleware when OTEL_SDK_DISABLED=true#2231
hannahramadan wants to merge 4 commits intoopen-telemetry:mainfrom
hannahramadan:rack_handle_unconfiged_middleware

Conversation

@hannahramadan
Copy link
Copy Markdown
Member

@hannahramadan hannahramadan commented Apr 14, 2026

When OTEL_SDK_DISABLED=true, the SDK skips configuration and Rack instrumentation's config is an empty hash. When attempting to access nil values, a NoMethodError was raised. This same issue seemed to exist in at least excon, grpc, and gruf.

We now initialize config with defaults in the base class ensure config always has valid default values, whether or not install() was called.

This is slightly redundant since @config gets overwritten in the install method, the first is a "just in case" install() is never called.

closes #2230

@hannahramadan hannahramadan changed the title fix: Handle unconfigured middleware when OTEL_SDK_DISABLED=true fix: Handle missing config in middleware when OTEL_SDK_DISABLED=true Apr 14, 2026
@arielvalentin
Copy link
Copy Markdown
Contributor

arielvalentin commented Apr 15, 2026

@hannahramadan is this not something that should be handled in Base?

Also, any chance that you could add some test coverage for this?

arielvalentin
arielvalentin previously approved these changes Apr 15, 2026
@hannahramadan
Copy link
Copy Markdown
Member Author

@hannahramadan is this not something that should be handled in Base?

Also, any chance that you could add some test coverage for this?

Base could make sense because it looks like this same issue could occur in a few other instrumentations. So we'd either need the Array() approach in a few additional spots or add it to Base, which fixes all cases and safe guards this issue in the future. I'll look into this.

@hannahramadan hannahramadan marked this pull request as draft April 15, 2026 16:37

def call(type:, requests: nil, call: nil, method: nil, metadata: nil)
return yield if instrumentation_config.empty?
return yield unless Grpc::Instrumentation.instance.installed?
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

This check to see if instrumentation was installed, along with the checks in gruf/interceptors/client and gruf/interceptors/server aren't technically equivalent to the previous behavior of checking if the configs were empty.

Is installed? the right check here, or should we handle this differently? I'm unsure about the original intent of using an config empty vs installed to guard.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

@AS-AlStar would you mind sharing more information about your intent here?

@hannahramadan hannahramadan marked this pull request as ready for review April 17, 2026 17:52
@config = {}
@installed = false
@options = options
@config = config_options({})
Copy link
Copy Markdown
Member Author

@hannahramadan hannahramadan Apr 17, 2026

Choose a reason for hiding this comment

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

As this is a change to base, I would love some extra eyes here. I noted one downstream impact of checking for empty configs not really being able to exist anymore, since now they wont ever really be.

@thompson-tomo thompson-tomo dismissed arielvalentin’s stale review April 17, 2026 18:13

Original solution which was approved has been reverted and different solution implemented affecting different set of gems.

@arielvalentin
Copy link
Copy Markdown
Contributor

@hannahramadan
Copy link
Copy Markdown
Member Author

@hannahramadan why not check the envar here? https://github.com/open-telemetry/opentelemetry-ruby-contrib/blob/main/instrumentation/base/lib/opentelemetry/instrumentation/base.rb#L216

@arielvalentin ah because if we have OTEL_SDK_DISABLED=true, it returns early and the install method is never reached

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Dup::TracerMiddleware crashes with NoMethodError: undefined method 'include?' for nil when OTEL_SDK_DISABLED=true

2 participants