From c32a8c515db9022c6521d2c35eb006dd723e79f2 Mon Sep 17 00:00:00 2001 From: rochdev Date: Fri, 22 Feb 2019 13:28:25 -0500 Subject: [PATCH] move dd-trace types to official repository --- notNeededPackages.json | 6 + types/dd-trace/dd-trace-tests.ts | 56 ---- types/dd-trace/index.d.ts | 275 ------------------ types/dd-trace/package.json | 6 - .../src/opentracing/span_context.d.ts | 28 -- types/dd-trace/tsconfig.json | 23 -- types/dd-trace/tslint.json | 6 - 7 files changed, 6 insertions(+), 394 deletions(-) delete mode 100644 types/dd-trace/dd-trace-tests.ts delete mode 100644 types/dd-trace/index.d.ts delete mode 100644 types/dd-trace/package.json delete mode 100644 types/dd-trace/src/opentracing/span_context.d.ts delete mode 100644 types/dd-trace/tsconfig.json delete mode 100644 types/dd-trace/tslint.json diff --git a/notNeededPackages.json b/notNeededPackages.json index 1521fd7426..6a91dbd943 100644 --- a/notNeededPackages.json +++ b/notNeededPackages.json @@ -396,6 +396,12 @@ "sourceRepoURL": "https://github.com/date-fns/date-fns", "asOfVersion": "2.6.0" }, + { + "libraryName": "dd-trace", + "typingsPackageName": "dd-trace", + "sourceRepoURL": "https://github.com/DataDog/dd-trace-js", + "asOfVersion": "0.9.0" + }, { "libraryName": "decimal.js", "typingsPackageName": "decimal.js", diff --git a/types/dd-trace/dd-trace-tests.ts b/types/dd-trace/dd-trace-tests.ts deleted file mode 100644 index cee1b6e3ee..0000000000 --- a/types/dd-trace/dd-trace-tests.ts +++ /dev/null @@ -1,56 +0,0 @@ -import * as tracer from "dd-trace"; -import SpanContext = require("dd-trace/src/opentracing/span_context"); - -tracer.init({ - enabled: true, - service: "MyLovelyService", - hostname: "localhost", - port: 8126, - env: "dev", - logger: { - debug: msg => {}, - error: err => {}, - } -}); - -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, - // 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", - 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", - }, - }) - .then(span => { - span.setTag("my_tag", "my_value"); - span.finish(); - }); - -const parentScope = tracer.scopeManager().active(); -const span = tracer.startSpan("memcached", { - childOf: parentScope && parentScope.span(), - tags: { - "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 deleted file mode 100644 index a55b7f8de7..0000000000 --- a/types/dd-trace/index.d.ts +++ /dev/null @@ -1,275 +0,0 @@ -// Type definitions for dd-trace-js 0.7 -// Project: https://github.com/DataDog/dd-trace-js -// Definitions by: Colin Bradley -// Eloy Durán -// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped -// TypeScript Version: 2.4 - -// 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"); - -declare var trace: TraceProxy; -export = trace; - -declare class TraceProxy extends Tracer { - /** - * Initializes the tracer. This should be called before importing other libraries. - */ - init(options?: TracerOptions): this; - - /** - * Enable and optionally configure a plugin. - * @param plugin The name of a built-in plugin. - * @param config Configuration options. - */ - use

(plugin: P, config: PluginConfiguration[P]): this; - - /** - * Initiate a trace and creates a new span. - * @param operationName The operation name to be used for this span. - * @param options Configuration options. These will take precedence over environment variables. - */ - trace(operationName: string, options: TraceOptions): Promise; - - /** - * Initiate a trace and creates a new span. - * @param operationName The operation name to be used for this span. - * @param options Configuration options. These will take precedence over environment variables. - */ - trace(operationName: string, options: TraceOptions, callback: (span: Span) => void): void; - - /** - * Get the span from the current context. - * @returns The current span or null if outside a trace context. - */ - currentSpan(): Span | null; - - /** - * Get the scope manager to manager context propagation for the tracer. - */ - scopeManager(): ScopeManager; -} - -interface TracerOptions { - /** - * Whether to enable the tracer. - * @default true - */ - enabled?: boolean; - - /** - * Enable debug logging in the tracer. - * @default false - */ - debug?: boolean; - - /** - * The service name to be used for this program. - */ - service?: string; - - /** - * The address of the trace agent that the tracer will submit to. - * @default 'localhost' - */ - hostname?: string; - - /** - * The port of the trace agent that the tracer will submit to. - * @default 8126 - */ - port?: number | string; - - /** - * Set an application’s environment e.g. prod, pre-prod, stage. - */ - env?: string; - - /** - * Percentage of spans to sample as a float between 0 and 1. - * @default 1 - */ - sampleRate?: number; - - /** - * Interval in milliseconds at which the tracer will submit traces to the agent. - * @default 2000 - */ - flushInterval?: number; - - /** - * Experimental features can be enabled all at once by using true or individually using key / value pairs. - * @default {} - */ - experimental?: ExperimentalOptions | boolean; - - /** - * Whether to load all built-in plugins. - * @default true - */ - plugins?: boolean; - - /** - * Custom logger to be used by the tracer (if debug = true), - * should support debug() and error() methods - * see https://datadog.github.io/dd-trace-js/#custom-logging__anchor - */ - logger?: { - debug: (message: string) => void; - error: (err: Error) => void; - }; - - /** - * Global tags that should be assigned to every span. - */ - tags?: { [key: string]: any }; -} - -interface ExperimentalOptions {} - -interface TraceOptions { - /** - * The service name to be used for this span. - * The service name from the tracer will be used if this is not provided. - */ - service?: string; - - /** - * The resource name to be used for this span. - * The operation name will be used if this is not provided. - */ - resource?: string; - - /** - * The span type to be used for this span. - */ - type?: string; - - /** - * The parent span or span context for the new span. Generally this is not needed as it will be - * fetched from the current context. - * If creating your own, this must be an instance of DatadogSpanContext from ./src/opentracing/span_context - * See: https://github.com/DataDog/dd-trace-js/blob/master/src/opentracing/tracer.js#L99 - */ - childOf?: Span | SpanContext | DatadogSpanContext; - - /** - * Global tags that should be assigned to every span. - */ - tags?: { [key: string]: any } | string; -} - -declare class ScopeManager { - /** - * Get the current active scope or null if there is none. - * - * @todo The dd-trace source returns null, but opentracing's childOf span - * option is typed as taking undefined or a scope, so using undefined - * here instead. - */ - active(): Scope | undefined; - - /** - * Activate a new scope wrapping the provided span. - * - * @param span The span for which to activate the new scope. - * @param finishSpanOnClose Whether to automatically finish the span when the scope is closed. - */ - activate(span: Span, finishSpanOnClose?: boolean): Scope; -} - -declare class Scope { - /** - * Get the span wrapped by this scope. - */ - span(): Span; - - /** - * Close the scope, and finish the span if the scope was created with `finishSpanOnClose` set to true. - */ - close(): void; -} - -type Plugin = - | "amqp10" - | "amqplib" - | "bluebird" - | "elasticsearch" - | "express" - | "graphql" - | "hapi" - | "http" - | "ioredis" - | "koa" - | "memcached" - | "mongodb-core" - | "mysql" - | "mysql2" - | "pg" - | "q" - | "redis" - | "restify" - | "when"; - -interface BasePluginOptions { - /** - * The service name to be used for this plugin. - */ - service?: string; -} - -interface BaseWebFrameworkPluginOptions 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 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 - * 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; - hapi: HapiPluginOptions; - http: HTTPPluginOptions; - koa: KoaPluginOptions; - restify: RestifyPluginOptions; -}; diff --git a/types/dd-trace/package.json b/types/dd-trace/package.json deleted file mode 100644 index 90deb3c97b..0000000000 --- a/types/dd-trace/package.json +++ /dev/null @@ -1,6 +0,0 @@ -{ - "private": true, - "dependencies": { - "opentracing": ">=0.14.1" - } -} diff --git a/types/dd-trace/src/opentracing/span_context.d.ts b/types/dd-trace/src/opentracing/span_context.d.ts deleted file mode 100644 index 7e2b06dd4d..0000000000 --- a/types/dd-trace/src/opentracing/span_context.d.ts +++ /dev/null @@ -1,28 +0,0 @@ -import { SpanContext } from 'opentracing'; - -declare class DatadogSpanContext extends SpanContext { - /** - * Used to create references to parent spans. - * See: https://github.com/DataDog/dd-trace-js/blob/master/src/opentracing/tracer.js#L99 - */ - constructor(props: SpanContextLike); -} - -interface SpanContextLike { - traceId: number; - - spanId: number; - - parentId?: number | null; - - sampled?: boolean; - - baggageItems?: { [key: string]: string }; - - trace?: { - started: number[], - finished: number[] - }; -} - -export = DatadogSpanContext; diff --git a/types/dd-trace/tsconfig.json b/types/dd-trace/tsconfig.json deleted file mode 100644 index 6e65e3983c..0000000000 --- a/types/dd-trace/tsconfig.json +++ /dev/null @@ -1,23 +0,0 @@ -{ - "compilerOptions": { - "module": "commonjs", - "lib": [ - "es6" - ], - "noImplicitAny": true, - "noImplicitThis": true, - "strictNullChecks": true, - "strictFunctionTypes": true, - "baseUrl": "../", - "typeRoots": [ - "../" - ], - "types": [], - "noEmit": true, - "forceConsistentCasingInFileNames": true - }, - "files": [ - "index.d.ts", - "dd-trace-tests.ts" - ] -} \ No newline at end of file diff --git a/types/dd-trace/tslint.json b/types/dd-trace/tslint.json deleted file mode 100644 index 4f44991c3c..0000000000 --- a/types/dd-trace/tslint.json +++ /dev/null @@ -1,6 +0,0 @@ -{ - "extends": "dtslint/dt.json", - "rules": { - "no-empty-interface": false - } -}