From 357e407b19828d83ee744eaa8943086008051f97 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Eloy=20Dur=C3=A1n?= Date: Wed, 19 Sep 2018 13:04:03 +0200 Subject: [PATCH 1/3] [dd-trace] Update for v0.6.0 --- types/dd-trace/dd-trace-tests.ts | 49 +++++++++++------ types/dd-trace/index.d.ts | 90 +++++++++++++++++++++++++------- 2 files changed, 104 insertions(+), 35 deletions(-) diff --git a/types/dd-trace/dd-trace-tests.ts b/types/dd-trace/dd-trace-tests.ts index 007ccc30a4..0f6ac97630 100644 --- a/types/dd-trace/dd-trace-tests.ts +++ b/types/dd-trace/dd-trace-tests.ts @@ -1,35 +1,52 @@ -import * as tracer from 'dd-trace'; -import SpanContext = require('dd-trace/src/opentracing/span_context'); +import * as tracer from "dd-trace"; +import SpanContext = require("dd-trace/src/opentracing/span_context"); tracer.init({ - service: 'MyLovelyService', - hostname: 'localhost', + service: "MyLovelyService", + hostname: "localhost", port: 8126, logger: { - debug: msg => { }, - error: err => { } - } + debug: msg => {}, + error: err => {}, + }, +}); + +tracer.use("express", { + service: "incoming-request", + headers: ["User-Agent"], + validateStatus: code => code !== 418, +}); + +tracer.use("graphql", { + depth: 1, + // Can’t use spread operator here due to https://github.com/Microsoft/TypeScript/issues/10727 + // tslint:disable-next-line:prefer-object-spread + variables: variables => Object.assign({}, variables, { password: "REDACTED" }), +}); + +tracer.use("http", { + splitByDomain: true, }); tracer - .trace('web.request', { - service: 'my_service', + .trace("web.request", { + service: "my_service", childOf: new SpanContext({ traceId: 1337, spanId: 42 }), // Childof must be an instance of this type. See: https://github.com/DataDog/dd-trace-js/blob/master/src/opentracing/tracer.js#L99 tags: { - env: 'dev' - } + env: "dev", + }, }) .then(span => { - span.setTag('my_tag', 'my_value'); + span.setTag("my_tag", "my_value"); span.finish(); }); const parentScope = tracer.scopeManager().active(); -const span = tracer.startSpan('memcached', { +const span = tracer.startSpan("memcached", { childOf: parentScope && parentScope.span(), tags: { - 'service.name': 'my-memcached', - 'resource.name': 'get', - 'span.type': 'memcached', + "service.name": "my-memcached", + "resource.name": "get", + "span.type": "memcached", }, }); diff --git a/types/dd-trace/index.d.ts b/types/dd-trace/index.d.ts index a6bbe7dde9..db1c5cf352 100644 --- a/types/dd-trace/index.d.ts +++ b/types/dd-trace/index.d.ts @@ -1,11 +1,14 @@ -// Type definitions for dd-trace-js 0.5 +// Type definitions for dd-trace-js 0.6 // Project: https://github.com/DataDog/dd-trace-js // Definitions by: Colin Bradley // Eloy Durán // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped +// Prettified with: +// $ prettier --parser typescript --tab-width 4 --semi --trailing-comma es5 --write --print-width 120 types/dd-trace/{,*}/*.ts* + import { Tracer, Span, SpanContext } from "opentracing"; -import DatadogSpanContext = require('./src/opentracing/span_context'); +import DatadogSpanContext = require("./src/opentracing/span_context"); declare var trace: TraceProxy; export = trace; @@ -21,7 +24,7 @@ declare class TraceProxy extends Tracer { * @param plugin The name of a built-in plugin. * @param config Configuration options. */ - use(plugin: string, config: PluginOptions): this; + use

(plugin: P, config: PluginConfiguration[P]): this; /** * Initiate a trace and creates a new span. @@ -103,25 +106,12 @@ interface TracerOptions { * see https://datadog.github.io/dd-trace-js/#custom-logging__anchor */ logger?: { - debug: (message: string) => void - error: (err: Error) => void + debug: (message: string) => void; + error: (err: Error) => void; }; } -interface ExperimentalOptions { - /** - * Whether to use Node's experimental async hooks. - * @default false - */ - asyncHooks?: boolean; -} - -interface PluginOptions { - /** - * The service name to be used for this plugin. - */ - service: string; -} +interface ExperimentalOptions {} interface TraceOptions { /** @@ -185,3 +175,65 @@ declare class Scope { */ close(): void; } + +type Plugin = + | "amqp10" + | "amqplib" + | "elasticsearch" + | "express" + | "graphql" + | "http" + | "mongodb-core" + | "mysql" + | "mysql2" + | "pg" + | "redis"; + +interface BasePluginOptions { + /** + * The service name to be used for this plugin. + */ + service?: string; +} + +interface ExpressPluginOptions extends BasePluginOptions { + /** + * An array of headers to include in the span metadata. + */ + headers?: string[]; + + /** + * Callback function to determine if there was an error. It should take a + * status code as its only parameter and return `true` for success or `false` + * for errors. + */ + validateStatus?: (code: number) => boolean; +} + +interface GraphQLPluginOptions extends BasePluginOptions { + /** + * The maximum depth of fields/resolvers to instrument. Set to `0` to only + * instrument the operation or to -1 to instrument all fields/resolvers. + */ + depth?: number; + + /** + * A callback to enable recording of variables. By default, no variables are + * recorded. For example, using `variables => variables` would record all + * variables. + */ + variables?: (variables: T) => Partial; +} + +interface HTTPPluginOptions extends BasePluginOptions { + /** + * Use the remote endpoint host as the service name instead of the default. + */ + splitByDomain?: boolean; +} + +type PluginConfiguration = { [K in Plugin]: BasePluginOptions } & { + express: ExpressPluginOptions; + graphql: GraphQLPluginOptions; + http: HTTPPluginOptions; +}; From 18a16839b0b1e9e9ca3811ac0867322b49998b70 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Eloy=20Dur=C3=A1n?= Date: Wed, 19 Sep 2018 13:22:41 +0200 Subject: [PATCH 2/3] [dd-trace] Require TS 2.1 --- types/dd-trace/index.d.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/types/dd-trace/index.d.ts b/types/dd-trace/index.d.ts index db1c5cf352..53f1884e08 100644 --- a/types/dd-trace/index.d.ts +++ b/types/dd-trace/index.d.ts @@ -3,6 +3,7 @@ // Definitions by: Colin Bradley // Eloy Durán // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped +// TypeScript Version: 2.1 // Prettified with: // $ prettier --parser typescript --tab-width 4 --semi --trailing-comma es5 --write --print-width 120 types/dd-trace/{,*}/*.ts* From b11d8d41e01f9536a0a6a7f7ecd812f84e65086a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Eloy=20Dur=C3=A1n?= Date: Thu, 27 Sep 2018 13:52:00 +0200 Subject: [PATCH 3/3] [dd-trace] Update for v0.6.0 release. --- types/dd-trace/dd-trace-tests.ts | 14 ++++++++------ types/dd-trace/index.d.ts | 22 +++++++++++++++++++--- types/dd-trace/tslint.json | 7 ++++++- 3 files changed, 33 insertions(+), 10 deletions(-) diff --git a/types/dd-trace/dd-trace-tests.ts b/types/dd-trace/dd-trace-tests.ts index 0f6ac97630..8169358155 100644 --- a/types/dd-trace/dd-trace-tests.ts +++ b/types/dd-trace/dd-trace-tests.ts @@ -11,11 +11,13 @@ tracer.init({ }, }); -tracer.use("express", { - service: "incoming-request", - headers: ["User-Agent"], - validateStatus: code => code !== 418, -}); +function useWebFrameworkPlugin(plugin: "express" | "hapi" | "koa" | "restify") { + tracer.use(plugin, { + service: "incoming-request", + headers: ["User-Agent"], + validateStatus: code => code !== 418, + }); +} tracer.use("graphql", { depth: 1, @@ -31,7 +33,7 @@ tracer.use("http", { tracer .trace("web.request", { service: "my_service", - childOf: new SpanContext({ traceId: 1337, spanId: 42 }), // Childof must be an instance of this type. See: https://github.com/DataDog/dd-trace-js/blob/master/src/opentracing/tracer.js#L99 + childOf: new SpanContext({ traceId: 1337, spanId: 42 }), // childOf must be an instance of this type. See: https://github.com/DataDog/dd-trace-js/blob/master/src/opentracing/tracer.js#L99 tags: { env: "dev", }, diff --git a/types/dd-trace/index.d.ts b/types/dd-trace/index.d.ts index 53f1884e08..90aa9afc66 100644 --- a/types/dd-trace/index.d.ts +++ b/types/dd-trace/index.d.ts @@ -3,7 +3,7 @@ // Definitions by: Colin Bradley // Eloy Durán // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped -// TypeScript Version: 2.1 +// TypeScript Version: 2.4 // Prettified with: // $ prettier --parser typescript --tab-width 4 --semi --trailing-comma es5 --write --print-width 120 types/dd-trace/{,*}/*.ts* @@ -183,12 +183,17 @@ type Plugin = | "elasticsearch" | "express" | "graphql" + | "hapi" | "http" + | "ioredis" + | "koa" + | "memcached" | "mongodb-core" | "mysql" | "mysql2" | "pg" - | "redis"; + | "redis" + | "restify"; interface BasePluginOptions { /** @@ -197,7 +202,7 @@ interface BasePluginOptions { service?: string; } -interface ExpressPluginOptions extends BasePluginOptions { +interface BaseWebFrameworkPluginOptions extends BasePluginOptions { /** * An array of headers to include in the span metadata. */ @@ -211,6 +216,14 @@ interface ExpressPluginOptions extends BasePluginOptions { validateStatus?: (code: number) => boolean; } +interface ExpressPluginOptions extends BaseWebFrameworkPluginOptions {} + +interface HapiPluginOptions extends BaseWebFrameworkPluginOptions {} + +interface KoaPluginOptions extends BaseWebFrameworkPluginOptions {} + +interface RestifyPluginOptions extends BaseWebFrameworkPluginOptions {} + interface GraphQLPluginOptions extends BasePluginOptions { /** * The maximum depth of fields/resolvers to instrument. Set to `0` to only @@ -236,5 +249,8 @@ interface HTTPPluginOptions extends BasePluginOptions { type PluginConfiguration = { [K in Plugin]: BasePluginOptions } & { express: ExpressPluginOptions; graphql: GraphQLPluginOptions; + hapi: HapiPluginOptions; http: HTTPPluginOptions; + koa: KoaPluginOptions; + restify: RestifyPluginOptions; }; diff --git a/types/dd-trace/tslint.json b/types/dd-trace/tslint.json index 3db14f85ea..4f44991c3c 100644 --- a/types/dd-trace/tslint.json +++ b/types/dd-trace/tslint.json @@ -1 +1,6 @@ -{ "extends": "dtslint/dt.json" } +{ + "extends": "dtslint/dt.json", + "rules": { + "no-empty-interface": false + } +}