Skip to content

Fix API Gateway type guards #165

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

Merged
merged 3 commits into from
Feb 16, 2021
Merged

Fix API Gateway type guards #165

merged 3 commits into from
Feb 16, 2021

Conversation

DylanLovesCoffee
Copy link
Contributor

What does this PR do?

Fixes the type guards for API Gateway V1 and V2 to look for more unique properties within their respective events.

Motivation

Bug fix where the API Gateway v1 type guard would also apply to v2 events leading us to misidentify the event type and incorrect parse the event object. This should address the issue raised in DataDog/serverless-plugin-datadog#112

Testing Guidelines

Updated the API Gateway v2 event sample used for testing. It was previously incorrectly using a v1 event, hence why this fell through the cracks.

Additional Notes

Types of Changes

  • Bug fix
  • New feature
  • Breaking change
  • Misc (docs, refactoring, dependency upgrade, etc.)

Check all that apply

  • This PR's description is comprehensive
  • This PR contains breaking changes that are documented in the description
  • This PR introduces new APIs or parameters that are documented and unlikely to change in the foreseeable future
  • This PR impacts documentation, and it has been updated (or a ticket has been logged)
  • This PR's changes are covered by the automated tests
  • This PR collects user input/sensitive content into Datadog
  • This PR passes the integration tests (ask a Datadog member to run the tests)

@DylanLovesCoffee DylanLovesCoffee requested a review from a team as a code owner February 12, 2021 22:49
@codecov-io
Copy link

codecov-io commented Feb 12, 2021

Codecov Report

Merging #165 (0adc7e8) into main (0372bfa) will increase coverage by 0.50%.
The diff coverage is 50.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##             main     #165      +/-   ##
==========================================
+ Coverage   86.19%   86.70%   +0.50%     
==========================================
  Files          31       31              
  Lines        1181     1181              
  Branches      235      235              
==========================================
+ Hits         1018     1024       +6     
+ Misses        108      102       -6     
  Partials       55       55              
Impacted Files Coverage Δ
src/trace/trigger.ts 84.55% <0.00%> (+4.87%) ⬆️
src/utils/event-type-guards.ts 100.00% <100.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 0372bfa...0adc7e8. Read the comment docs.

}

export function isAPIGatewayEventV2(event: any): event is APIGatewayProxyEventV2 {
return event.requestContext !== undefined && event.version !== undefined;
return event.requestContext !== undefined && event.version === "2.0" && event.rawQueryString !== undefined;
Copy link
Contributor

Choose a reason for hiding this comment

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

Small nit: maybe declare "2.0" as a constant in src/trace/constants.ts

@DylanLovesCoffee DylanLovesCoffee merged commit 08a3e40 into main Feb 16, 2021
@DylanLovesCoffee DylanLovesCoffee deleted the dylan/fix-apigw-type branch February 16, 2021 16:22
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