npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

shimo-jaeger-client

v3.7.3

Published

Jaeger binding for OpenTracing Node

Downloads

3

Readme

Build Status Coverage Status NPM Published Version OpenTracing 1.0 Enabled

Jaeger Bindings for Javascript OpenTracing API

This is Jaeger's client side instrumentation library for Node.js that implements Javascript OpenTracing API 1.0.

Contributing and Developing

Please see CONTRIBUTING.md.

Installation

npm install --save jaeger-client

Initialization

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'
};
var options = {
  'tags': {
    'my-awesome-service.version': '1.1.2'
  },
  'metrics': metrics,
  'logger': logger
};
var tracer = initTracer(config, options);

Usage

The Tracer instance created by initTracer is OpenTracing-1.0 compliant. See opentracing-javascript for usage examples.

TChannel Span Bridging

Because tchannel-node does not have instrumentation for OpenTracing, Jaeger-Client exposes methods wrapping tchannel handlers, and encoded channels. An encoded channel is a channel wrapped in either a thrift encoder TChannelAsThrift, or json encoder TChannelAsJson. To wrap a server handler for thrift one can initialize a tchannel bridge, and wrap the encoded handler function with a tracedHandler decorator. The tchannel bridge takes an OpenTracing tracer, and a context factory. The context factory must be a function that returns a context with the methods 'getSpan', and 'setSpan' which retrieve and assign the span to the context respectively.

import { TChannelBridge } from 'jaeger-client';
import Context from 'some-conformant-context';

function contextFactory() {
    return new Context();
};

let bridge = new TChannelBridge(tracer, {contextFactory: contextFactory});
let server = new TChannel({ serviceName: 'server' });
server.listen(4040, '127.0.0.1');
let serverThriftChannel = TChannelAsThrift({
    channel: server,
    entryPoint: path.join(__dirname, 'thrift', 'echo.thrift') // file path to a thrift file
});

let perProcessOptions = {};
serverThriftChannel.register(server, 'Echo::echo', perProcessOptions, bridge.tracedHandler(
    (perProcessOptions, req, head, body, callback) => {
        /* Your handler code goes here. */
    }
));

Outbound calls can be made in two ways, shown below.

Using encoded channel to create a request and calling request.send()

import { TChannelBridge } from 'jaeger-client';

let bridge = new TChannelBridge(tracer);
// Create the toplevel client channel.
let client = new TChannel();

// Create the client subchannel that makes requests.
let clientSubChannel = client.makeSubChannel({
    serviceName: 'server',
    peers: ['127.0.0.1:4040']
});

let encodedThriftChannel = TChannelAsThrift({
    channel: clientSubChannel,
    entryPoint: path.join(__dirname, 'thrift', 'echo.thrift') // file path to a thrift file
});

// wrap encodedThriftChannel in a tracing decorator
let tracedChannel = bridge.tracedChannel(encodedThriftChannel);

// The encodedThriftChannel's (also true for json encoded channels) request object can call 'send' directly.
let req = tracedChannel.request({
    serviceName: 'server',
    context: context, // must be passed through from the service handler shown above
    headers: { cn: 'echo' }
});

// headers should contain your outgoing tchannel headers if any.
// In this instance 'send' is being called on the request object, and not the channel.
req.send('Echo::echo', headers, { value: 'some-string' });

Using top level channel to create a request and calling encodedChannel.send(request)

let tracedChannel = bridge.tracedChannel(encodedThriftChannel);

// tracedChannel.channel refers to encodedThriftChannel's inner channel which
// is clientSubChannel in this instance.
let req = tracedChannel.channel.request({
    serviceName: 'server',
    headers: { cn: 'echo' },
    context: context, // must be passed through from the service handler shown above
    timeout: someTimeout,
});
// send() can be called directly on the tracing decorator
tracedChannel.send(req, 'Echo::echo', o.headers, { value: 'some-string' }, clientCallback);

Debug Traces (Forced Sampling)

Programmatically

The OpenTracing API defines a sampling.priority standard tag that can be used to affect the sampling of a span and its children:

span.setTag(opentracing_tags.SAMPLING_PRIORITY, 1);

Via HTTP Headers

Jaeger Tracer also understands a special HTTP Header jaeger-debug-id, which can be set in the incoming request, e.g.

curl -H "jaeger-debug-id: some-correlation-id" http://myhost.com

When Jaeger sees this header in the request that otherwise has no tracing context, it ensures that the new trace started for this request will be sampled in the "debug" mode (meaning it should survive all downsampling that might happen in the collection pipeline), and the root span will have a tag as if this statement was executed:

span.setTag("jaeger-debug-id", "some-correlation-id");

This allows using Jaeger UI to find the trace by this tag.

Zipkin Compatibility

Support for Zipkin's B3 Propagation HTTP headers is provided by the ZipkinB3TextMapCodec, which can be configured instead of the default TextMapCodec.

The new codec can be used by registering it with a tracer instance as both an injector and an extractor:

let codec = new ZipkinB3TextMapCodec({ urlEncoding: true });

tracer.registerInjector(opentracing.FORMAT_HTTP_HEADERS, codec);
tracer.registerExtractor(opentracing.FORMAT_HTTP_HEADERS, codec);

This can prove useful when compatibility with existing Zipkin tracing/instrumentation is desired.

License

Apache 2.0 License.