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-logs
package
- For browser-side logging, use the
- You will not get any console output since this sends directly to DataDog. Use the
onDebug
option to log out messages.
Installation
Install the required packages (datadog-transport-common
is installed as part of @loglayer/transport-datadog
):
sh
npm i loglayer @loglayer/transport-datadog serialize-error
sh
pnpm add loglayer @loglayer/transport-datadog serialize-error
sh
yarn add loglayer @loglayer/transport-datadog serialize-error
Usage Example
typescript
import { LogLayer } from 'loglayer'
import { DataDogTransport } from "@loglayer/transport-datadog"
import { serializeError } from "serialize-error";
const log = new LogLayer({
errorSerializer: serializeError,
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.