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

[SVLS-4647] Fix lambda authorizer trace context injection issue #453

Merged
merged 1 commit into from Mar 27, 2024

Conversation

joeyzhao2018
Copy link
Contributor

@joeyzhao2018 joeyzhao2018 commented Mar 27, 2024

What does this PR do?

There's a regression introduced about authorizer span due to the hardcoded headers values broken by the changes happened in ddtrace.
Specifically, the value of trace id has been directly fetched from the span_context like this injected_headers[TraceHeader.TRACE_ID] = str(span_context.trace_id) and that span_context.trace_id is now changed into a big int and causing problem when the downstream main lambda tries to extract it
Screenshot 2024-03-26 at 11 43 53 AM
The fix is to use the official propagtor from ddtrace to inject the context.

Testing Guidelines

Updated the unittest to use the propagator too in order to future proof such kind of issue introduced by dependency updates.
Tested in a real lambda case and see it back to normal like this:
Screenshot 2024-03-27 at 1 15 22 PM

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)

injected_headers[TraceHeader.SAMPLING_PRIORITY] = str(
span_context.sampling_priority
)
propagator.inject(span_context, injected_headers)
Copy link
Contributor

Choose a reason for hiding this comment

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

Great catch, I wonder if this methods should eventually be refactored into a tracing service and not the wrapper 😕

Copy link
Contributor

Choose a reason for hiding this comment

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

the propagator.inject ends up injecting into injected_headers, correct?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good question!

Having the same thought, I went ahead trying to refactor it.
Then I found it's already in a helper method called _inject_authorizer_span_headers.
Then it felt that the injection is more relevant to the wrapper because the wrapper now has the inferred_span or span data and it also should be responsible for the final response data. And then at this point, the injection became more like prepare_response and the only tracer related part is already encapsulated by the propagator.inject helper.
Hope this makes sense.

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.

LGTM – left a non-blocking question.

@joeyzhao2018 joeyzhao2018 merged commit 8e79a70 into main Mar 27, 2024
51 checks passed
@joeyzhao2018 joeyzhao2018 deleted the joey/authorizer_fix branch March 27, 2024 17:49
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