Skip to content

Commit 3168187

Browse files
authored
Merge pull request #68 from DataDog/stephenf/fix-sync-api-timestamp
Fix timestamps when metrics are submitted synchronously with date
2 parents bd3b705 + 4f6137d commit 3168187

File tree

5 files changed

+8
-6
lines changed

5 files changed

+8
-6
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "datadog-lambda-js",
3-
"version": "2.20.0",
3+
"version": "2.21.0",
44
"description": "Lambda client library that supports hybrid tracing in node js",
55
"main": "dist/index.js",
66
"types": "dist/index.d.ts",

src/metrics/batcher.spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { Distribution } from "./model";
44
describe("Batcher", () => {
55
it("joins metrics with different tag orders", () => {
66
const batcher = new Batcher();
7-
const timestamp = new Date(1559928315);
7+
const timestamp = new Date(1559928315000);
88
const distribution1 = new Distribution(
99
"my-dist",
1010
[{ timestamp, value: 1 }, { timestamp, value: 2 }],
@@ -29,7 +29,7 @@ describe("Batcher", () => {
2929

3030
it("doesn't join metrics with different tags", () => {
3131
const batcher = new Batcher();
32-
const timestamp = new Date(1559928315);
32+
const timestamp = new Date(1559928315000);
3333
const distribution1 = new Distribution(
3434
"my-dist",
3535
[{ timestamp, value: 1 }, { timestamp, value: 2 }],

src/metrics/model.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { Distribution } from "./model";
22

33
describe("Distribution", () => {
44
it("converts to a APIMetric", () => {
5-
const timestamp = new Date(1559928315);
5+
const timestamp = new Date(1559928315000);
66

77
const distribution = new Distribution(
88
"my-dist",

src/metrics/model.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,9 @@ export class Distribution implements Metric {
4242

4343
public toAPIMetrics(): APIMetric[] {
4444
const points: APIPoint[] = this.points.map((point) => {
45-
return [point.timestamp.getTime(), [point.value]];
45+
// Convert the milliseconds we get from getTime to seconds for the Datadog API
46+
const unixSeconds = Math.floor(point.timestamp.getTime() / 1000);
47+
return [unixSeconds, [point.value]];
4648
});
4749
return [
4850
{

src/metrics/processor.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ class MockAPIClient implements Client {
2222
}
2323

2424
function makeMetric(name: string = "my-metric", value: number = 1): Metric {
25-
const timestamp = new Date(1559941498);
25+
const timestamp = new Date(1559941498000);
2626
return new Distribution(name, [{ timestamp, value }], "tag:a", "tag:b");
2727
}
2828

0 commit comments

Comments
 (0)