Nebo15 / logger_json

JSON logger formatter with support for Google Cloud, DataDog and other for Elixir.
https://nebo15.github.io/logger_json/
MIT License
237 stars 92 forks source link

add datadog formatters #60

Closed btkostner closed 3 years ago

btkostner commented 3 years ago

This adds a DatadogLogger and a Plug DatadogLogger. Copied mostly from the Google version. Field names are from the Datadog docs and should work out of the box for most people.

Let me know if there are things I missed, or anything you want changed.

Outputs:

{
  "domain": ["elixir"],
  "logger": {
    "thread_name": "#PID<0.510.0>",
    "method_name": "Elixir.Appsignal.initialize/0"
  },
  "message": "AppSignal disabled.",
  "syslog": {
    "hostname": [10, 10, 100, 100, 100, 100, 100],
    "severity": "info",
    "timestamp": "2020-12-14T19:15:28.207Z"
  }
}
{
  "domain": ["elixir"],
  "logger": {
    "thread_name": "#PID<0.712.0>",
    "method_name": "Elixir.LoggerJSON.Ecto.telemetry_logging_handler/4"
  },
  "message": "CREATE TABLE IF NOT EXISTS `schema_migrations` (`version` bigint, `inserted_at` datetime, PRIMARY KEY (`version`)) ENGINE = INNODB",
  "query": {
    "decode_time_μs": 1,
    "execution_time_μs": 164,
    "latency_μs": 475,
    "queue_time_μs": 309,
    "repo": "Recognizer.Repo"
  },
  "syslog": {
    "hostname": [10, 10, 100, 100, 100, 100, 100],
    "severity": "debug",
    "timestamp": "2020-12-14T19:16:47.782Z"
  }
}
{
  "domain": ["elixir"],
  "duration": 3863403,
  "http": {
    "url": "http://localhost/create-account",
    "status_code": 200,
    "method": "GET",
    "referer": "http://localhost:4000/login",
    "request_id": "http_FlDCOItxeudZJ20AAADD",
    "useragent": "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.66 Safari/537.36",
    "url_details": {
      "host": "localhost",
      "port": 4000,
      "path": "/create-account",
      "queryString": "",
      "scheme": "http"
    }
  },
  "logger": {
    "thread_name": "#PID<0.1042.0>",
    "method_name": "Elixir.LoggerJSON.Plug.call/2"
  },
  "message": "",
  "network": {
    "client": {
      "ip": "127.0.0.1"
    }
  },
  "phoenix": {
    "controller": "Elixir.RecognizerWeb.Accounts.UserRegistrationController",
    "action": "new"
  },
  "request_id": "http_FlDCOItxeudZJ20AAADD",
  "syslog": {
    "hostname": [10, 10, 100, 100, 100, 100, 100],
    "severity": "info",
    "timestamp": "2020-12-14T19:16:55.088Z"
  }
}
coveralls commented 3 years ago

Coverage Status

Coverage decreased (-4.1%) to 71.564% when pulling 4135c3b806d3d858c37a9eff722363e8c24f9ce8 on btkostner:datadog into d39ff4dc179e48d1f588724a9fa36730f818624d on Nebo15:master.

AndrewDryga commented 3 years ago

Hey @btkostner, sorry for taking so long to reply. This generally looks good to me but needs to clean up some docs from GKE. I notice there is a duplication issue arising and I had ideas how we can restructure this package into something behavior-based to avoid it, but that can be done later, I don't want to overwhelm you.

Did you have a chance to try this formatter in production?

btkostner commented 3 years ago

I tried this formatter a bit while I was developing it, but I haven't put it in a production environment yet. I can pull a screenshot of it in Datadog after the PR fixes are done if you want.

AndrewDryga commented 3 years ago

@btkostner Would it be used in production? I want to make sure it would have some real usage if we add it, because we will need to maintain it. Otherwise, we can add a notice to the docs that this formatted is experimental and I'll remove that notice once we have somebody who run it for some time in the real app.

btkostner commented 3 years ago

Yes. This will be used for System76 elixir projects in production. Along that line, what are your thoughts about other json formatters similar to the ecto one?

AndrewDryga commented 3 years ago

@btkostner from your examples they look good to me, if we need we can tune them later but until more people start to use this formatter :).