zipkin-instrumentation-typeorm

Typeorm db connection for instrumentation with Zipkin.js

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.Traceror 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));

Repository

https://github.com/niklaus0823/zipkin-instrumentation-typeorm


上一篇:zonetk-core
下一篇:typeorm

相关推荐

  • 个推基于Zipkin的分布式链路追踪实践

    (https://img.javascriptcn.com/48b1e65f01c11ef06554e4aef03d7e50) 作者:个推应用平台基础架构高级研发工程师 阿飞 01业务背景 随着微...

    1 年前
  • zipkin-transport-http

    Transports Zipkin trace data via HTTP Zipkintransporthttp npm(https://img.shields.io/npm/dm/zipk...

    4 个月前
  • zipkin

    The core tracer for Zipkin JS zipkin This is the core npm package for Zipkin. It contains the pub...

    4 个月前
  • typeorm

    DataMapper ORM for TypeScript, ES7, ES6, ES5. Supports MySQL, PostgreSQL, MariaDB, SQLite, MS SQL Se...

    7 个月前
  • NestJs学习记录(1)- Typeorm的使用

    背景 最近在学习NestJs,但是不从实际需求出发,没有项目的依托,感觉总是个入门而已,只有在解决一个个项目上的问题才能进一步加深和巩固所学知识,故想将搭建一个博客后台系统的需求为出发点,巩固所学知识...

    3 个月前
  • @steedos/odata-v4-typeorm

    OData to TYPEORM query compiler OData V4 Service modules TYPEORM Connector Service OData v4 requ...

    3 个月前
  • @nestjs/typeorm

    Nest modern, fast, powerful node.js web framework (@typeorm) travisimage: https://api.travis...

    4 个月前
  • @brunnerlivio/typeorm

    DataMapper ORM for TypeScript, ES7, ES6, ES5. Supports MySQL, PostgreSQL, MariaDB, SQLite, MS SQL Se...

    3 个月前
  • @accounts/typeorm

    TypeORM adaptor for accounts @accounts/typeorm TypeORM adaptor for accounts npm(https://img.shie...

    4 个月前

官方社区

扫码加入 JavaScript 社区