Skip to content
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

Capturing Performance monitoring transactions for AWS and GCP #830

Merged
merged 12 commits into from Sep 29, 2020
Merged

Capturing Performance monitoring transactions for AWS and GCP #830

merged 12 commits into from Sep 29, 2020

Conversation

shantanu73
Copy link
Contributor

  1. Added code to capture transactions related to performance monitoring for AWS & GCP integrations.
  2. Added test cases as per above changes.

Shantanu Dhiman added 5 commits September 16, 2020 12:34
1) Added code to capture performace data for AWS Lambda Integration.
2) Added and modified test cases based on above changes.
1) Added code to capture performance monitoring data for GCP cloud functions.
2) Added & modified unit test cases based on above changes.
1) Added event assert statements in test_aws.py file
sentry_sdk/integrations/aws_lambda.py Outdated Show resolved Hide resolved
sentry_sdk/integrations/aws_lambda.py Outdated Show resolved Hide resolved
tests/integrations/aws_lambda/test_aws.py Outdated Show resolved Hide resolved
tests/integrations/aws_lambda/test_aws.py Show resolved Hide resolved
tests/integrations/aws_lambda/test_aws.py Outdated Show resolved Hide resolved
tests/integrations/aws_lambda/test_aws.py Outdated Show resolved Hide resolved
tests/integrations/gcp/test_gcp.py Outdated Show resolved Hide resolved
tests/integrations/gcp/test_gcp.py Outdated Show resolved Hide resolved
Shantanu Dhiman added 2 commits September 25, 2020 20:05
1) Modified aws_lambda.py file to include continue_from_headers method for transaction and kept try-except bock inside transaction, changed op value to serverless.function.
2) Modified gcp.py file to include continue_from_headers method for transaction and kept try-except block inside transaction context, changed op value to serverless.function.
3) Modified gcp.py file to include request data and headers data.
4) Modified test_aws.py file to remove redundant traces_sample_rate parameter and moved the logic for fetching events & envelopes to same loop.
5) Modified test_gcp.py file to remove redundant traces_sample_rate parameter and moved the logic for fetching events & envelopes to same loop (similar to AWS).
1) Modified queryy_string parameter in event processor for gcp.py file.
2) Added functionhandler and event parameters while returning handler in the sentry_wrapper.
# event. Meaning every body is unstructured to us.
request["data"] = AnnotatedValue("", {"rem": [["!raw", "x", 0, 0]]})
if "body" in aws_event:
request["data"] = aws_event.get("body", "")
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@untitaker I made this change to display the request body appear on Sentry Dashboard as shown below. This change was discussed with AJ.

req_body

Copy link
Member

Choose a reason for hiding this comment

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

Please restore the old behavior when the client option send_default_pii is in its default False. If the user set send_default_pii=True we can do what you propose.

Also please restore the code comment.

The reason for this is that we want to be safe by default: the request body can contain a lot of sensitive data and setting sendDefaultPii is our way of having the user say "I accept the risks".

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@untitaker you mean that essentially, I move this section of code I've written to the if section for send_default_pii part and revert the changes here.

Copy link
Member

Choose a reason for hiding this comment

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

sorry I mean

if send_default_pii:
    new_code
else:
    old_code

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Okay, I'll make these changes asap.

@@ -143,6 +153,18 @@ def event_processor(event, hint):

request["url"] = "gcp:///{}".format(environ.get("FUNCTION_NAME"))

if hasattr(gcp_event, "method"):
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@untitaker I've modified event processor for GCP integration to get request related for Sentry dashboard.

1) Added code to set region tag for AWS & GCP integrations
Shantanu Dhiman added 2 commits September 28, 2020 17:59
1) Moved the logic to get request body only when user explicitly sets send_default_pii value to True for both AWS & GCP integrations
1) Modified region parameter for AWS & GCP integrations.
)
try:
scope.set_tag("gcp_region", environ.get("FUNCTION_REGION"))
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@untitaker Made all changes as per review comments, you may review them.

sentry_sdk/integrations/gcp.py Outdated Show resolved Hide resolved
sentry_sdk/integrations/aws_lambda.py Outdated Show resolved Hide resolved
sentry_sdk/integrations/gcp.py Show resolved Hide resolved
sentry_sdk/integrations/gcp.py Show resolved Hide resolved
sentry_sdk/integrations/gcp.py Show resolved Hide resolved
@@ -50,7 +50,7 @@ def sentry_func(functionhandler, event, *args, **kwargs):
logger.debug(
"The configured timeout could not be fetched from Cloud Functions configuration."
)
return func(functionhandler, event, *args, **kwargs)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@untitaker wanted to know why was this changed?
If we are going to change this, then I might need to fix code to get event object, as well as fix unit tests for this coz they might break.

Copy link
Member

Choose a reason for hiding this comment

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

Sorry, I thought this was an unnecessary change, will revert.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

okay, alright. Actually this change was done considering all trigger types for GCP Cloud functions. In all the trigger types, there are 2 parameters which are passed on to the "invoke_user_function" (similar to "request_handler" in AWS) which are "functionhandler" & "event" (similar to "event" & "context" in AWS).
And, since we do need headers from event object and other request related data, this change was made.

@untitaker untitaker merged commit cdf21de into getsentry:master Sep 29, 2020
@untitaker
Copy link
Member

Perfect, thanks. I will release later this week, out of bandwidth right now unfortunately.

@shantanu73
Copy link
Contributor Author

Perfect, thanks. I will release later this week, out of bandwidth right now unfortunately.

Sure. Thanks.

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.

None yet

2 participants