Skip to content

Commit

Permalink
Merge pull request #2619 from simlu/dev
Browse files Browse the repository at this point in the history
fix: now logging logs as metric
  • Loading branch information
simlu authored May 21, 2021
2 parents 60bf6d8 + ac98f81 commit e09f903
Show file tree
Hide file tree
Showing 5 changed files with 84 additions and 5 deletions.
21 changes: 16 additions & 5 deletions src/logic/logger/message/datadog.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,26 @@
const get = require('lodash.get');
const datadogDistributionMetric = require('../singleton/datadog-distribution-metric');

module.exports = ({ message }) => {
module.exports = ({
logGroup, level, message, timestamp
}) => {
let parsedMessage = {};
try {
parsedMessage = JSON.parse(message);

if (get(parsedMessage, ['type']) === 'distribution-metric') {
datadogDistributionMetric.enqueue(...get(parsedMessage, ['args']));
}
} catch (e) {
/* ignored */
}
if (get(parsedMessage, ['type']) === 'distribution-metric') {
datadogDistributionMetric.enqueue(...get(parsedMessage, ['args']));
}
datadogDistributionMetric.enqueue(
'aws.lambda_monitor.lambda.log_count',
[timestamp * 1000],
{
tags: [
`level:${level}`,
`fnName:${logGroup.replace(/^\/aws\/lambda\//, '')}`
]
}
);
};
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,23 @@
"environment:local-dev"
]
},
{
"metric": "aws.lambda_monitor.lambda.log_count",
"points": [
[
1511405879000,
[
1
]
]
],
"type": "distribution",
"tags": [
"level:warning",
"fnName:peg-solitiare-dev-overview",
"environment:local-dev"
]
},
{
"metric": "aws.lambda_monitor.lambda.execution_duration",
"points": [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,23 @@
"path": "/api/v1/distribution_points?api_key=INVALID_DATADOG_API_KEY",
"body": {
"series": [
{
"metric": "aws.lambda_monitor.lambda.log_count",
"points": [
[
1511405879000,
[
1
]
]
],
"type": "distribution",
"tags": [
"level:warning",
"fnName:peg-solitiare-dev-overview",
"environment:local-dev"
]
},
{
"metric": "aws.lambda_monitor.lambda.execution_duration",
"points": [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,23 @@
"environment:local-dev"
]
},
{
"metric": "aws.lambda_monitor.lambda.log_count",
"points": [
[
1511405879000,
[
1
]
]
],
"type": "distribution",
"tags": [
"level:warning",
"fnName:peg-solitiare-dev-overview",
"environment:local-dev"
]
},
{
"metric": "aws.lambda_monitor.lambda.execution_duration",
"points": [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,23 @@
"path": "/api/v1/distribution_points?api_key=INVALID_DATADOG_API_KEY",
"body": {
"series": [
{
"metric": "aws.lambda_monitor.lambda.log_count",
"points": [
[
1511405879000,
[
1
]
]
],
"type": "distribution",
"tags": [
"level:warning",
"fnName:peg-solitiare-dev-overview",
"environment:local-dev"
]
},
{
"metric": "aws.lambda_monitor.lambda.execution_duration",
"points": [
Expand Down

0 comments on commit e09f903

Please sign in to comment.