You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Nov 10, 2022. It is now read-only.
This package provides everything needed to interact with the OpenTelemetry API, including all TypeScript interfaces, enums, and no-op implementations. It is intended for use both on the server and in the browser.
9
9
10
-
## Quick Start
10
+
The methods in this package perform no operations by default. This means they can be safely called by a library or end-user application whether there is an SDK registered or not. In order to generate and export telemetry data, you will also need an SDK such as the [OpenTelemetry JS SDK][opentelemetry-js].
11
11
12
-
To get started you need to install the SDK and plugins, create a TracerProvider, and register it with the API.
12
+
## Tracing Quick Start
13
13
14
-
### Install Dependencies
15
-
16
-
```sh
17
-
$ # Install tracing dependencies
18
-
$ npm install \
19
-
@opentelemetry/api \
20
-
@opentelemetry/core \
21
-
@opentelemetry/node \
22
-
@opentelemetry/tracing \
23
-
@opentelemetry/exporter-jaeger \ # add exporters as needed
24
-
@opentelemetry/plugin-http # add plugins as needed
25
-
```
26
-
27
-
> Note: this example is for node.js. See [examples/tracer-web](https://github.com/open-telemetry/opentelemetry-js/tree/main/examples/tracer-web) for a browser example.
14
+
### You Will Need
28
15
29
-
### Initialize the SDK
16
+
- An application you wish to instrument
17
+
-[OpenTelemetry JS SDK][opentelemetry-js]
18
+
- Node.js >=8.5.0 (14+ is preferred) or an ECMAScript 5+ compatible browser
30
19
31
-
Before any other module in your application is loaded, you must initialize the global tracer and meter providers. If you fail to initialize a provider, no-op implementations will be provided to any library which acquires them from the API.
20
+
**Note:** ECMAScript 5+ compatibility is for this package only. Please refer to the documentation for the SDK you are using to determine its minimum ECMAScript version.
32
21
33
-
To collect traces and metrics, you will have to tell the SDK where to export telemetry data to. This example uses Jaeger and Prometheus, but exporters exist for [other tracing backends][other-tracing-backends]. If you're not sure if there is an exporter for your tracing backend, contact your tracing provider.
* The SimpleSpanProcessor does no batching and exports spans
46
-
* immediately when they end. For most production use cases,
47
-
* OpenTelemetry recommends use of the BatchSpanProcessor.
48
-
*/
49
-
tracerProvider.addSpanProcessor(
50
-
newSimpleSpanProcessor(
51
-
newJaegerExporter({
52
-
serviceName:'my-service'
53
-
})
54
-
)
55
-
);
56
-
57
-
/**
58
-
* Registering the provider with the API allows it to be discovered
59
-
* and used by instrumentation libraries. The OpenTelemetry API provides
60
-
* methods to set global SDK implementations, but the default SDK provides
61
-
* a convenience method named `register` which registers same defaults
62
-
* for you.
63
-
*
64
-
* By default the NodeTracerProvider uses Trace Context for propagation
65
-
* and AsyncHooksScopeManager for context management. To learn about
66
-
* customizing this behavior, see API Registration Options below.
67
-
*/
68
-
tracerProvider.register();
69
-
```
22
+
**Note for library authors:** Only your end users will need an OpenTelemetry SDK. If you wish to support OpenTelemetry in your library, you only need to use the OpenTelemetry API. For more information, please read the [tracing documentation][docs-tracing].
70
23
71
-
## Version Compatibility
72
-
73
-
Because the npm installer and node module resolution algorithm could potentially allow two or more copies of any given package to exist within the same `node_modules` structure, the OpenTelemetry API takes advantage of a variable on the `global` object to store the global API. When an API method in the API package is called, it checks if this `global` API exists and proxies calls to it if and only if it is a compatible API version. This means if a package has a dependency on an OpenTelemetry API version which is not compatible with the API used by the end user, the package will receive a no-op implementation of the API.
74
-
75
-
## Advanced Use
76
-
77
-
### API Registration Options
78
-
79
-
If you prefer to choose your own propagator or context manager, you may pass an options object into the `tracerProvider.register()` method. Omitted or `undefined` options will be replaced by a default value and `null` values will be skipped.
If you are writing an instrumentation library, or prefer to call the API methods directly rather than using the `register` method on the Tracer/Meter Provider, OpenTelemetry provides direct access to the underlying API methods through the `@opentelemetry/api` package. API entry points are defined as global singleton objects `trace`, `metrics`, `propagation`, and `context` which contain methods used to initialize SDK implementations and acquire resources from the API.
32
+
In order to get started with tracing, you will need to first register an SDK. The SDK you are using may provide a convenience method which calls the registration methods for you, but if you would like to call them directly they are documented here: [sdk registration methods][docs-sdk-registration].
96
33
97
-
-[Trace API Documentation][trace-api-docs]
98
-
-[Propagation API Documentation][propagation-api-docs]
99
-
-[Context API Documentation][context-api-docs]
34
+
Once you have registered an SDK, you can start and end spans. A simple example of basic SDK registration and tracing a simple operation is below. The example should export spans to the console once per second. For more information, see the [tracing documentation][docs-tracing].
Library authors need only to depend on the `@opentelemetry/api` package and trust that the application owners which use their library will initialize an appropriate SDK.
Because the npm installer and node module resolution algorithm could potentially allow two or more copies of any given package to exist within the same `node_modules` structure, the OpenTelemetry API takes advantage of a variable on the `global` object to store the global API. When an API method in the API package is called, it checks if this `global` API exists and proxies calls to it if and only if it is a compatible API version. This means if a package has a dependency on an OpenTelemetry API version which is not compatible with the API used by the end user, the package will receive a no-op implementation of the API.
144
75
145
76
## Useful links
146
77
@@ -152,6 +83,8 @@ async function doSomething() {
152
83
153
84
Apache 2.0 - See [LICENSE][license-url] for more information.
These methods are used to register a compatible OpenTelemetry SDK. Some SDKs like the [OpenTelemetry JS SDK][opentelemetry-js] provide convenience methods which call these registration methods for you.
4
+
5
+
-[Trace API Documentation][trace-api-docs]
6
+
-[Propagation API Documentation][propagation-api-docs]
0 commit comments