You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository has been archived by the owner on Dec 14, 2022. It is now read-only.
Wondering if you have experience trying to send logs to datadog with a message that is json rather than a string? I'd like to do this because I want to be able to search on all of the message fields rather than sending the JSON as metadata and then creating a facet.
any help is appreciated, thanks!
The text was updated successfully, but these errors were encountered:
dcurletti
changed the title
How to send JSON logs to datadog in such a way that the metadata fields are searchable without creating a facet
How to send JSON to datadog as the message
May 30, 2019
Hey @dcurletti ! I had no problems sending JSON objects to datadog. Code snippet incoming:
constfmt=process.env.LOGGER_FORMAT==='simple' ?
format.combine(format.timestamp(),format.colorize(),format.simple()) :
format.combine(format.timestamp(),format.json());constourTransports=[newtransports.Console()];if(process.env.DD_API_KEY){ourTransports.push(newDatadogTransport({apiKey: process.env.DD_API_KEY,metadata: {source: 'nodejs',// not sure this does anything usefulsourcecategory: 'sourcecode',// not sure this does anything usefulservice: process.env.DD_SERVICE,environment: process.env.YOUR_ENV,},}));}constlogger=createLogger({format: fmt,level: process.env.LOGGER_LEVEL||'info',transports: ourTransports,});
Basically, for devs running the server w/ a winston logger locally, they set LOGGER_FORMAT of simple to get a plain, simple formatted logger w/ colors. In production, though, DD_API_KEY is set and the format used is format.combine(format.timestamp(), format.json()) - meaning that the logger itself will spit out JSON messages to both the console and datadog. All of our logger instances used in specific classes, then, use a simple logger.child({ class: 'FILENAME HERE' }) call so that we know the source of a particular logger call, and that class field present in the JSON is one of our facets for searching in datadog. It all works pretty well in my experience.
Hope that helps!
Sign up for freeto subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Wondering if you have experience trying to send logs to datadog with a message that is json rather than a string? I'd like to do this because I want to be able to search on all of the message fields rather than sending the JSON as metadata and then creating a facet.
any help is appreciated, thanks!
The text was updated successfully, but these errors were encountered: