Skip to content

Commit 22a93db

Browse files
authored
Merge pull request #4 from bufferapp/task/add-dd-trace-support
Add datadog tracing support
2 parents 195866a + 1599fdf commit 22a93db

File tree

4 files changed

+996
-1
lines changed

4 files changed

+996
-1
lines changed

bufflog.ts

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import tracer from "dd-trace";
2+
import formats from "dd-trace/ext/formats";
13

24
export class BuffLog {
35
pinoLogger: any;
@@ -12,7 +14,19 @@ export class BuffLog {
1214

1315
// Define "base" fields
1416
// soon: remove the `v` field https://github.com/pinojs/pino/issues/620
15-
base: {
17+
base: {},
18+
19+
mixin () {
20+
// Check here if a current trace exist to inject it in the log
21+
// `tracer` is a singleton, will no-op if no tracer was initialized
22+
var span = tracer.scope().active()
23+
if (span) {
24+
const traceInfo = {}
25+
tracer.inject(span.context(), formats.LOG, traceInfo);
26+
return traceInfo;
27+
} else {
28+
return {}
29+
}
1630
},
1731

1832
// notice doesn't exist in pino, let's add it

index.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
1+
import tracer from "dd-trace";
2+
import express from 'express';
13
import {BuffLog} from './bufflog';
24

5+
tracer.init({
6+
hostname: "dd-agent-hostname",
7+
logInjection: false
8+
});
9+
310
let logger = new BuffLog();
411

512
logger.info('hello info');
@@ -8,3 +15,20 @@ logger.notice('hello notice');
815
logger.warning('hello warning');
916
logger.error('hello error');
1017
logger.critical('hello critical');
18+
19+
const app = express();
20+
21+
app.listen(4000, () => {
22+
console.log(`Server is listening on port 4000`);
23+
});
24+
25+
app.get('/', (req, res) => {
26+
var logger = new BuffLog();
27+
logger.notice("Notice log via endpoint");
28+
logger.info('hello info');
29+
logger.debug('hello debug');
30+
logger.notice('hello notice');
31+
logger.warning('hello warning');
32+
logger.error('hello error');
33+
logger.critical('hello critical');
34+
});

0 commit comments

Comments
 (0)