Skip to content

Conversation

@shreyamalpani
Copy link
Contributor

@shreyamalpani shreyamalpani commented Dec 17, 2024

What does this PR do?

Decodes error.msg and error.type headers as was previously done for the error.stack header, because of DataDog/dd-trace-dotnet#6438 encoding error.msg and error.type.

Motivation

[SLES-2001] .NET Datadog Tracer throws exception from AWS Lambda Function
[SVLS-6041] Having non-ascii characters in a stack trace causes an exception within the tracer.

Testing

Tested with a lambda that throws an exception with an error message containing a non-ASCII character.
image

debug!("Failed to decode error message: {e}");
m.to_string()
}
};
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm pretty sure there's a cleaner way to do this

let decoded_message = match base64_to_string(m) {
Ok(decoded) => decoded,
Err(e) => {
debug!("Failed to decode error message: {e}");
Copy link
Contributor

Choose a reason for hiding this comment

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

Message is too ambiguous, since you're actually setting the error at the end, so it's kinda misleading and user might think that it failed, but the error message is actually there

Copy link
Contributor

Choose a reason for hiding this comment

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

Needs unit testing


if let Some(m) = message {
let decoded_message = base64_to_string(m).unwrap_or_else(|_| {
debug!("Error message header may not be encoded, setting as is");
Copy link
Contributor

Choose a reason for hiding this comment

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

Much more cleaner, great!

}
};
let decoded_stack = base64_to_string(s).unwrap_or_else(|_| {
debug!("Error stack header may not be encoded, setting as is");
Copy link
Contributor

Choose a reason for hiding this comment

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

This always comes encoded, so the previous error message was OK

Copy link
Contributor

@duncanista duncanista left a comment

Choose a reason for hiding this comment

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

Let's keep the previous message for the error stack, overall LGTM

@shreyamalpani shreyamalpani merged commit beb8bf6 into main Dec 18, 2024
24 checks passed
@shreyamalpani shreyamalpani deleted the shreya.malpani/decode-error-msg-and-type branch December 18, 2024 19:16
shreyamalpani added a commit to DataDog/dd-trace-dotnet that referenced this pull request Dec 20, 2024
## Summary of changes

Encodes `error.msg` and `error.type` like the previously encoded
`error.stack`.


![image](https://github.com/user-attachments/assets/9bf0becf-7960-4106-9b74-132e99f83755)

Related extension changes:
DataDog/datadog-agent#32231
DataDog/datadog-lambda-extension#500

## Reason for change
Prevents the tracer from throwing an exception due to non-ASCII
characters in these header values.

[[SLES-2001] .NET Datadog Tracer throws exception from AWS Lambda
Function](https://datadoghq.atlassian.net/browse/SLES-2001)
[[SVLS-6041] Having non-ascii characters in a stack trace causes an
exception within the
tracer.](https://datadoghq.atlassian.net/browse/SVLS-6041)

## Implementation details
Encodes the string values to UTF-8 bytes and then to a Base64 string.

## Test coverage
Updated tests to check for encoded values.

## Other details
<!-- Fixes #{issue} -->


<!-- ⚠️ Note: where possible, please obtain 2 approvals prior to
merging. Unless CODEOWNERS specifies otherwise, for external teams it is
typically best to have one review from a team member, and one review
from apm-dotnet. Trivial changes do not require 2 reviews. -->


[SLES-2001]:
https://datadoghq.atlassian.net/browse/SLES-2001?atlOrigin=eyJpIjoiNWRkNTljNzYxNjVmNDY3MDlhMDU5Y2ZhYzA5YTRkZjUiLCJwIjoiZ2l0aHViLWNvbS1KU1cifQ
[SVLS-6041]:
https://datadoghq.atlassian.net/browse/SVLS-6041?atlOrigin=eyJpIjoiNWRkNTljNzYxNjVmNDY3MDlhMDU5Y2ZhYzA5YTRkZjUiLCJwIjoiZ2l0aHViLWNvbS1KU1cifQ
chojomok pushed a commit to DataDog/dd-trace-dotnet that referenced this pull request Jul 15, 2025
## Summary of changes

Encodes `error.msg` and `error.type` like the previously encoded
`error.stack`.


![image](https://github.com/user-attachments/assets/9bf0becf-7960-4106-9b74-132e99f83755)

Related extension changes:
DataDog/datadog-agent#32231
DataDog/datadog-lambda-extension#500

## Reason for change
Prevents the tracer from throwing an exception due to non-ASCII
characters in these header values.

[[SLES-2001] .NET Datadog Tracer throws exception from AWS Lambda
Function](https://datadoghq.atlassian.net/browse/SLES-2001)
[[SVLS-6041] Having non-ascii characters in a stack trace causes an
exception within the
tracer.](https://datadoghq.atlassian.net/browse/SVLS-6041)

## Implementation details
Encodes the string values to UTF-8 bytes and then to a Base64 string.

## Test coverage
Updated tests to check for encoded values.

## Other details
<!-- Fixes #{issue} -->


<!-- ⚠️ Note: where possible, please obtain 2 approvals prior to
merging. Unless CODEOWNERS specifies otherwise, for external teams it is
typically best to have one review from a team member, and one review
from apm-dotnet. Trivial changes do not require 2 reviews. -->


[SLES-2001]:
https://datadoghq.atlassian.net/browse/SLES-2001?atlOrigin=eyJpIjoiNWRkNTljNzYxNjVmNDY3MDlhMDU5Y2ZhYzA5YTRkZjUiLCJwIjoiZ2l0aHViLWNvbS1KU1cifQ
[SVLS-6041]:
https://datadoghq.atlassian.net/browse/SVLS-6041?atlOrigin=eyJpIjoiNWRkNTljNzYxNjVmNDY3MDlhMDU5Y2ZhYzA5YTRkZjUiLCJwIjoiZ2l0aHViLWNvbS1KU1cifQ
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