-
Notifications
You must be signed in to change notification settings - Fork 36
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #50 from DataDog/stephenf/log-enhanced-metrics-by-…
…default-js Enable enhanced metrics by default and write enhanced metrics to logs
- Loading branch information
Showing
9 changed files
with
61 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
src/metrics/build-metric-log.spec.ts → src/metrics/metric-log.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
// Builds the string representation of the metric that will be written to logs | ||
export function buildMetricLog(name: string, value: number, tags: string[]) { | ||
return `${JSON.stringify({ | ||
// Date.now() returns Unix time in milliseconds, we convert to seconds for DD API submission | ||
e: Date.now() / 1000, | ||
m: name, | ||
t: tags, | ||
v: value, | ||
})}\n`; | ||
} | ||
|
||
/** | ||
* Writes the specified metric to standard output | ||
* @param name The name of the metric | ||
* @param value Metric datapoint's value | ||
* @param tags Tags to apply to the metric | ||
*/ | ||
export function writeMetricToStdout(name: string, value: number, tags: string[]) { | ||
// We use process.stdout.write, because console.log will prepend metadata to the start | ||
// of the log that log forwarder doesn't know how to read. | ||
process.stdout.write(buildMetricLog(name, value, tags)); | ||
} |