在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
开源软件名称:opentracing/opentracing-javascript开源软件地址:https://github.com/opentracing/opentracing-javascript开源编程语言:TypeScript 97.3%开源软件介绍:OpenTracing API for JavaScriptThis library is a JavaScript implementation of Open Tracing API. It is intended for use both on the server and in the browser. Required ReadingTo fully understand this platform API, it's helpful to be familiar with the OpenTracing project and terminology more specifically. Quick StartInstall the package using npm install --save opentracing ExampleThe package contains an example using a naive npm run example The output should look something like:
Code snippetIn your JavaScript code, add instrumentation to the operations to be tracked. This is composed primarily of using "spans" around operations of interest and adding log statements to capture useful data relevant to those operations. const http = require('http');
const opentracing = require('opentracing');
// NOTE: the default OpenTracing tracer does not record any tracing information.
// Replace this line with the tracer implementation of your choice.
const tracer = new opentracing.Tracer();
const span = tracer.startSpan('http_request');
const opts = {
host : 'example.com',
method: 'GET',
port : '80',
path: '/',
};
http.request(opts, res => {
res.setEncoding('utf8');
res.on('error', err => {
// assuming no retries, mark the span as failed
span.setTag(opentracing.Tags.ERROR, true);
span.log({'event': 'error', 'error.object': err, 'message': err.message, 'stack': err.stack});
span.finish();
});
res.on('data', chunk => {
span.log({'event': 'data_received', 'chunk_length': chunk.length});
});
res.on('end', () => {
span.log({'event': 'request_end'});
span.finish();
});
}).end(); As noted in the source snippet, the default behavior of the const CustomTracer = require('tracing-implementation-of-your-choice');
const tracer = new CustomTracer(); Usage in the browserThe package contains two bundles built with webpack that can be included using a standard
Usage with TypeScriptSince the source is written in TypeScript, if you are using TypeScript, you can just Global tracerThe library also provides a global singleton tracer for convenience. This can be set and accessed via the following: opentracing.initGlobalTracer(new CustomTracer());
const tracer = opentracing.globalTracer(); Note: API DocumentationThere is a hosted copy of the current generated ESDoc API Documentation here. Contributing & developer informationSee the OpenTracing website for general information on contributing to OpenTracing. The project is written in TypeScript and built using a npm scripts. Run:
Note: The minimum supported Node version for development is OpenTracing tracer implementationsThis section is intended for developers wishing to implement their own tracers. Developers who simply wish to use OpenTracing can safely ignore this information. Custom tracer implementationImplementations can subclass API compatibility testingIf const apiCompatibilityChecks = require('opentracing/lib/test/api_compatibility.js').default;
apiCompatibilityChecks(() => new CustomTracer()); LICENSEApache License 2.0 MockTracerA minimal example tracer is provided in the |
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论