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

What would be the best way to integrate Datadog APM tracing? #37

Closed
theogravity opened this issue Feb 18, 2021 · 2 comments
Closed

What would be the best way to integrate Datadog APM tracing? #37

theogravity opened this issue Feb 18, 2021 · 2 comments
Labels

Comments

@theogravity
Copy link

theogravity commented Feb 18, 2021

According to:

https://docs.datadoghq.com/tracing/connect_logs_and_traces/nodejs/

To enable this feature, I'd have to wrap the record that writes out with the following:

        const span = tracer.scope().active();
        const time = new Date().toISOString();
        const record = { time, level, message };

        if (span) {
            tracer.inject(span.context(), formats.LOG, record);
        }

Based on reading the roarr docs, it seems I'd want to inject this in the child logger function / create middleware?

@gajus gajus added the question label Feb 18, 2021
@gajus
Copy link
Owner

gajus commented Feb 18, 2021

Depends. If you want all your logs (e.g. those included by some dependencies that use roarr) then your better option is to extend ROARR.write. Something like this:

import {
  ROARR,
} from 'roarr';

const main = () => {
  const oldWrite = ROARR.write;

  ROARR.write = (message) => {
    const span = tracer.scope().active();
    const time = new Date().toISOString();
    const record = { time, level, message };

    if (span) {
      tracer.inject(span.context(), formats.LOG, record);
    }

    oldWrite(message);
  };
};

If you only care about the logs produced directly by your application, then middleware is sufficient.

@gajus gajus closed this as completed Feb 18, 2021
@theogravity
Copy link
Author

Thank you!

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

No branches or pull requests

2 participants