How to use dd-trace - 10 common examples

To help you get started, we’ve selected a few dd-trace examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github moleculerjs / moleculer / src / tracing / exporters / datadog2.js View on Github external
init(tracer) {
		super.init(tracer);

		try {
			const ddTrace = require("dd-trace");
			DatadogSpanContext = require("dd-trace/src/opentracing/span_context");
			DatadogPlatform = require("dd-trace/src/platform");
			this.ddTracer = global.tracer || ddTrace.init(_.defaultsDeep(this.opts.tracerOptions, {
				url: this.opts.agentUrl
			}));
		} catch(err) {
			/* istanbul ignore next */
			this.tracer.broker.fatal("The 'dd-trace' package is missing! Please install it with 'npm install dd-trace --save' command!", err, true);
		}

		this.defaultTags = _.isFunction(this.opts.defaultTags) ? this.opts.defaultTags.call(this, tracer) : this.opts.defaultTags;
		if (this.defaultTags) {
			this.defaultTags = this.flattenTags(this.defaultTags, true);
		}

		this.ddScope = this.ddTracer.scope();

		const oldGetCurrentTraceID = this.tracer.getCurrentTraceID.bind(this.tracer);
		this.tracer.getCurrentTraceID = () => {
github moleculerjs / moleculer / dev / tracing.js View on Github external
"use strict";

const asyncHooks = require("async_hooks");

const tracer = require("dd-trace").init({
	service: "moleculer", // shows up as Service in Datadog UI
	//url: "http://192.168.0.181:8126",
	//debug: true,
	samplingPriority: "USER_KEEP",
});

tracer.use("http");
tracer.use("ioredis");


const ServiceBroker = require("../src/service-broker");
"use strict";

const { MoleculerError } 	= require("../src/errors");
const _ 					= require("lodash");
const { inspect }			= require("util");
github artsy / metaphysics / src / lib / tracer.ts View on Github external
export function init() {
  tracer.init({
    service: DD_TRACER_SERVICE_NAME,
    hostname: DD_TRACER_HOSTNAME,
    plugins: false,
    logger: { debug, error },
    debug: !PRODUCTION_ENV,
  })
  tracer.use("express", {
    // We want the root spans of MP to be labelled as just `metaphysics`
    service: DD_TRACER_SERVICE_NAME,
    headers: ["User-Agent", "X-User-ID"],
  } as any)
  tracer.use("http", {
    service: `${DD_TRACER_SERVICE_NAME}.http-client`,
  })
  tracer.use("graphql", {
    service: `${DD_TRACER_SERVICE_NAME}.graphql`,
github moleculerjs / moleculer / src / tracing / exporters / datadog.js View on Github external
init(tracer) {
		super.init(tracer);

		try {
			const ddTrace = require("dd-trace");
			DatadogSpanContext = require("dd-trace/packages/dd-trace/src/opentracing/span_context");
			DatadogID = require("dd-trace/packages/dd-trace/src/id");
			if (!this.ddTracer) {
				this.ddTracer = ddTrace.init(_.defaultsDeep(this.opts.tracerOptions, {
					url: this.opts.agentUrl
				}));
			}
		} catch(err) {
			/* istanbul ignore next */
			this.tracer.broker.fatal("The 'dd-trace' package is missing! Please install it with 'npm install dd-trace --save' command!", err, true);
		}

		this.defaultTags = _.isFunction(this.opts.defaultTags) ? this.opts.defaultTags.call(this, tracer) : this.opts.defaultTags;
		if (this.defaultTags) {
			this.defaultTags = this.flattenTags(this.defaultTags, true);
		}

		this.ddScope = this.ddTracer.scope();

		const oldGetCurrentTraceID = this.tracer.getCurrentTraceID.bind(this.tracer);
github topcoder-platform / community-app / src / server / index.js View on Github external
/* eslint-disable */
/* Datadog debugging */
import ddTrace from 'dd-trace';

ddTrace.init();

import atob from 'atob';
import Application from 'shared';
import config from 'config';
import express from 'express';
import fetch from 'isomorphic-fetch';
import { logger } from 'topcoder-react-lib';
import fs from 'fs';
import moment from 'moment';
import path from 'path';
import qs from 'qs';
import serializeJs from 'serialize-javascript';

import { DoSSR } from 'utils/SSR';

import { factory as reducerFactory } from 'reducers';
github artsy / metaphysics / src / lib / tracer.ts View on Github external
export function init() {
  tracer.init({
    service: DD_TRACER_SERVICE_NAME,
    hostname: DD_TRACER_HOSTNAME,
    plugins: false,
    logger: { debug, error },
    debug: !PRODUCTION_ENV,
  })
  tracer.use("express", {
    // We want the root spans of MP to be labelled as just `metaphysics`
    service: DD_TRACER_SERVICE_NAME,
    headers: ["User-Agent", "X-User-ID"],
  } as any)
  tracer.use("http", {
    service: `${DD_TRACER_SERVICE_NAME}.http-client`,
  })
  tracer.use("graphql", {
    service: `${DD_TRACER_SERVICE_NAME}.graphql`,
    /**
     * NOTE: This means we capture _all_ variables. When/if needed, we can
     *       use this callback to redact sensitive variables.
     */
    variables: variables => variables,
  } as any)
}
github artsy / metaphysics / src / lib / tracer.ts View on Github external
tracer.init({
    service: DD_TRACER_SERVICE_NAME,
    hostname: DD_TRACER_HOSTNAME,
    plugins: false,
    logger: { debug, error },
    debug: !PRODUCTION_ENV,
  })
  tracer.use("express", {
    // We want the root spans of MP to be labelled as just `metaphysics`
    service: DD_TRACER_SERVICE_NAME,
    headers: ["User-Agent", "X-User-ID"],
  } as any)
  tracer.use("http", {
    service: `${DD_TRACER_SERVICE_NAME}.http-client`,
  })
  tracer.use("graphql", {
    service: `${DD_TRACER_SERVICE_NAME}.graphql`,
    /**
     * NOTE: This means we capture _all_ variables. When/if needed, we can
     *       use this callback to redact sensitive variables.
     */
    variables: variables => variables,
  } as any)
}
github artsy / metaphysics / src / lib / tracer.ts View on Github external
export function init() {
  tracer.init({
    service: DD_TRACER_SERVICE_NAME,
    hostname: DD_TRACER_HOSTNAME,
    plugins: false,
    logger: { debug, error },
    debug: !PRODUCTION_ENV,
  })
  tracer.use("express", {
    // We want the root spans of MP to be labelled as just `metaphysics`
    service: DD_TRACER_SERVICE_NAME,
    headers: ["User-Agent", "X-User-ID"],
  } as any)
  tracer.use("http", {
    service: `${DD_TRACER_SERVICE_NAME}.http-client`,
  })
  tracer.use("graphql", {
    service: `${DD_TRACER_SERVICE_NAME}.graphql`,
    /**
     * NOTE: This means we capture _all_ variables. When/if needed, we can
     *       use this callback to redact sensitive variables.
     */
    variables: variables => variables,
  } as any)
}
github DefinitelyTyped / DefinitelyTyped / types / dd-trace / dd-trace-tests.ts View on Github external
import * as ddTrace from 'dd-trace';
import SpanContext = require('dd-trace/src/opentracing/span_context');

const tracer = ddTrace.init({
    service: 'MyLovelyService',
    hostname: 'localhost',
    port: 8126,
    logger: {
        debug: msg => { },
        error: err => { }
    }
});

tracer
    .trace('web.request', {
        service: 'my_service',
        childOf: new SpanContext({ traceId: 1337, spanId: 42 }),
        tags: {
            env: 'dev'
        }
github moleculerjs / moleculer / test / unit / tracing / exporters / datadog.spec.js View on Github external
it("should convert normal span to Datadog span with parentID, env & logs", () => {
			exporter.ddTracer.startSpan.mockClear();
			fakeDdSpan.context.mockClear();
			fakeDdSpan.setTag.mockClear();
			DatadogSpanContext.mockClear();
			exporter.convertID = jest.fn(id => id);
			exporter.opts.env = "testing";

			const fakeOldSpan = { name: "old-span" };
			fakeTracerScope._spans[asyncHooks.executionAsyncId()] = fakeOldSpan;

			const span = {
				name: "Test Span",
				type: "action",
				id: "aaa-12345678901234567890",
				traceID: "bbb-12345678901234567890",
				parentID: "ccc-12345678901234567890",

				service: {
					fullName: "v1.posts"
				},