Adds type definitions for 'jaeger-client' (#35796)

Adds type definitions and tests
Adds package configuration for external types
Adds tsconfig and tslint config
Adds target Typescript version header to support 'opentracing' external types
This commit is contained in:
jgeth 2019-05-28 14:52:08 -07:00 committed by Sheetal Nandi
parent cec8eb31ac
commit a39cadfd2a
5 changed files with 124 additions and 0 deletions

90
types/jaeger-client/index.d.ts vendored Normal file
View File

@ -0,0 +1,90 @@
// Type definitions for jaeger-client 3.15
// Project: https://github.com/jaegertracing/jaeger-client-node#readme
// Definitions by: jgeth <https://github.com/jgeth>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// TypeScript Version: 2.1
// opentracing requires typescript version ^2.1
import * as opentracing from "opentracing";
import * as prometheus from "prom-client";
// Counter tracks the number of times an event has occurred
export interface Counter {
// Adds the given value to the counter.
increment(delta: number): void;
}
// Gauge returns instantaneous measurements of something as an int64 value
export interface Gauge {
// Update the gauge to the value passed in.
update(value: number): void;
}
export interface Logger {
info(msg: string): void;
error(msg: string): void;
}
export interface MetricsFactory {
createCounter(name: string, tags: any): Counter;
createTimer(name: string, tags: any): Timer;
createGauge(name: string, tags: any): Gauge;
}
export interface Reporter {
// TODO: use span type opentracing.Span from package 'opentracing' which fails DTS linting on import 2019-05-28 jgeth
report(span: opentracing.Span): void;
close(callback?: () => void): void;
setProcess(serviceName: string, tags: any): void;
}
export interface ReporterConfig {
logSpans?: boolean;
agentHost?: string;
agentPort?: number;
flushIntervalMs?: number;
}
export interface SamplerConfig {
type: string;
param: number;
host?: string;
port?: number;
refreshIntervalMs?: number;
}
// Timer tracks how long an operation took and also computes percentiles.
export interface Timer {
// Records the time passed in.
record(value: number): void;
}
export interface TracingConfig {
serviceName?: string;
disable?: boolean;
sampler?: SamplerConfig;
reporter?: ReporterConfig;
}
export interface TracingOptions {
reporter?: Reporter;
metrics?: PrometheusMetricsFactory;
logger?: Logger;
tags?: any;
}
export function initTracer(
tracingConfig: TracingConfig,
tracingOptions: TracingOptions
): opentracing.Tracer;
export function initTracerFromEnv(
tracingConfig: TracingConfig,
tracingOptions: TracingOptions
): opentracing.Tracer;
export class PrometheusMetricsFactory {
constructor(client: typeof prometheus, serviceName: string);
createCounter(name: string, tags: {}): Counter;
createGauge(name: string, tags: {}): Gauge;
}

View File

@ -0,0 +1,10 @@
import * as jaegerClient from "jaeger-client";
import * as promClient from "prom-client";
const tracingConfig: jaegerClient.TracingConfig = {};
const tracingOptions: jaegerClient.TracingOptions = {};
jaegerClient.initTracer(tracingConfig, tracingOptions);
jaegerClient.initTracerFromEnv(tracingConfig, tracingOptions);
const metrics = new jaegerClient.PrometheusMetricsFactory(promClient, "foo");

View File

@ -0,0 +1,7 @@
{
"private": true,
"dependencies": {
"opentracing": "~0.14.3",
"prom-client": "~11.3.0"
}
}

View File

@ -0,0 +1,16 @@
{
"compilerOptions": {
"module": "commonjs",
"lib": ["es6"],
"noImplicitAny": true,
"noImplicitThis": true,
"strictFunctionTypes": true,
"strictNullChecks": true,
"baseUrl": "../",
"typeRoots": ["../"],
"types": [],
"noEmit": true,
"forceConsistentCasingInFileNames": true
},
"files": ["index.d.ts", "jaeger-client-tests.ts"]
}

View File

@ -0,0 +1 @@
{ "extends": "dtslint/dt.json" }