Skip to content

Fix Grape API api_view method#5364

Merged
vpellan merged 3 commits intoDataDog:masterfrom
ansor4:ansor4/add-grape-api-base-check
Mar 5, 2026
Merged

Fix Grape API api_view method#5364
vpellan merged 3 commits intoDataDog:masterfrom
ansor4:ansor4/add-grape-api-base-check

Conversation

@ansor4
Copy link
Copy Markdown
Contributor

@ansor4 ansor4 commented Feb 13, 2026

What does this PR do?

Grape 3.1.0 introduced a change that breaks fetching the api name from the instance. The change had removed the attr_reader on base for an API instance, resulting in an error when using this version of Grape with datadog.

[2026-02-11T21:59:57.943480 #17] ERROR -- datadog: [datadog] (/usr/local/bundle/gems/datadog-2.28.0/lib/datadog/tracing/contrib/grape/endpoint.rb:80:in 'Datadog::Tracing::Contrib::Grape::Endpoint.endpoint_start_process') undefined method 'base' for class #<Class:0x00007f61f1b194c8>

Motivation:

Above error prevented expected service names and values to show up on the dashboard.

Change log entry

Additional Notes:

How to test the change?

I was able to monkey-patch our service in the meantime and I'm see the expected values in the dashboard.

module DatadogGrapeFix
  def api_view(api)
    if defined?(::Grape::API::Instance) && api <= ::Grape::API::Instance && api.respond_to?(:base)
      api.base.to_s
    else
      api.to_s
    end
  end
end

Datadog::Tracing::Contrib::Grape::Endpoint.singleton_class.prepend(DatadogGrapeFix)

@ansor4 ansor4 requested review from a team as code owners February 13, 2026 21:38
@ansor4 ansor4 requested a review from vpellan February 13, 2026 21:39
@github-actions github-actions Bot added integrations Involves tracing integrations tracing labels Feb 13, 2026
@vpellan vpellan added the community Was opened by a community member label Feb 16, 2026
@vpellan
Copy link
Copy Markdown
Contributor

vpellan commented Feb 16, 2026

Launched CI

Copy link
Copy Markdown
Member

@p-datadog p-datadog left a comment

Choose a reason for hiding this comment

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

Looking at our appraisals, ruby 4.0 specifies grape < 2.3 (I find it weird that most recent ruby has a requirement of an old grape) and the other MRIs have no grape version constraint. Should we distribute < 1.2, <2.3, 2.3 and 3.0 / 3.1 grape versions throughout the various ruby versions?

Comment thread lib/datadog/tracing/contrib/grape/endpoint.rb
Copy link
Copy Markdown
Member

@p-datadog p-datadog left a comment

Choose a reason for hiding this comment

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

Looking at our appraisals, ruby 4.0 specifies grape < 2.3 (I find it weird that most recent ruby has a requirement of an old grape) and the other MRIs have no grape version constraint. Should we distribute < 1.2, <2.3, 2.3 and 3.0 / 3.1 grape versions throughout the various ruby versions?

@vpellan
Copy link
Copy Markdown
Contributor

vpellan commented Mar 3, 2026

Hello! Thanks for your contribution! We're looking at merging this PR and once it's done, we'll merge this one too

@ivoanjo
Copy link
Copy Markdown
Member

ivoanjo commented Mar 3, 2026

I believe this fixes #5359

Comment thread spec/datadog/tracing/contrib/grape/endpoint_spec.rb Outdated
Comment thread spec/datadog/tracing/contrib/grape/endpoint_spec.rb Outdated
@vpellan
Copy link
Copy Markdown
Contributor

vpellan commented Mar 4, 2026

@ivoanjo is right, we need this fix to be able to support 3.1.x, which means we first need to merge this PR before merging #5414. I'm going to update it with latest master, apply reviews and merge it

@vpellan vpellan merged commit b60e998 into DataDog:master Mar 5, 2026
632 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

community Was opened by a community member integrations Involves tracing integrations tracing

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants