Skip to content

[POC] Add DD_TRACE_EXTRACTOR env var to customize Trace extraction customization #112

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 6 commits into from
Feb 19, 2021

Conversation

Czechh
Copy link
Contributor

@Czechh Czechh commented Jan 15, 2021

What does this PR do?

Analogous to DataDog/datadog-lambda-js#151

Provides a way to customize how to extract the trace from the event or context. This will allow us to quickly support new tools and technologies with custom code.

Motivation

Testing Guidelines

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)

@Czechh Czechh requested a review from a team as a code owner January 15, 2021 19:27
@Czechh Czechh force-pushed the sergio.prada/trace-extractor branch from 0b0ef90 to c7d34ea Compare January 15, 2021 19:33
@tianchu tianchu force-pushed the sergio.prada/trace-extractor branch from 8c24766 to 15a1132 Compare February 17, 2021 21:08
self.extractor_env = os.environ.get("DD_TRACE_EXTRACTOR", None)
self.trace_extractor = None

if self.extractor_env:
Copy link
Contributor

Choose a reason for hiding this comment

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

If someone isn't using the redirected handler, could this cause a cyclical dependency. Eg. user does this:

from datadog_lambda.wrapper import datadog_lambda_wrapper

@datadog_lambda_wrapper
def my_lambda_handler(event, context):
   pass

def my_lambda_extractor(event, context):
   //... some extractor logic here

In this case, the import chain would be my_function.py -> datadog_lambda.wrapper -> my_function.py -> etc etc .

Copy link
Contributor

Choose a reason for hiding this comment

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

In node we addressed this by only supporting the env var for the extractor in the redirected handler. When you aren't using the redirected handler, it was possible to pass the extractor in as a config variable to the wrapper.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I think I can probably delay the import to when the extractor needs to be invoked. But I'd rather simply instruct users to put the extractor in a separate file (from the one where the handler is defined). I think that's probably good enough for a poc and given the fact that most of applications should be using the redirected handler now.

@tianchu tianchu merged commit 689ed6f into main Feb 19, 2021
@tianchu tianchu deleted the sergio.prada/trace-extractor branch February 19, 2021 15: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.

3 participants