Skip to content

Bug: DD_FLUSH_TO_LOG = False flushes to log #6255

Closed
@manzkel

Description

@manzkel

Expected Behaviour

DD_FLUSH_TO_LOG is a boolean environment variable and as such should be converted based on it's content rather than used as a string.

Current Behaviour

As long as the variable is set by the user, DD_FLUSH_TO_LOG is used as string and therefore evaluates to true (when used in boolean operations further down), irrespective of the value passed to the environment variable.

Code snippet

DD_FLUSH_TO_LOG=False 


import os
from aws_lambda_powertools.metrics.provider.datadog import DatadogMetrics

os.environ["DD_FLUSH_TO_LOG"] = "False"
metrics = DatadogMetrics()

print(metrics.provider.flush_to_log)
>'False'

Possible Solution

Use resolve_truthy_env_var_choice instead of resolve_env_var_choice here

self.flush_to_log = resolve_env_var_choice(choice=flush_to_log, env=os.getenv(constants.DATADOG_FLUSH_TO_LOG))

Steps to Reproduce

Powertools for AWS Lambda (Python) version

latest

AWS Lambda function runtime

3.9

Packaging format used

PyPi

Debugging logs

Activity

added
bugSomething isn't working
triagePending triage from maintainers
on Mar 12, 2025
boring-cyborg

boring-cyborg commented on Mar 12, 2025

@boring-cyborg

Thanks for opening your first issue here! We'll come back to you as soon as we can.
In the meantime, check out the #python channel on our Powertools for AWS Lambda Discord: Invite link

changed the title [-]Bug: DD_FLUSH_TO_LOG = False evaluates to true[/-] [+]Bug: DD_FLUSH_TO_LOG = False flushes to log[/+] on Mar 13, 2025
leandrodamascena

leandrodamascena commented on Mar 17, 2025

@leandrodamascena
Contributor

Hi @manzkel! Thanks for opening this issue! Yes, you are right! When setting this using ENV VAR as string, it is not coercing to bool to check if it is true or false. I'm sending a PR to fix this.

added and removed
triagePending triage from maintainers
on Mar 17, 2025
manzkel

manzkel commented on Mar 18, 2025

@manzkel
Author

Thanks so much for opening the PR! 🚀
I know it may not be the right place but if by any chance you could have a look at this discussion #6256 it would be great as I am unable to tell whether this is a bug in the datadog handler as well or whether the problem lies in my configuration, thank you

8 remaining items

Loading
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

bugSomething isn't workingmetrics

Type

Projects

Status

Shipped

Milestone

No milestone

Relationships

None yet

    Participants

    @leandrodamascena@manzkel

    Issue actions

      Bug: DD_FLUSH_TO_LOG = False flushes to log · Issue #6255 · aws-powertools/powertools-lambda-python