moleculer icon indicating copy to clipboard operation
moleculer copied to clipboard

Datadog logs

Open diflores opened this issue 4 years ago • 4 comments

Prerequisites

Please answer the following questions for yourself before submitting an issue.

  • [X] I am running the latest version
  • [X] I checked the documentation and found no answer
  • [X] I checked to make sure that this issue has not already been filed
  • [X] I'm reporting the issue to the correct repository

Current Behavior

Datadog logs are not sent.

Expected Behavior

I expect to see my logs in the Datadog dashboard.

Failure Information

First things first, amazing work, you guys. Developing microservices with Moleculer is bliss. I have the following configuration for Moleculer logger:

  logger: [{
    type: 'Console',
    options: {
      // Using colors on the output
      colors: true,
      // Print module names with different colors (like docker-compose for containers)
      moduleColors: false,
      // Line formatter. It can be "json", "short", "simple", "full", a `Function` or a
      // template string like "{timestamp} {level} {nodeID}/{mod}: {msg}"
      formatter: 'full',
      // Custom object printer. If not defined, it uses the `util.inspect` method.
      objectPrinter: null,
      // Auto-padding the module name in order to messages begin at the same column.
      autoPadding: false,
    },
  },
  {
    type: 'Datadog',
    options: {
      // Logging level
      level: 'info',
      // Datadog server endpoint. https://docs.datadoghq.com/api/?lang=bash#send-logs-over-http
      url: 'https://http-intake.logs.datadoghq.com/v1/input/',
      // Datadog API key
      apiKey: 'my_api_key',
      // Datadog source variable
      ddSource: 'moleculer',
      // Datadog env variable
      env: 'development',
      // Datadog hostname variable
      hostname: 'test.com',
      // Custom object printer function for `Object` & `Ąrray`
      objectPrinter: null,
      // Data uploading interval
      interval: 10 * 1000,
    },
  }, 'Laboratory'],

I can see my logs appear correctly in my console, but I can't see them in Datadog. There's no error regarding Datadog showing in my console. Additionally, I tried doing a POST request using cURL, and it worked, so API Key is not the problem. I also tried to use the Winston logger option mentioned in Moleculer documentation, with this solution, but I had no luck.

I hope someone can help me; I've been stuck for days.

All the best, and thank you in advance!

diflores avatar Aug 20 '21 01:08 diflores

I've just test it in the repo with a simple code and the log messages appears on Datadog.

logger: [
    {
        type: "Console",
        options: {}
    },
    {
        type: "File",
        options: {
            folder: "d:/logs",
            filename: "moleculer-{date}.log",
            formatter: "full"
        }
    },
    {
        type: "Datadog",
        options: {}
    }
]

The Datadog API key configured via env var. image

icebob avatar Aug 20 '21 07:08 icebob

Hi, thanks for your quick answer. I tested your code with a microservice that has explicit definition of the ServiceBroker and worked fine, thanks. My problem is when using the moleculer.config.js file. Everything else works fine (Datadog tracing, Prometheus metrics, for example), but Datadog logger is somehow ignored. Any clue of what could be my problem? Providing more context, I'm using Kubernetes with minikube. Logs are correctly printed to console.

All the best!

diflores avatar Aug 20 '21 21:08 diflores

Hi, thanks for your quick answer. I tested your code with a microservice that has explicit definition of the ServiceBroker and worked fine, thanks. My problem is when using the moleculer.config.js file. Everything else works fine (Datadog tracing, Prometheus metrics, for example), but Datadog logger is somehow ignored. Any clue of what could be my problem? Providing more context, I'm using Kubernetes with minikube. Logs are correctly printed to console.

All the best!

The other loggers such as Pino also do not work when using moleculer.config.js.

dokutoshi avatar Dec 07 '21 20:12 dokutoshi

Does this have something to do with the fact that Datadog requires key to be sent in header, and not as param? return fetch( ${this.opts.baseUrl}${this.opts.apiVersion}${this.opts.path}, { method: "post", body: JSON.stringify({ series }), headers: { "Content-Type": "application/json", "DD-API-KEY": this.opts.apiKey } } )

bcavlin avatar Nov 20 '22 20:11 bcavlin