Skip to content

Conversation

@florentinl
Copy link
Contributor

@florentinl florentinl commented Oct 29, 2025

What does this PR do?

My understanding is that we want instrumentation telemetry to be off by default in python lambda. There is currently a bypass for AppSec that is a bit weird using env vars directly in __init__.py. I added another bypass for Runtime SCA and moved the logic to the config module to rely on parsed env vars instead.

Motivation

A customer asked if he could enable Runtime SCA without enabling AAP (AppSec) in Lambda. This currently requires setting DD_INSTRUMENTATION_TELEMETRY_ENABLED manually, we could make it a bit more easy.

Testing Guidelines

Additional Notes

  • In ddtrace, the telemetry_writer is instantiated and enabled on first import if DD_INSTRUMENTATION_TELEMETRY_ENABLED is not explicitely set to false => The current telemetry enablement code in datadog_lambda/tracing.py is therefore redundant and unnecessary so I removed it.

  • The config.enable_telemetry flag was therefore not necessary anymore and I removed it.

  • This small refactor relies on the fact that the configuration is resolved before importing ddtrace which happens transitively through cold_start.py. Should we make this more explicit by importing it in __init__.py or is this already clear enough ?

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)

@florentinl florentinl force-pushed the florentin.labelle/APPSEC-59739/enable-telemetry-when-sca-is-enabled branch 2 times, most recently from 1716faf to e6c42de Compare October 29, 2025 11:56
@florentinl florentinl marked this pull request as ready for review October 29, 2025 12:04
@florentinl florentinl requested review from a team as code owners October 29, 2025 12:04
@florentinl florentinl marked this pull request as draft October 29, 2025 12:04
@florentinl florentinl marked this pull request as ready for review October 29, 2025 12:17
@joeyzhao2018
Copy link
Contributor

In ddtrace, the telemetry_writer is instantiated and enabled on first import if DD_INSTRUMENTATION_TELEMETRY_ENABLED is not explicitely set to false => The current telemetry enablement code in datadog_lambda/tracing.py is therefore redundant and unnecessary so I removed it.

Currently we are turning telemetry off (except for asm case) for both performance concerns and incpompatibilies (many errors). Therefore I believe we need to keep it.

btw, what's Runtime SCA?

# Telemetry is required for Appsec Software Composition Analysis
os.environ["DD_INSTRUMENTATION_TELEMETRY_ENABLED"] = os.environ.get(
"DD_APPSEC_ENABLED", "false"
)
Copy link
Contributor

Choose a reason for hiding this comment

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

The reason this code was added here was we must ensure the DD_INSTRUMENTATION_TELEMETRY_ENABLED is set before any ddtrace code is imported. Can we ensure that we the change you're proposing? How can we enforce it?

Copy link
Contributor Author

@florentinl florentinl Oct 29, 2025

Choose a reason for hiding this comment

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

The reason this code was added here was we must ensure the DD_INSTRUMENTATION_TELEMETRY_ENABLED is set before any ddtrace code is imported.

I agree. As explained in the PR notes, this is the reason why we need the config to be resolved before the from datadog_lambda.patch import patch_all line of __init__.py.

Can we ensure that we the change you're proposing? How can we enforce it?

We can eagerly import the config in __init__.py and add a test to ensure that importing config.py does not import ddtrace. Would that work for you or does it feel like an unnecessary constraint ? Let me suggest something.

The idea was to reuse the parsing of environment variables done in config if possible. This also looked like some configuration and it felt natural to put it in "config.py".
I can keep it in __init__.py if it make more sense.

Copy link
Contributor

Choose a reason for hiding this comment

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

I think any of those options are fine. As long as we can ensure it's being set before importing ddtrace. I like your idea of adding a test to check for this.

Copy link
Contributor

@purple4reina purple4reina left a comment

Choose a reason for hiding this comment

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

We need to ensure that the DD_INSTRUMENTATION_TELEMETRY_ENABLED is set before any ddtrace code is imported.

@florentinl
Copy link
Contributor Author

florentinl commented Oct 29, 2025

Currently we are turning telemetry off (except for asm case) for both performance concerns and incpompatibilies (many errors). Therefore I believe we need to keep it.

Okay wasn't aware of the arguments for keeping it disabled, thank you for the insight. I am definitely not challenging this decision.

btw, what's Runtime SCA?

Runtime Software Composition Analysis (SCA) is a Code Security product that analyzes third party dependencies installed on the application. It relies on instrumentation telemetry to collect the list of dependencies and their versions.

@florentinl florentinl force-pushed the florentin.labelle/APPSEC-59739/enable-telemetry-when-sca-is-enabled branch 6 times, most recently from 8bf9772 to 3d7e4fc Compare October 29, 2025 17:24
@florentinl florentinl force-pushed the florentin.labelle/APPSEC-59739/enable-telemetry-when-sca-is-enabled branch from 3d7e4fc to f451e8a Compare October 29, 2025 17:26
@florentinl florentinl merged commit af3d0e2 into main Oct 31, 2025
83 checks passed
@florentinl florentinl deleted the florentin.labelle/APPSEC-59739/enable-telemetry-when-sca-is-enabled branch October 31, 2025 08:32
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