Skip to content
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

Datadog logs #988

Open
4 tasks done
diflores opened this issue Aug 20, 2021 · 4 comments
Open
4 tasks done

Datadog logs #988

diflores opened this issue Aug 20, 2021 · 4 comments

Comments

@diflores
Copy link

diflores commented Aug 20, 2021

Prerequisites

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

  • I am running the latest version
  • I checked the documentation and found no answer
  • I checked to make sure that this issue has not already been filed
  • 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!

@icebob
Copy link
Member

icebob commented Aug 20, 2021

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

@diflores
Copy link
Author

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!

@dokutoshi
Copy link

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.

@NoudH NoudH mentioned this issue Jan 17, 2022
9 tasks
@bcavlin
Copy link

bcavlin commented Nov 20, 2022

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 } } )

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