@3rdi/fastify-jaeger-middleware 中文文档教程

发布于 6年前 浏览 27 项目主页 更新于 3年前

fastify-jaeger-middleware

Install

npm i @3rdi/fastify-jaeger-middleware --save

Usage

首先按照 https://github.com/jaegertracing/jaeger-client-node 中的指南创建一个 jaeger 跟踪器

var initTracer = require('jaeger-client').initTracer;

// See schema https://github.com/jaegertracing/jaeger-client-node/blob/master/src/configuration.js#L37
var config = {
  serviceName: 'my-awesome-service',
  reporter: {
    // Provide the traces endpoint; this forces the client to connect directly to the Collector and send
    // spans over HTTP
    collectorEndpoint: 'http://jaeger-collector:14268/api/traces',
    // Provide username and password if authentication is enabled in the Collector
    // username: '',
    // password: '',
  },
};
var options = {
  tags: {
    'my-awesome-service.version': '1.1.2',
  },
  metrics: metrics,
  logger: logger,
};
var tracer = initTracer(config, options);

然后注册中间件并使用跟踪器实例化它。

const jaegerMiddleware = require('@3rdi/fastify-jaeger-middleware');

 fastify.register(jaegerMiddleware, { tracer: jaegerTracer });

这会给你一个像这样的 jaeger 报告。

alt text

License

麻省理工学院

fastify-jaeger-middleware

Install

npm i @3rdi/fastify-jaeger-middleware --save

Usage

First create a jaeger tracer by following the guide from https://github.com/jaegertracing/jaeger-client-node

var initTracer = require('jaeger-client').initTracer;

// See schema https://github.com/jaegertracing/jaeger-client-node/blob/master/src/configuration.js#L37
var config = {
  serviceName: 'my-awesome-service',
  reporter: {
    // Provide the traces endpoint; this forces the client to connect directly to the Collector and send
    // spans over HTTP
    collectorEndpoint: 'http://jaeger-collector:14268/api/traces',
    // Provide username and password if authentication is enabled in the Collector
    // username: '',
    // password: '',
  },
};
var options = {
  tags: {
    'my-awesome-service.version': '1.1.2',
  },
  metrics: metrics,
  logger: logger,
};
var tracer = initTracer(config, options);

Then register the middleware and instantiate this with the tracer.

const jaegerMiddleware = require('@3rdi/fastify-jaeger-middleware');

 fastify.register(jaegerMiddleware, { tracer: jaegerTracer });

This will give you a report in jaeger like this.

alt text

License

Licensed under MIT.

    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文