add types of zipkin-context-cls, zipkin-instrumentation-express, zipk… (#22998)

* add types of zipkin-context-cls, zipkin-instrumentation-express, zipkin-instrumentation-fetch, zipkin-transport-http

* fix: CI failure because express require typescript 2.2

* fix: test zipkin-context-cls only, remove irrelevant test code
This commit is contained in:
York Yao
2018-01-18 07:15:59 -08:00
committed by Andy
parent 7742f42ef1
commit 6caa94a7a4
20 changed files with 251 additions and 0 deletions
+16
View File
@@ -0,0 +1,16 @@
// Type definitions for zipkin-context-cls 0.11
// Project: https://github.com/openzipkin/zipkin-js#readme
// Definitions by: York Yao <https://github.com/plantain-00>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
import { Context, TraceId } from 'zipkin';
declare class CLSContext implements Context<any> {
setContext(ctx: TraceId): void;
getContext(): TraceId;
scoped<V>(callback: () => V): V;
letContext<V>(ctx: TraceId, callback: () => V): V;
constructor(name: string)
}
export = CLSContext;
+6
View File
@@ -0,0 +1,6 @@
{
"private": true,
"dependencies": {
"zipkin": "^0.11.2"
}
}
+23
View File
@@ -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"
]
}
+1
View File
@@ -0,0 +1 @@
{ "extends": "dtslint/dt.json" }
@@ -0,0 +1,9 @@
import {
Tracer,
BatchRecorder,
jsonEncoder,
} from 'zipkin';
import CLSContext = require('zipkin-context-cls');
const ctxImpl = new CLSContext('zipkin');
+14
View File
@@ -0,0 +1,14 @@
// Type definitions for zipkin-instrumentation-express 0.11
// Project: https://github.com/openzipkin/zipkin-js#readme
// Definitions by: York Yao <https://github.com/plantain-00>
// 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;
@@ -0,0 +1,6 @@
{
"private": true,
"dependencies": {
"zipkin": "^0.11.2"
}
}
@@ -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"
]
}
@@ -0,0 +1 @@
{ "extends": "dtslint/dt.json" }
@@ -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 }));
+16
View File
@@ -0,0 +1,16 @@
// Type definitions for zipkin-instrumentation-fetch 0.11
// Project: https://github.com/openzipkin/zipkin-js#readme
// Definitions by: York Yao <https://github.com/plantain-00>
// 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;
@@ -0,0 +1,6 @@
{
"private": true,
"dependencies": {
"zipkin": "^0.11.2"
}
}
@@ -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"
]
}
@@ -0,0 +1 @@
{ "extends": "dtslint/dt.json" }
@@ -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 });
+18
View File
@@ -0,0 +1,18 @@
// Type definitions for zipkin-transport-http 0.11
// Project: https://github.com/openzipkin/zipkin-js#readme
// Definitions by: York Yao <https://github.com/plantain-00>
// 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)
}
+6
View File
@@ -0,0 +1,6 @@
{
"private": true,
"dependencies": {
"zipkin": "^0.11.2"
}
}
+23
View File
@@ -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"
]
}
+1
View File
@@ -0,0 +1 @@
{ "extends": "dtslint/dt.json" }
@@ -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'
});