Skip to content

Commit 8ece999

Browse files
authored
fix(profiling/http): converts nanoseconds timestamp to seconds (#1325)
1 parent 99ab6c3 commit 8ece999

File tree

2 files changed

+5
-4
lines changed

2 files changed

+5
-4
lines changed

ddtrace/profiling/exporter/http.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -153,10 +153,10 @@ def export(self, events, start_time_ns, end_time_ns):
153153
fields = {
154154
"runtime-id": RUNTIME_ID,
155155
"recording-start": (
156-
datetime.datetime.utcfromtimestamp(start_time_ns).replace(microsecond=0).isoformat() + "Z"
156+
datetime.datetime.utcfromtimestamp(start_time_ns / 1e9).replace(microsecond=0).isoformat() + "Z"
157157
).encode(),
158158
"recording-end": (
159-
datetime.datetime.utcfromtimestamp(end_time_ns).replace(microsecond=0).isoformat() + "Z"
159+
datetime.datetime.utcfromtimestamp(end_time_ns / 1e9).replace(microsecond=0).isoformat() + "Z"
160160
).encode(),
161161
"runtime": PYTHON_IMPLEMENTATION,
162162
"format": b"pprof",

tests/profiling/exporter/test_http.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
import pytest
1010

11+
from ddtrace import compat
1112
from ddtrace.vendor import six
1213
from ddtrace.vendor.six.moves import BaseHTTPServer
1314
from ddtrace.vendor.six.moves import http_client
@@ -63,7 +64,7 @@ def do_POST(self):
6364
items[part.get_param("name", header="content-disposition")].append(part.get_payload(decode=True))
6465
for key, check in {
6566
"recording-start": lambda x: x[0] == b"1970-01-01T00:00:00Z",
66-
"recording-end": lambda x: b"1970-01-01T00:00:01Z",
67+
"recording-end": lambda x: x[0].startswith(b"20"),
6768
"runtime": lambda x: x[0] == platform.python_implementation().encode(),
6869
"format": lambda x: x[0] == b"pprof",
6970
"type": lambda x: x[0] == b"cpu+alloc+exceptions",
@@ -148,7 +149,7 @@ def test_wrong_api_key(endpoint_test_server):
148149

149150
def test_export(endpoint_test_server):
150151
exp = http.PprofHTTPExporter(_ENDPOINT, _API_KEY)
151-
exp.export(test_pprof.TEST_EVENTS, 0, 1)
152+
exp.export(test_pprof.TEST_EVENTS, 0, compat.time_ns())
152153

153154

154155
def test_export_no_endpoint(endpoint_test_server):

0 commit comments

Comments
 (0)