0.1.5 • Published 7 years ago

sasdn-middleware-grpc-zipkin v0.1.5

Weekly downloads
3
License
MIT
Repository
github
Last release
7 years ago

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: ctxzipkin.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,
        );
    }
}
0.1.5

7 years ago

0.1.4

7 years ago

0.1.3

7 years ago

0.1.2

7 years ago

0.1.1

7 years ago

0.0.6

7 years ago