dd-trace-py icon indicating copy to clipboard operation
dd-trace-py copied to clipboard

chore(telemetry): use enum for telemetry log levels

Open romainkomorndatadog opened this issue 8 months ago • 4 comments

Makes type-checking more accurate the telemetry writer's add_log() method by specifying an enum.

For example, improperly specifying TELEMETRY_LOG_LEVEL.POTATO instead of .ERROR would result in:

ddtrace/appsec/_iast/_metrics.py:77: error: "Type[TELEMETRY_LOG_LEVEL]" has no attribute "POTATO"  [attr-defined]

This was prompted by #9349 having failures in system-tests due to the use of WARNING instead of WARN.

The telemetry API docs currently specify:

Log level Remote collection policy
ERROR Enabled by default, configured by environment variable DD_TELEMETRY_LOG_COLLECTION_ENABLED
WARN Enabled by default, configured by same environment variable as ERROR
DEBUG Can be enabled locally by the end user when asked by the support team.

Checklist

  • [x] Change(s) are motivated and described in the PR description
  • [x] Testing strategy is described if automated tests are not included in the PR
  • [x] Risks are described (performance impact, potential for breakage, maintainability)
  • [x] Change is maintainable (easy to change, telemetry, documentation)
  • [x] Library release note guidelines are followed or label changelog/no-changelog is set
  • [x] Documentation is included (in-code, generated user docs, public corp docs)
  • [x] Backport labels are set (if applicable)
  • [x] If this PR changes the public interface, I've notified @DataDog/apm-tees.

Reviewer Checklist

  • [x] Title is accurate
  • [x] All changes are related to the pull request's stated goal
  • [x] Description motivates each change
  • [x] Avoids breaking API changes
  • [x] Testing strategy adequately addresses listed risks
  • [x] Change is maintainable (easy to change, telemetry, documentation)
  • [x] Release note makes sense to a user of the library
  • [x] Author has acknowledged and discussed the performance implications of this PR as reported in the benchmarks PR comment
  • [x] Backport labels are set in a manner that is consistent with the release branch maintenance policy

romainkomorndatadog avatar Jun 12 '24 10:06 romainkomorndatadog