1 | # OpenTelemetry Tracing SDK
|
2 |
|
3 | [![NPM Published Version][npm-img]][npm-url]
|
4 | [![dependencies][dependencies-image]][dependencies-url]
|
5 | [![devDependencies][devDependencies-image]][devDependencies-url]
|
6 | [![Apache License][license-image]][license-image]
|
7 |
|
8 | The `tracing` module contains the foundation for all tracing SDKs of [opentelemetry-js](https://github.com/open-telemetry/opentelemetry-js).
|
9 |
|
10 | Used standalone, this module provides methods for manual instrumentation of code, offering full control over span creation for client-side JavaScript (browser) and Node.js.
|
11 |
|
12 | It does **not** provide automated instrumentation of known libraries, context propagation for asynchronous invocations or distributed-context out-of-the-box.
|
13 |
|
14 | For automated instrumentation for Node.js, please see
|
15 | [@opentelemetry/node](https://github.com/open-telemetry/opentelemetry-js/tree/main/packages/opentelemetry-node).
|
16 |
|
17 | ## Installation
|
18 |
|
19 | ```bash
|
20 | npm install --save @opentelemetry/api
|
21 | npm install --save @opentelemetry/tracing
|
22 | ```
|
23 |
|
24 | ## Usage
|
25 |
|
26 | ```js
|
27 | const opentelemetry = require('@opentelemetry/api');
|
28 | const { BasicTracerProvider } = require('@opentelemetry/tracing');
|
29 |
|
30 | // To start a trace, you first need to initialize the Tracer provider.
|
31 | // NOTE: The default OpenTelemetry tracer provider does not record any tracing information.
|
32 | // Registering a working tracer provider allows the API methods to record traces.
|
33 | new BasicTracerProvider().register();
|
34 |
|
35 | // To create a span in a trace, we used the global singleton tracer to start a new span.
|
36 | const span = opentelemetry.trace.getTracer('default').startSpan('foo');
|
37 |
|
38 | // Set a span attribute
|
39 | span.setAttribute('key', 'value');
|
40 |
|
41 | // We must end the spans so they become available for exporting.
|
42 | span.end();
|
43 | ```
|
44 |
|
45 | ## Config
|
46 |
|
47 | Tracing configuration is a merge of user supplied configuration with both the default
|
48 | configuration as specified in [config.ts](./src/config.ts) and an
|
49 | environmentally configurable sampling (via `OTEL_TRACES_SAMPLER` and `OTEL_TRACES_SAMPLER_ARG`).
|
50 |
|
51 | ## Example
|
52 |
|
53 | See [examples/basic-tracer-node](https://github.com/open-telemetry/opentelemetry-js/tree/main/examples/basic-tracer-node) for an end-to-end example, including exporting created spans.
|
54 |
|
55 | ## Useful links
|
56 |
|
57 | - For more information on OpenTelemetry, visit: <https://opentelemetry.io/>
|
58 | - For more about OpenTelemetry JavaScript: <https://github.com/open-telemetry/opentelemetry-js>
|
59 | - For help or feedback on this project, join us in [GitHub Discussions][discussions-url]
|
60 |
|
61 | ## License
|
62 |
|
63 | Apache 2.0 - See [LICENSE][license-url] for more information.
|
64 |
|
65 | [discussions-url]: https://github.com/open-telemetry/opentelemetry-js/discussions
|
66 | [license-url]: https://github.com/open-telemetry/opentelemetry-js/blob/main/LICENSE
|
67 | [license-image]: https://img.shields.io/badge/license-Apache_2.0-green.svg?style=flat
|
68 | [dependencies-image]: https://status.david-dm.org/gh/open-telemetry/opentelemetry-js.svg?path=packages%2Fopentelemetry-tracing
|
69 | [dependencies-url]: https://david-dm.org/open-telemetry/opentelemetry-js?path=packages%2Fopentelemetry-tracing
|
70 | [devDependencies-image]: https://status.david-dm.org/gh/open-telemetry/opentelemetry-js.svg?path=packages%2Fopentelemetry-tracing&type=dev
|
71 | [devDependencies-url]: https://david-dm.org/open-telemetry/opentelemetry-js?path=packages%2Fopentelemetry-tracing&type=dev
|
72 | [npm-url]: https://www.npmjs.com/package/@opentelemetry/tracing
|
73 | [npm-img]: https://badge.fury.io/js/%40opentelemetry%2Ftracing.svg
|