zipkin-instrumentation-typeorm

2019-12-04

zipkin-instrumentation-typeorm是什么

什么是zipkin-instrumentation-typeorm,Typeorm db connection for instrumentation with Zipkin.js

zipkin-instrumentation-typeorm使用教程帮助文档

typeorm

Typeorm db connection and instrumentation that adds Zipkin tracing to the application.

Install

$ npm install --save zipkin-instrumentation-typeorm

API

proxyConnection([conn], [info], [ctx])

conn

Type: typeorm.SelectQueryBuilder

Allows to build complex sql queries in a fashion way and execute those queries.

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

Typeorm DB Connection Proxy

This library will wrap grpc client proxy to record traces.

import * as zipkin from 'zipkin';
import {TypeOrmInstrumentation} from '../index';
import {User as UserEntity} from './entity/User';
import {Entity, createConnection} from 'typeorm';

// build entities
const entities = [];
entities.push({UserEntity: UserEntity});

// create zipkin Tracer
const tracer = new zipkin.Tracer({
    ctxImpl: new zipkin.ExplicitContext(),
    recorder: new zipkin.ConsoleRecorder()
});

async function getUser(): Promise<UserEntity> {
    const conn = await createConnection({
        type: 'sqlite',
        database: './User.db',
        entities: entities,
    });

    const proxyConn = TypeOrmInstrumentation.proxyConnection(conn, {tracer});

    return await proxyConn.getRepository(UserEntity)
        .createQueryBuilder('user')
        .where(`user.id=:id`, {id: '1000'})
        .getOne();
}

getUser()
    .then(res => console.log(res))
    .catch(err => console.log(err));

上一篇:zonetk-core
下一篇:typeorm
相关文章

首次访问,人机识别验证

扫描下方二维码回复 1024 获取验证码,验证完毕后 永久 无须验证

操作步骤:[打开微信]->[扫描上侧二维码]->[关注 FedJavaScript 的微信] 输入 1024 获取验证码

验证码有误,请重新输入