Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add datadog tracing support #4

Merged
merged 5 commits into from
Feb 24, 2020
Merged

Add datadog tracing support #4

merged 5 commits into from
Feb 24, 2020

Conversation

erickhun
Copy link
Collaborator

Append trace_id and span_id to the logs.
We use the mixin() function of pino to append traces to the logs.

Pre-Requirement:

The service using the lib will need to also have the dd-trace library installed. If not, nothing will be appended to the logs.

How to initialise the tracer in a service:

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

# then BuffLog will automatically detect instance of `tracer` and inject the `trace_id`/`span_id`

Results:

# outside a request: 
{"level":35,"time":1582527777954,"message":"hello notice","v":1}
{"level":40,"time":1582527777955,"message":"hello warning","v":1}
{"level":50,"time":1582527777955,"message":"hello error","v":1}
{"level":60,"time":1582527777955,"message":"hello critical","v":1}

# during a request: 
Server is listening on port 4000
{"level":35,"time":1582527789115,"dd":{"trace_id":"4471443652644886255","span_id":"8148478562811089665"},"message":"Log via endpoint","v":1}
{"level":35,"time":1582527789116,"dd":{"trace_id":"4471443652644886255","span_id":"8148478562811089665"},"message":"hello notice","v":1}
{"level":40,"time":1582527789117,"dd":{"trace_id":"4471443652644886255","span_id":"8148478562811089665"},"message":"hello warning","v":1}
{"level":50,"time":1582527789117,"dd":{"trace_id":"4471443652644886255","span_id":"8148478562811089665"},"message":"hello error","v":1}
{"level":60,"time":1582527789117,"dd":{"trace_id":"4471443652644886255","span_id":"8148478562811089665"},"message":"hello critical","v":1}

cc @esclapes @colinscape if you have any comments :) ( I also tried to add tests with #3 , but I couldn't figure out yet how to properly test what's sent to stdout )

@erickhun erickhun requested review from esclapes and removed request for esclapes February 24, 2020 07:25
@erickhun erickhun merged commit 22a93db into master Feb 24, 2020
@erickhun erickhun deleted the task/add-dd-trace-support branch February 24, 2020 07:26
import {BuffLog} from './bufflog';

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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @erickhun,

Curious to know what differences you found between using logInjection: true which supports pino and doing the injection manually like we are doing in this PR. Is the injected data different?

Copy link
Collaborator Author

@erickhun erickhun Feb 24, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@esclapes good one, i've tried to add the traceID with switching the logInjection to true as you said, but it didn't work out of the box 🤔. It's why i've ended up with the manual tracing.

I'm not too sure how we can make it detect by the dd-trace plugin out of the box. but if you have any idea to make that work that'd be awesome.

Copy link

@esclapes esclapes Feb 24, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@erickhun 🤔 my hunch is that it's an issue with the order of the imports. I believe the .init call needs to happen before anything else is imported so that dd-trace has time to monkey patch the supported libraries.

We usually place all the init code in a separate file and then import that file at the top of the index. This is a recent example

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@esclapes oh thanks! i'll try this in an other branch. Sorry if that might look obvious, still trying to get up to speed with js 😅

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@esclapes implemented in #8

It also worked if we don't do it in an other file 🤔. I think I've perhaps not switched the autoinject parameter properly 🙈

Thanks for your feedbacks, definitely make it easier to use!

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Glad to know that it works! It feels nice to use the dd-trace feature for this, as it will probably be updated with newer features and bug fixes that may not be obvious to us.

💯

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants