Skip to content

Calling datadog.initialize >1 times can be destructive #369

@thundergolfer

Description

@thundergolfer

Given the current behaviour of datadog.initialize, there's potential for a subsequent call to it to wipe out previous API config, which I think is unnecessary and could create annoying bugs.

If I do:

import datadog

API_KEY="thisisakey"
datadog.initialize(api_key=API_KEY)

...
# some other code somewhere later
datadog.initialize(statsd_host=os.environ.get("DOGSTATSD_HOST_IP", "localhost"))

My api_key will no longer be set because of this code -> https://github.com/DataDog/datadogpy/blob/master/datadog/__init__.py#L73

I think it would be quite straightforward to change the above code to first check if _api_key is already set, and not override it with the os.environ.get call. Then datadog.intialize would be more predictable :).

More broadly, I think the mutable state in datadog.api and datadog.statsd makes initilization/config management harder to manager.


Sidenote: I think this issue is expressing related concerns about datadog.initialize #347

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions