DataDog Transport Server
Ships logs server-side to Datadog using the datadog-transport-common library.
Important Notes
- Only works server-side (not in browsers)
- For browser-side logging, use the
@loglayer/transport-datadog-browser-logspackage
- For browser-side logging, use the
- You will not get any console output since this sends directly to DataDog. Use the
onDebugoption to log out messages.
Installation
Install the required packages (datadog-transport-common is installed as part of @loglayer/transport-datadog):
npm i loglayer @loglayer/transport-datadog serialize-errorpnpm add loglayer @loglayer/transport-datadog serialize-erroryarn add loglayer @loglayer/transport-datadog serialize-errorUsage Example
DataDog Error Tracking
To use DataDog's Error Tracking feature, configure the errorFieldName as error in your LogLayer configuration.
Alternatively, you can use DataDog's Pipeline Processing to remap the default err field to error.
You can also add remapping via DataDog Logs > Configuration > Standard Attributes and add remapping for the error.message / error.stack attributes (or add a new one for these if they do not exist) and remap to how you've configured LogLayer.
For example, attribute error.message might remap to err.message,metadata.err.message, depending on how LogLayer is configured.
import { LogLayer } from 'loglayer'
import { DataDogTransport } from "@loglayer/transport-datadog"
import { serializeError } from "serialize-error";
const log = new LogLayer({
errorSerializer: serializeError,
errorFieldName: "error",
transport: new DataDogTransport({
options: {
ddClientConf: {
authMethods: {
apiKeyAuth: "YOUR_API_KEY",
},
},
ddServerConf: {
// Note: This must match the site you use for your DataDog login - See below for more info
site: "datadoghq.eu"
},
onDebug: (msg) => {
console.log(msg);
},
onError: (err, logs) => {
console.error(err, logs);
},
},
})
})Transport Configuration
Required Parameters
| Name | Type | Description |
|---|---|---|
options | DDTransportOptions | The options for the transport |
Optional Parameters
| Name | Type | Default | Description |
|---|---|---|---|
enabled | boolean | true | Whether the transport is enabled |
messageField | string | "message" | The field name to use for the message |
levelField | string | "level" | The field name to use for the log level |
timestampField | string | "time" | The field name to use for the timestamp |
timestampFunction | () => any | - | A custom function to stamp the timestamp. The default timestamp uses the ISO 8601 format |
level | "trace" | "debug" | "info" | "warn" | "error" | "fatal" | "trace" | Minimum log level to process. Logs below this level will be filtered out |
Changelog
View the changelog here.
