Skip to content

Commit

Permalink
Merge pull request #1056 from NoudH/master
Browse files Browse the repository at this point in the history
Datadog logger
  • Loading branch information
icebob authored Jan 17, 2022
2 parents d88abb1 + 1cdbc57 commit b951993
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
5 changes: 3 additions & 2 deletions src/loggers/datadog.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class DatadogLogger extends BaseLogger {
super(opts);

this.opts = _.defaultsDeep(this.opts, {
url: "https://http-intake.logs.datadoghq.com/v1/input/",
url: "https://http-intake.logs.datadoghq.com/api/v2/logs/",
apiKey: process.env.DATADOG_API_KEY,
ddSource: "moleculer",
env: undefined,
Expand Down Expand Up @@ -159,10 +159,11 @@ class DatadogLogger extends BaseLogger {
};
});

return fetch(this.opts.url + this.opts.apiKey, {
return fetch(this.opts.url, {
method: "post",
body: JSON.stringify(data),
headers: {
"DD-API-KEY": this.opts.apiKey,
"Content-Type": "application/json"
}
})
Expand Down
9 changes: 5 additions & 4 deletions test/unit/loggers/datadog.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ describe("Test Datadog logger class", () => {
expect(logger.opts).toEqual({
createLogger: null,
level: "info",
url: "https://http-intake.logs.datadoghq.com/v1/input/",
url: "https://http-intake.logs.datadoghq.com/api/v2/logs/",
apiKey: "datadog-api-key",
ddSource: "moleculer",
env: undefined,
Expand All @@ -51,7 +51,7 @@ describe("Test Datadog logger class", () => {
expect(logger.opts).toEqual({
createLogger: expect.any(Function),
level: "debug",
url: "https://http-intake.logs.datadoghq.com/v1/input/",
url: "https://http-intake.logs.datadoghq.com/api/v2/logs/",
apiKey: "datadog-api-key",
ddSource: "my-app",
env: "production",
Expand Down Expand Up @@ -363,11 +363,12 @@ describe("Test Datadog logger class", () => {

expect(fetch).toHaveBeenCalledTimes(1);
expect(fetch).toHaveBeenCalledWith(
"https://http-intake.logs.datadoghq.com/v1/input/datadog-api-key",
"https://http-intake.logs.datadoghq.com/api/v2/logs/",
{
method: "post",
headers: {
"Content-Type": "application/json"
"Content-Type": "application/json",
"DD-API-KEY": "datadog-api-key"
},
body: '[{"timestamp":0,"level":"fatal","message":"message { a: 5 }","nodeID":"node-1","ddsource":"moleculer","ddtags":"env:,nodeID:node-1,namespace:undefined","hostname":"my-host"},{"timestamp":0,"level":"error","message":"message { a: 5 }","nodeID":"node-1","ddsource":"moleculer","ddtags":"env:,nodeID:node-1,namespace:undefined","hostname":"my-host"}]'
}
Expand Down

0 comments on commit b951993

Please sign in to comment.