sasdn-middleware-grpc-zipkin
v0.1.5
Published
SASDN middleware for grpc instrumentation with Zipkin.js
Downloads
4
Readme
sasdn-middleware-grpc-zipkin
SASDN middleware for grpc instrumentation that adds Zipkin tracing to the application.
Install
$ npm install --save sasdn-middleware-grpc-zipkin
API
middleware([info])
info
tracer
Type: zipkin.Tracer
or false
Default: false
serviceName
Type: string
Default: unknown
port
Type: number
Default: 0
proxyClient([client], [info], [ctx])
client
Type: grpc.Client
info
tracer
Type: zipkin.Tracer
or false
Default: false
serviceName
Type: string
Default: unknown
remoteServiceName
Type: string
Default: unknown
port
Type: number
Default: 0
ctx
Type: object
Example: ctx[zipkin.HttpHeaders.TraceId] = new zipkin.TraceId();
Examples
SASDN Grpc Middleware
import {RpcApplication} from 'sasdn';
import {Tracer, ExplicitContext, ConsoleRecorder} from 'zipkin';
import {GrpcInstrumentation} from '../index';
const tracer = new Tracer({
ctxImpl: new ExplicitContext(),
recorder: new ConsoleRecorder()
});
const app = new RpcApplication();
// Add the Zipkin middleware
app.use(GrpcInstrumentation.middleware({tracer}));
Grpc Client Proxy
This library will wrap grpc client proxy to add metadata and record traces.
import * as grpc from 'grpc';
import {GatewayContext, RpcContext} from 'sasdn';
import {GrpcInstrumentation} from '../index';
import {Tracer, ExplicitContext, ConsoleRecorder} from 'zipkin';
import {OrderServiceClient} from './proto/order/order_grpc_pb';
const tracer = new Tracer({
ctxImpl: new ExplicitContext(),
recorder: new ConsoleRecorder()
});
export default class GrpcClientOrder {
public client: OrderServiceClient;
constructor(ctx?: GatewayContext | RpcContext) {
this.client = GrpcInstrumentation.proxyClient(
new OrderServiceClient('127.0.0.1:9090', grpc.credentials.createInsecure()),
{tracer},
ctx,
);
}
}