Skip to content

Allow set custom timestamp for metric datapoint #58

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

Closed
PatrykMilewski opened this issue Mar 9, 2020 · 8 comments
Closed

Allow set custom timestamp for metric datapoint #58

PatrykMilewski opened this issue Mar 9, 2020 · 8 comments

Comments

@PatrykMilewski
Copy link

Expected Behavior

When I'm sending datapoint with sendDistributionMetric function, I would like to specify my custom timestamp.

Actual Behavior

Right now it automatically uses the actual time for timestamp generation.

Specifications

  • Datadog Lambda Layer version: none, datadog-lambda-layer-js:2.17.0
  • Node version: 12.x
@agocs
Copy link
Contributor

agocs commented Mar 9, 2020

👋 Hi, I've added this to a list of feature requests. Custom timestamps in this library make sense. We already allow them in Ruby, Python, and Go.

@PatrykMilewski
Copy link
Author

PatrykMilewski commented Mar 10, 2020

@agocs Could you specify the header of the function, that would have this feature? I'm not sure how you are planning your API for this package, but if you guys would give me some hints, then I could implement it myself and create PR.

@agocs
Copy link
Contributor

agocs commented Mar 10, 2020

Hey @PatrykMilewski , I definitely appreciate the offer. I think the new function would take the signature

export function sendDistributionMetricWithDate(name: string, value: number, date: Date, ...tags: string[])

It would, unfortunately, require refactoring listener.sendDistrobutionMetric and a few other functions to accept the custom date.

@vishnuvisnu
Copy link
Contributor

vishnuvisnu commented Mar 21, 2020

public sendDistributionMetricWithDate(name: string, value: number, date: Date, ...tags: string[])  {

   if (this.config.logForwarding) {
     writeMetricToStdout(name, value, tags);
     return;
   }
   const dist = new Distribution(name, [{ timestamp: date, value }], ...tags);
   if (this.currentProcessor !== undefined) {
     this.currentProcessor.then((processor) => {
       processor.addMetric(dist);
     });
   } else {
     logError("can't send metrics, datadog lambda handler not set up.");
   }
}
public sendDistributionMetric(name: string, value: number, ...tags: string[]) {
 sendDistributionMetricWithDate(name, value, new Date(), tags);
}

These changes to MetricListener in listener.ts along with new function sendDistributionMetricWithDate in index.ts should work, right?

@vishnuvisnu
Copy link
Contributor

vishnuvisnu commented Mar 23, 2020

@agocs Created PR #63 to add custom timestamp.

@vishnuvisnu
Copy link
Contributor

vishnuvisnu commented Mar 23, 2020

@agocs Could you please expedite PR? We are currently using in datadog in production and using the datadog metrics from cloudwatch logs (that were published from the segment) that are in forming like MONITORING|..|..|..|.. but there is significant delay in getting metrics in datadog. This is the current ticket with the datadog team https://help.datadoghq.com/hc/en-us/requests/322610?flash_digest=9f923b6f7becc24b49af9543c88c5faa51c3a52c.

Thanks.

@DarcyRaynerDD
Copy link
Contributor

Hey @vishnuvisnu, thanks for the PR. I can review this for you.

@PatrykMilewski
Copy link
Author

I'm closing it since PR #63 is already merged into master. Thank you @vishnuvisnu

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants