Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save stevenc81/dd54789ace5b9db7753e9665b84394d4 to your computer and use it in GitHub Desktop.
Save stevenc81/dd54789ace5b9db7753e9665b84394d4 to your computer and use it in GitHub Desktop.
A quick example for Datadog APM tracing and logging
require('dd-trace').init({
hostname: process.env.DD_AGENT_HOST,
port: 8126,
env: 'development',
logInjection: true,
analytics: true,
});
const { createLogger, format, transports } = require('winston');
const addAppNameFormat = format(info => {
info.ddtags = {'logging-mvp': 'dd-tracing-logging-examples-nodejs'};
return info;
});
const logger = createLogger({
level: 'info',
exitOnError: false,
format: format.combine(
addAppNameFormat(),
format.json(),
),
transports: [
new transports.Console(),
],
});
const express = require('express');
var app = express();
app.get('/', function (req, res) {
logger.log('info', 'A simple log that works with Datadog APM tracing and logging!');
res.send('Hello world, this will demo Datadog tracing and logging!');
});
app.listen(3000, function () {
console.log('Example app listening on port 3000!');
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment