Skip to content

Commit

Permalink
Merge pull request #4 from bufferapp/task/add-dd-trace-support
Browse files Browse the repository at this point in the history
Add datadog tracing support
  • Loading branch information
erickhun authored Feb 24, 2020
2 parents 195866a + 1599fdf commit 22a93db
Show file tree
Hide file tree
Showing 4 changed files with 996 additions and 1 deletion.
16 changes: 15 additions & 1 deletion bufflog.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import tracer from "dd-trace";
import formats from "dd-trace/ext/formats";

export class BuffLog {
pinoLogger: any;
Expand All @@ -12,7 +14,19 @@ export class BuffLog {

// Define "base" fields
// soon: remove the `v` field https://github.com/pinojs/pino/issues/620
base: {
base: {},

mixin () {
// Check here if a current trace exist to inject it in the log
// `tracer` is a singleton, will no-op if no tracer was initialized
var span = tracer.scope().active()
if (span) {
const traceInfo = {}
tracer.inject(span.context(), formats.LOG, traceInfo);
return traceInfo;
} else {
return {}
}
},

// notice doesn't exist in pino, let's add it
Expand Down
24 changes: 24 additions & 0 deletions index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
import tracer from "dd-trace";
import express from 'express';
import {BuffLog} from './bufflog';

tracer.init({
hostname: "dd-agent-hostname",
logInjection: false
});

let logger = new BuffLog();

logger.info('hello info');
Expand All @@ -8,3 +15,20 @@ logger.notice('hello notice');
logger.warning('hello warning');
logger.error('hello error');
logger.critical('hello critical');

const app = express();

app.listen(4000, () => {
console.log(`Server is listening on port 4000`);
});

app.get('/', (req, res) => {
var logger = new BuffLog();
logger.notice("Notice log via endpoint");
logger.info('hello info');
logger.debug('hello debug');
logger.notice('hello notice');
logger.warning('hello warning');
logger.error('hello error');
logger.critical('hello critical');
});
Loading

0 comments on commit 22a93db

Please sign in to comment.