Skip to content
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

fix(profiling): allow to override options after load #1332

Merged
merged 2 commits into from
Apr 2, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 4 additions & 3 deletions ddtrace/profiling/exporter/http.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
from ddtrace.vendor.six.moves.urllib import parse as urlparse

import ddtrace
from ddtrace.profiling import _attr
from ddtrace.profiling import _traceback
from ddtrace.profiling import exporter
from ddtrace.vendor import attr
Expand Down Expand Up @@ -58,10 +59,10 @@ class PprofHTTPExporter(pprof.PprofExporter):
"""PProf HTTP exporter."""

endpoint = attr.ib(
default=os.getenv("DD_PROFILING_API_URL", "https://intake.profile.datadoghq.com/v1/input"), type=str
factory=_attr.from_env("DD_PROFILING_API_URL", "https://intake.profile.datadoghq.com/v1/input", str), type=str
)
api_key = attr.ib(default=os.getenv("DD_PROFILING_API_KEY", ""), type=str)
timeout = attr.ib(default=os.getenv("DD_PROFILING_API_TIMEOUT", 10), type=float)
api_key = attr.ib(factory=_attr.from_env("DD_PROFILING_API_KEY", "", str), type=str)
timeout = attr.ib(factory=_attr.from_env("DD_PROFILING_API_TIMEOUT", 10, float), type=float)

@staticmethod
def _encode_multipart_formdata(fields, tags):
Expand Down
6 changes: 6 additions & 0 deletions tests/profiling/exporter/test_http.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,12 @@ def test_export_reset(endpoint_test_reset_server):
assert isinstance(e, http_client.BadStatusLine)


def test_default_from_env(monkeypatch):
monkeypatch.setenv("DD_PROFILING_API_KEY", "123")
exp = http.PprofHTTPExporter()
assert exp.api_key == "123"


def test_get_tags():
tags = http.PprofHTTPExporter()._get_tags("foobar")
assert len(tags) == 7
Expand Down