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

Clarify lambda capturing of SQS and SNS message attributes #614

Merged
merged 1 commit into from
Mar 22, 2022

Conversation

trentm
Copy link
Member

@trentm trentm commented Mar 10, 2022

elastic/apm-agent-nodejs#2605 shows that just setting transaction.context.message.headers = sqsRecord.messageAttributes is wrong, because messageAttributes for both SNS and SQS events have a different structure than is expected. Currently the spec just says:

Field Value Description Source
context.message.headers - The message attributes. Should only be captured, if capturing headers is enabled in the configuration. record.messageAttributes
...
context.message.headers - The message attributes. Should only be captured, if capturing headers is enabled in the configuration. record.sns.messageAttributes

This change attempts to clarify that the messageAttributes fields in the event cannot be used directly.

Checklist for a small enhancement

  • Create PR as draft
  • Approval by at least one other agent
  • Mark as Ready for Review (automatically requests reviews from all agents and PM via CODEOWNERS)
    • Remove PM from reviewers if impact on product is negligible
    • Remove agents from reviewers if the change is not relevant for them
  • Merge after 2 business days passed without objections
    To auto-merge the PR, add /schedule YYYY-MM-DD to the PR description.

@trentm trentm self-assigned this Mar 10, 2022
@apmmachine
Copy link

apmmachine commented Mar 10, 2022

💚 Build Succeeded

the below badges are clickable and redirect to their specific view in the CI or DOCS
Pipeline View Test View Changes Artifacts preview preview

Expand to view the summary

Build stats

  • Start Time: 2022-03-21T05:52:00.838+0000

  • Duration: 3 min 12 sec

trentm added a commit to elastic/apm-agent-nodejs that referenced this pull request Mar 10, 2022
… attributes for lambda transaction

- If a SNS or SQS single event trigger to an instrumented Lambda
  function includes message attributes with the name "traceparent" (and
  "tracestate"), case-insensitive, then those are used to continue the
  trace. This was already being done for API Gateway event headers.
- Also, fix a bug in the capturing of SNS and SQS message attributes as
  "transaction.context.message.headers". Note that only "String"-type
  message attributes are captured. Binary-type attributes are base64
  encoded. I'm not sure of the value in capturing them.

Closes: #1831
Fixes: #2605
Refs: elastic/apm#614
@AlexanderWert
Copy link
Member

@trentm Great catch!

In general: I think it's OK to ignore Binary attributes as I don't see a use case where it might be useful to capture a binary value as an attribute in a transaction. According to the AWS docs StringListValue and BinaryListValue are not implemented (reserved for future), so we can ignore those as well.

For Java:

  • SNS: all data types are represented as String in the AWS library, so not a problem.
  • SQS: currently, with MessageAttribute.getStringValue() we only capture Number and String-typed message attributes. Binary-typed attributes are ignored. So, nothing to do here for Java.

@basepi Let's fix the bug Trent mentioned above for the Python agent as part of the current lambda improvements.

@trentm trentm requested a review from AlexanderWert March 10, 2022 18:19
@trentm trentm marked this pull request as ready for review March 15, 2022 16:04
@trentm trentm requested review from a team as code owners March 15, 2022 16:04
@trentm trentm removed request for a team March 15, 2022 16:05
@trentm trentm removed request for a team March 15, 2022 16:05
trentm added a commit to elastic/apm-agent-nodejs that referenced this pull request Mar 15, 2022
… attributes for lambda transaction (#2606)

- If a SNS or SQS single event trigger to an instrumented Lambda
  function includes message attributes with the name "traceparent" (and
  "tracestate"), case-insensitive, then those are used to continue the
  trace. This was already being done for API Gateway event headers.
- Also, fix a bug in the capturing of SNS and SQS message attributes as
  "transaction.context.message.headers". Note that only "String"-type
  message attributes are captured. Binary-type attributes are base64
  encoded. I'm not sure of the value in capturing them.

Closes: #1831
Fixes: #2605
Refs: elastic/apm#614
Copy link
Member

@SylvainJuge SylvainJuge left a comment

Choose a reason for hiding this comment

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

LGTM from the Java agent perspective as it fits existing implementation.

@trentm trentm merged commit c586f9b into main Mar 22, 2022
@trentm trentm deleted the trentm/lambda-clarify-message-attrs branch March 22, 2022 18:30
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.

5 participants