-
Notifications
You must be signed in to change notification settings - Fork 399
Fix AppSec Sinatra contrib types #5275
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
Typing analysisIgnored filesThis PR clears 8 ignored files. It increases the percentage of typed files from 40.63% to 41.52% (+0.89%). Ignored files (+0-8)✅ Cleared:Note: Ignored files are excluded from the next sections. Untyped methodsThis PR introduces 4 untyped methods and 1 partially typed method. It increases the percentage of typed methods from 58.54% to 58.81% (+0.27%). Untyped methods (+4-0)❌ Introduced:Partially typed methods (+1-0)❌ Introduced:If you believe a method or an attribute is rightfully untyped or partially typed, you can add |
| def watch: ("sinatra.request.dispatch", ::Symbol key) { (stack, ::Datadog::AppSec::Contrib::Sinatra::Gateway::Request) -> stack_result } -> void | ||
| | ("sinatra.request.routed", ::Symbol key) { (stack, [::Datadog::AppSec::Contrib::Sinatra::Gateway::Request, ::Datadog::AppSec::Contrib::Sinatra::Gateway::RouteParams]) -> stack_result } -> void | ||
| | ("sinatra.response.body.json", ::Symbol key) { (stack, Gateway::DataContainer) -> stack_result } -> void | ||
| | (::String name, ::Symbol key) { (stack, argument) -> stack_result } -> void |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Strech what do you think of this approach?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess our "dynamically-typed" language loses its charm in RBS signatures.
But regarding this change, I don't see how it could be made much better, it looks ok I think.
The only thing we could theoretically do is move each argument type (or signature) to the integration package: e.g. declare a type for [::Datadog::AppSec::Contrib::Sinatra::Gateway::Request, ::Datadog::AppSec::Contrib::Sinatra::Gateway::RouteParams], or maybe even a type for the whole ("sinatra.request.routed", ::Symbol key) { (stack, [::Datadog::AppSec::Contrib::Sinatra::Gateway::Request, ::Datadog::AppSec::Contrib::Sinatra::Gateway::RouteParams]) -> stack_result } -> void in the Sinatra contrib RBS namespace).
Maybe that looks better... maybe not 🤷
BenchmarksBenchmark execution time: 2026-01-23 17:23:26 Comparing candidate commit 4b72b39 in PR branch Found 0 performance improvements and 0 performance regressions! Performance is the same for 44 metrics, 2 unstable metrics. |
| def watch_request_dispatch(gateway = Instrumentation.gateway) | ||
| gateway.watch('sinatra.request.dispatch', :appsec) do |stack, gateway_request| | ||
| context = gateway_request.env[AppSec::Ext::CONTEXT_KEY] | ||
| context = gateway_request.env[AppSec::Ext::CONTEXT_KEY] # : Context |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry if I'm out of the loop: is this the "new" syntax for type overrides? # : ...
| gateway.watch('sinatra.request.routed', :appsec) do |stack, args| | ||
| gateway_request, gateway_route_params = args # : [Gateway::Request, Gateway::RouteParams] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's annoying that you have to do this, just to add a type annotation. 😢
What does this PR do?
This PR removes
lib/appsec/contrib/sinatrafrom steep ignored files and fixes types.Motivation:
We want all
AppSecto be properly typechecked.Change log entry
None. This change is internal.
Additional Notes:
APPSEC-60626
How to test the change?
CI