diff --git a/types/zipkin-context-cls/index.d.ts b/types/zipkin-context-cls/index.d.ts new file mode 100644 index 0000000000..df1b9f57aa --- /dev/null +++ b/types/zipkin-context-cls/index.d.ts @@ -0,0 +1,16 @@ +// Type definitions for zipkin-context-cls 0.11 +// Project: https://github.com/openzipkin/zipkin-js#readme +// Definitions by: York Yao +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped + +import { Context, TraceId } from 'zipkin'; + +declare class CLSContext implements Context { + setContext(ctx: TraceId): void; + getContext(): TraceId; + scoped(callback: () => V): V; + letContext(ctx: TraceId, callback: () => V): V; + constructor(name: string) +} + +export = CLSContext; diff --git a/types/zipkin-context-cls/package.json b/types/zipkin-context-cls/package.json new file mode 100644 index 0000000000..371d115490 --- /dev/null +++ b/types/zipkin-context-cls/package.json @@ -0,0 +1,6 @@ +{ + "private": true, + "dependencies": { + "zipkin": "^0.11.2" + } +} diff --git a/types/zipkin-context-cls/tsconfig.json b/types/zipkin-context-cls/tsconfig.json new file mode 100644 index 0000000000..6cd3375b4f --- /dev/null +++ b/types/zipkin-context-cls/tsconfig.json @@ -0,0 +1,23 @@ +{ + "compilerOptions": { + "module": "commonjs", + "lib": [ + "es6" + ], + "noImplicitAny": true, + "noImplicitThis": true, + "strictNullChecks": true, + "strictFunctionTypes": true, + "baseUrl": "../", + "typeRoots": [ + "../" + ], + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true + }, + "files": [ + "index.d.ts", + "zipkin-context-cls-tests.ts" + ] +} diff --git a/types/zipkin-context-cls/tslint.json b/types/zipkin-context-cls/tslint.json new file mode 100644 index 0000000000..3db14f85ea --- /dev/null +++ b/types/zipkin-context-cls/tslint.json @@ -0,0 +1 @@ +{ "extends": "dtslint/dt.json" } diff --git a/types/zipkin-context-cls/zipkin-context-cls-tests.ts b/types/zipkin-context-cls/zipkin-context-cls-tests.ts new file mode 100644 index 0000000000..31168e824b --- /dev/null +++ b/types/zipkin-context-cls/zipkin-context-cls-tests.ts @@ -0,0 +1,9 @@ +import { + Tracer, + BatchRecorder, + jsonEncoder, +} from 'zipkin'; + +import CLSContext = require('zipkin-context-cls'); + +const ctxImpl = new CLSContext('zipkin'); diff --git a/types/zipkin-instrumentation-express/index.d.ts b/types/zipkin-instrumentation-express/index.d.ts new file mode 100644 index 0000000000..ab587b3cae --- /dev/null +++ b/types/zipkin-instrumentation-express/index.d.ts @@ -0,0 +1,14 @@ +// Type definitions for zipkin-instrumentation-express 0.11 +// Project: https://github.com/openzipkin/zipkin-js#readme +// Definitions by: York Yao +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped +// TypeScript Version: 2.2 + +import express = require('express'); +import { Tracer } from 'zipkin'; + +export interface Options { + tracer: Tracer; +} + +export function expressMiddleware(options: Options): express.RequestHandler; diff --git a/types/zipkin-instrumentation-express/package.json b/types/zipkin-instrumentation-express/package.json new file mode 100644 index 0000000000..371d115490 --- /dev/null +++ b/types/zipkin-instrumentation-express/package.json @@ -0,0 +1,6 @@ +{ + "private": true, + "dependencies": { + "zipkin": "^0.11.2" + } +} diff --git a/types/zipkin-instrumentation-express/tsconfig.json b/types/zipkin-instrumentation-express/tsconfig.json new file mode 100644 index 0000000000..8038e5a2cd --- /dev/null +++ b/types/zipkin-instrumentation-express/tsconfig.json @@ -0,0 +1,23 @@ +{ + "compilerOptions": { + "module": "commonjs", + "lib": [ + "es6" + ], + "noImplicitAny": true, + "noImplicitThis": true, + "strictNullChecks": true, + "strictFunctionTypes": true, + "baseUrl": "../", + "typeRoots": [ + "../" + ], + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true + }, + "files": [ + "index.d.ts", + "zipkin-instrumentation-express-tests.ts" + ] +} diff --git a/types/zipkin-instrumentation-express/tslint.json b/types/zipkin-instrumentation-express/tslint.json new file mode 100644 index 0000000000..3db14f85ea --- /dev/null +++ b/types/zipkin-instrumentation-express/tslint.json @@ -0,0 +1 @@ +{ "extends": "dtslint/dt.json" } diff --git a/types/zipkin-instrumentation-express/zipkin-instrumentation-express-tests.ts b/types/zipkin-instrumentation-express/zipkin-instrumentation-express-tests.ts new file mode 100644 index 0000000000..bcfb82ec46 --- /dev/null +++ b/types/zipkin-instrumentation-express/zipkin-instrumentation-express-tests.ts @@ -0,0 +1,12 @@ +import express = require('express'); +import { Tracer, ExplicitContext, ConsoleRecorder } from 'zipkin'; +import { expressMiddleware as zipkinMiddleware } from 'zipkin-instrumentation-express'; + +const ctxImpl = new ExplicitContext(); +const recorder = new ConsoleRecorder(); +const localServiceName = 'service-a'; +const tracer = new Tracer({ ctxImpl, recorder, localServiceName }); + +const app = express(); + +app.use(zipkinMiddleware({ tracer })); diff --git a/types/zipkin-instrumentation-fetch/index.d.ts b/types/zipkin-instrumentation-fetch/index.d.ts new file mode 100644 index 0000000000..b9236c94fa --- /dev/null +++ b/types/zipkin-instrumentation-fetch/index.d.ts @@ -0,0 +1,16 @@ +// Type definitions for zipkin-instrumentation-fetch 0.11 +// Project: https://github.com/openzipkin/zipkin-js#readme +// Definitions by: York Yao +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped + +import { Tracer } from 'zipkin'; +import fetch from 'node-fetch'; + +interface Options { + tracer: Tracer; + remoteServiceName: string; +} + +declare function wrapFetch(rawFetch: typeof fetch, options: Options): typeof fetch; + +export = wrapFetch; diff --git a/types/zipkin-instrumentation-fetch/package.json b/types/zipkin-instrumentation-fetch/package.json new file mode 100644 index 0000000000..371d115490 --- /dev/null +++ b/types/zipkin-instrumentation-fetch/package.json @@ -0,0 +1,6 @@ +{ + "private": true, + "dependencies": { + "zipkin": "^0.11.2" + } +} diff --git a/types/zipkin-instrumentation-fetch/tsconfig.json b/types/zipkin-instrumentation-fetch/tsconfig.json new file mode 100644 index 0000000000..1cf310ea24 --- /dev/null +++ b/types/zipkin-instrumentation-fetch/tsconfig.json @@ -0,0 +1,23 @@ +{ + "compilerOptions": { + "module": "commonjs", + "lib": [ + "es6" + ], + "noImplicitAny": true, + "noImplicitThis": true, + "strictNullChecks": true, + "strictFunctionTypes": true, + "baseUrl": "../", + "typeRoots": [ + "../" + ], + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true + }, + "files": [ + "index.d.ts", + "zipkin-instrumentation-fetch-tests.ts" + ] +} diff --git a/types/zipkin-instrumentation-fetch/tslint.json b/types/zipkin-instrumentation-fetch/tslint.json new file mode 100644 index 0000000000..3db14f85ea --- /dev/null +++ b/types/zipkin-instrumentation-fetch/tslint.json @@ -0,0 +1 @@ +{ "extends": "dtslint/dt.json" } diff --git a/types/zipkin-instrumentation-fetch/zipkin-instrumentation-fetch-tests.ts b/types/zipkin-instrumentation-fetch/zipkin-instrumentation-fetch-tests.ts new file mode 100644 index 0000000000..5790413e0a --- /dev/null +++ b/types/zipkin-instrumentation-fetch/zipkin-instrumentation-fetch-tests.ts @@ -0,0 +1,26 @@ +import wrapFetch = require('zipkin-instrumentation-fetch'); +import fetch from 'node-fetch'; + +import { + Tracer, + BatchRecorder, + jsonEncoder, +} from 'zipkin'; + +import CLSContext = require('zipkin-context-cls'); +import { HttpLogger } from 'zipkin-transport-http'; + +// Setup the tracer to use http and implicit trace context +const tracer = new Tracer({ + ctxImpl: new CLSContext('zipkin'), + recorder: new BatchRecorder({ + logger: new HttpLogger({ + endpoint: 'http://localhost:9411/api/v2/spans', + jsonEncoder: jsonEncoder.JSON_V2 + }) + }), + localServiceName: 'service-a' +}); + +const remoteServiceName = 'youtube'; +const zipkinFetch = wrapFetch(fetch, { tracer, remoteServiceName }); diff --git a/types/zipkin-transport-http/index.d.ts b/types/zipkin-transport-http/index.d.ts new file mode 100644 index 0000000000..2cc34f0893 --- /dev/null +++ b/types/zipkin-transport-http/index.d.ts @@ -0,0 +1,18 @@ +// Type definitions for zipkin-transport-http 0.11 +// Project: https://github.com/openzipkin/zipkin-js#readme +// Definitions by: York Yao +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped + +import { JsonEncoder, Logger, model } from 'zipkin'; + +export interface Options { + endpoint: string; + jsonEncoder?: JsonEncoder; + httpInterval?: number; + headers?: { [name: string]: string }; +} + +export class HttpLogger implements Logger { + logSpan(span: model.Span): void; + constructor(options: Options) +} diff --git a/types/zipkin-transport-http/package.json b/types/zipkin-transport-http/package.json new file mode 100644 index 0000000000..371d115490 --- /dev/null +++ b/types/zipkin-transport-http/package.json @@ -0,0 +1,6 @@ +{ + "private": true, + "dependencies": { + "zipkin": "^0.11.2" + } +} diff --git a/types/zipkin-transport-http/tsconfig.json b/types/zipkin-transport-http/tsconfig.json new file mode 100644 index 0000000000..4f892dbef3 --- /dev/null +++ b/types/zipkin-transport-http/tsconfig.json @@ -0,0 +1,23 @@ +{ + "compilerOptions": { + "module": "commonjs", + "lib": [ + "es6" + ], + "noImplicitAny": true, + "noImplicitThis": true, + "strictNullChecks": true, + "strictFunctionTypes": true, + "baseUrl": "../", + "typeRoots": [ + "../" + ], + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true + }, + "files": [ + "index.d.ts", + "zipkin-transport-http-tests.ts" + ] +} diff --git a/types/zipkin-transport-http/tslint.json b/types/zipkin-transport-http/tslint.json new file mode 100644 index 0000000000..3db14f85ea --- /dev/null +++ b/types/zipkin-transport-http/tslint.json @@ -0,0 +1 @@ +{ "extends": "dtslint/dt.json" } diff --git a/types/zipkin-transport-http/zipkin-transport-http-tests.ts b/types/zipkin-transport-http/zipkin-transport-http-tests.ts new file mode 100644 index 0000000000..4b5b91d218 --- /dev/null +++ b/types/zipkin-transport-http/zipkin-transport-http-tests.ts @@ -0,0 +1,20 @@ +import { + Tracer, + BatchRecorder, + jsonEncoder, +} from 'zipkin'; + +import CLSContext = require('zipkin-context-cls'); +import { HttpLogger } from 'zipkin-transport-http'; + +// Setup the tracer to use http and implicit trace context +const tracer = new Tracer({ + ctxImpl: new CLSContext('zipkin'), + recorder: new BatchRecorder({ + logger: new HttpLogger({ + endpoint: 'http://localhost:9411/api/v2/spans', + jsonEncoder: jsonEncoder.JSON_V2 + }) + }), + localServiceName: 'service-a' +});