doc: upgrade/migration guide for SDK 2.0 (#5513)

Co-authored-by: Marc Pichler <marc.pichler@dynatrace.com>
Co-authored-by: Jamie Danielson <jamiedanielson@honeycomb.io>
This commit is contained in:
Trent Mick 2025-03-04 23:00:44 -08:00 committed by GitHub
parent cb4826635a
commit 04b32102f0
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with 480 additions and 260 deletions

View File

@ -6,6 +6,7 @@ All notable changes to this project will be documented in this file.
For API changes, see the [API CHANGELOG](api/CHANGELOG.md).
For experimental package changes, see the [experimental CHANGELOG](experimental/CHANGELOG.md).
For semantic convention package changes, see the [semconv CHANGELOG](packages/semantic-conventions/CHANGELOG.md).
For notes on migrating to 2.x / 0.200.x see [the upgrade guide](doc/upgrade-to-2.x.md).
## Unreleased
@ -52,7 +53,7 @@ For semantic convention package changes, see the [semconv CHANGELOG](packages/se
* feat(core)!: remove deprecated samplers [#5316](https://github.com/open-telemetry/opentelemetry-js/pull/5316) @pichlermarc
* (user-facing): deprecated `AlwaysOnSampler` has moved to `@opentelemetry/sdk-trace-base`
* (user-facing): deprecated `AlwaysOffSampler` has moved to `@opentelemetry/sdk-trace-base`
* (user-facing): deprecated `TraceIdRatioSampler` has moved to `@opentelemetry/sdk-trace-base`
* (user-facing): deprecated `ParentBasedSampler` has moved to `@opentelemetry/sdk-trace-base`
* (user-facing): deprecated `TraceIdRatioSampler` has moved to `@opentelemetry/sdk-trace-base`
* feat(resource): Merge sync and async resource interfaces into a single interface [#5350](https://github.com/open-telemetry/opentelemetry-js/pull/5350) @dyladan
* Resource constructor now takes a single argument which contains an optional `attributes` object

View File

@ -373,7 +373,7 @@ These instrumentations are hosted at <https://github.com/open-telemetry/opentele
## Useful links
- Upgrade guidelines: [Upgrade Guide](./doc/upgrade-guide.md)
- [Upgrade to SDK 2.x guide](./doc/upgrade-to-2.x.md)
- For more information on OpenTelemetry, visit: <https://opentelemetry.io/>
- For help or feedback on this project, join us in [GitHub Discussions][discussions-url]

View File

@ -1,257 +0,0 @@
# Upgrade guidelines
## 0.37.x to 0.38.0
- `@opentelemetry/sdk-node` `NodeSDKConfiguration.defaultAttributes` has been unused and was removed as the concept does not exist in OpenTelemetry anymore
- Please use `NodeSDKConfiguration.resource` instead.
## 0.35.x to 0.36.0
- `@opentelemetry/sdk-node` changed `await start()` to now be synchronous
- `@opentelemetry/sdk-node` changed `await detectResources()` to now be synchronous
## 0.28.x to 0.29.x
- `@opentelemetry/exporter-trace-otlp-http` is now exporting `scopeSpans` instead of `instrumentationLibrarySpans`
- this exporter now requires collector version `0.48` and up.
- `@opentelemetry/exporter-metrics-otlp-http` is now exporting `scopeMetrics` instead of `instrumentationLibraryMetrics`
- this exporter now requires collector version `0.48` and up.
## 0.27.x to 0.28.x
- In `@opentelemetry/exporter-trace-otlp-http`, `OTLPExporterBase._isShutdown` is replaced with `_shutdownOnce`.
## 0.26.x to 0.27.x
Metric and trace exporters are split into separate packages:
- `@opentelemetry/exporter-otlp-http` => `@opentelemetry/exporter-trace-otlp-http` and `@opentelemetry/exporter-metrics-otlp-http`
- `@opentelemetry/exporter-otlp-grpc` => `@opentelemetry/exporter-trace-otlp-grpc` and `@opentelemetry/exporter-metrics-otlp-grpc`
- `@opentelemetry/exporter-otlp-proto` => `@opentelemetry/exporter-trace-otlp-proto` and `@opentelemetry/exporter-metrics-otlp-proto`
Metric types are renamed:
- `@openetelemetry/api-metrics`
- `Meter`
- `createValueRecorder` => `createHistogram`
- `createValueObserver` => `createObservableGauge`
- `createSumObserver` => `createObservableCounter`
- `createUpDownSumObserver` => `createObservableUpDownCounter`
- `ValueRecorder` => `Histogram`
- `ValueObserver` => `ObservableGauge`
- `SumObserver` => `ObservableCounter`
- `UpDownSumObserver` => `ObservableUpDownCounter`
- `ObserverResult` => `ObservableResult`
- `Observation.observer` => `Observation.observable`
- `@opentelemetry/sdk-metrics-base`
- `MetricKind`
- `VALUE_RECORDER` => `HISTOGRAM`
- `SUM_OBSERVER` => `OBSERVABLE_COUNTER`
- `UP_DOWN_SUM_OBSERVER` => `OBSERVABLE_UP_DOWN_COUNTER`
- `VALUE_OBSERVER` => `OBSERVABLE_GAUGE`
## 0.25.x to 1.x.y
Collector exporter packages and types are renamed:
- `@opentelemetry/exporter-collector` => `@opentelemetry/exporter-otlp-http`
- `CollectorExporterBase` => `OTLPExporterBase`
- `CollectorTraceExporter` => `OTLPTraceExporter`
- `CollectorMetricExporter` => `OTLPMetricExporter`
- `CollectorExporterBrowserBase` => `OTLPExporterBrowserBase`
- `CollectorExporterNodeBase` => `OTLPExporterNodeBase`
- `CollectorExporterConfigBase` => `OTLPExporterConfigBase`
- `CollectorExporterError` => `OTLPExporterError`
- `COLLECTOR_SPAN_KIND_MAPPING` => `OTLP_SPAN_KIND_MAPPING`
- `collectorTypes` => `otlpTypes`
- `@opentelemetry/exporter-collector-grpc` => `@opentelemetry/exporter-otlp-grpc`
- `CollectorTraceExporter` => `OTLPTraceExporter`
- `CollectorMetricExporter` => `OTLPMetricExporter`
- `CollectorExporterConfigNode` => `OTLPExporterConfigNode`
- `@opentelemetry/exporter-collector-proto` => `@opentelemetry/exporter-otlp-proto`
- `CollectorExporterNodeBase` => `OTLPExporterNodeBase`
- `CollectorMetricExporter` => `OTLPMetricExporter`
- `CollectorTraceExporter` => `OTLPTraceExporter`
- W3C propagators in @opentelemetry/core were renamed
- `HttpTraceContextPropagator` -> `W3CTraceContextPropagator`
- `HttpBaggagePropagator` -> `W3CBaggagePropagator`
## 0.24.x to 0.25.x
- SDKs packages for trace and metrics has been renamed to have a consistent naming schema:
- @opentelemetry/tracing -> @opentelemetry/sdk-trace-base
- @opentelemetry/node -> @opentelemetry/sdk-trace-node
- @opentelemetry/web -> @opentelemetry/sdk-trace-web
- @opentelemetry/metrics -> @opentelemetry/sdk-metrics-base
- @opentelemetry/node-sdk -> @opentelemetry/sdk-node
## 0.23.x to 0.24.x
- `ResourceAttributes` renamed to `SemanticResourceAttributes` in the `@opentelemetry/semantic-conventions` package
## 0.19.x to 0.20.0
- `HttpBaggage` renamed to `HttpBaggagePropagator`
- `HttpTraceContext` renamed to `HttpTraceContextPropagator`
- `JaegerHttpTracePropagator` renamed to `JaegerPropagator`
- `serviceName` configuration removed from Collector exporters. Use `service.name` Resource attribute instead.
- Prometheus exporter added suffix `_total` to counter metrics.
## 0.18.x to 0.19.0
- API is now a peer dependency. This means that users will need to include `@opentelemetry/api` as a dependency of their project in order to use the SDK. NPM version 7+ (Node 15+) should do this automatically.
- All plugins have been removed in favor of instrumentations.
- The `@opentelemetry/propagator-b3` package previously exported three propagators: `B3Propagator`,`B3SinglePropagator`, and `B3MultiPropagator`, but now only exports the `B3Propagator`. It extracts b3 context in single and multi-header encodings, and injects context using the single-header encoding by default, but can be configured to inject context using the multi-header encoding during construction: `new B3Propagator({ injectEncoding: B3InjectEncoding.MULTI_HEADER })`. If you were previously using the `B3SinglePropagator` or `B3MultiPropagator` directly, you should update your code to use the `B3Propagator` with the appropriate configuration. See the [README](https://github.com/open-telemetry/opentelemetry-js/blob/main/packages/opentelemetry-propagator-b3/README.md) for full details and usage.
- Sampling configuration via environment variable has changed. If you were using `OTEL_SAMPLING_PROBABILITY` then you should replace it with `OTEL_TRACES_SAMPLER=parentbased_traceidratio` and `OTEL_TRACES_SAMPLER_ARG=<number>` where `<number>` is a number in the [0..1] range, e.g. "0.25". Default is 1.0 if unset.
## 0.17.0 to 0.18.0
- `diag.setLogLevel` is removed and LogLevel can be set by an optional second parameter to `setLogger`
[PR-1975](https://github.com/open-telemetry/opentelemetry-js/pull/1975)
- Breaking change - The resulting resource MUST have all attributes that are on any of the two input resources. If a key exists on both the old and updating resource, the value of the updating resource MUST be picked - previously it was opposite.
## 0.16.0 to 0.17.0
[PR-1880](https://github.com/open-telemetry/opentelemetry-js/pull/1880) feat(diag-logger): introduce a new global level api.diag for internal diagnostic logging
[PR-1925](https://github.com/open-telemetry/opentelemetry-js/pull/1925) feat(diag-logger): part 2 - breaking changes - remove api.Logger, api.NoopLogger, core.LogLevel, core.ConsoleLogger
- These PR's remove the previous `Logger` and `LogLevel` implementations and change the way you should use the replacement `DiagLogger` and `DiagLogLevel`, below are simple examples of how to change your existing usages.
### Setting the global diagnostic logger
The new global [`api.diag`](https://github.com/open-telemetry/opentelemetry-js/blob/main/api/src/api/diag.ts) provides the ability to set the global diagnostic logger `setLogger()` and logging level `setLogLevel()`, it is also a `DiagLogger` implementation and should be directly to log diagnostic messages.
All included logger references have been removed in preference to using the global `api.diag` directly, so you no longer need to pass around the logger instance via function parameters or included as part of the configuration for a component.
```javascript
import { diag, DiagConsoleLogger, DiagLogLevel } from "@opentelemetry/api";
// Setting the default Global logger to use the Console
// And optionally change the logging level (Defaults to INFO)
diag.setLogger(new DiagConsoleLogger(), DiagLogLevel.ERROR)
```
### Using the logger anywhere in the code
```typescript
import { diag } from "@opentelemetry/api";
// Remove or make optional the parameter and don't use it.
export function MyFunction() {
diag.debug("...");
diag.info("...");
diag.warn("...");
diag.error("...");
diag.verbose("..");
}
```
### Setting the logger back to a noop
```typescript
import { diag } from "@opentelemetry/api";
diag.setLogger();
```
[PR-1855](https://github.com/open-telemetry/opentelemetry-js/pull/1855) Use instrumentation loader to load plugins and instrumentations
- Providers do no load the plugins anymore. Also PluginLoader has been removed from providers, use `registerInstrumentations` instead
```javascript
//Previously in node
const provider = new NodeTracerProvider({
plugins: {
'@grpc/grpc-js': {
enabled: true,
path: '@opentelemetry/plugin-grpc-js',
},
}
});
// Now
const provider = new NodeTracerProvider();
const { registerInstrumentations } = require('@opentelemetry/instrumentation');
registerInstrumentations({
instrumentations: [
{
plugins: {
'@grpc/grpc-js': {
enabled: true,
path: '@opentelemetry/plugin-grpc-js',
},
}
}
],
tracerProvider: provider,
});
// or if you want to load only default instrumentations / plugins
registerInstrumentations({
tracerProvider: provider,
});
//Previously in browser
const provider = new WebTracerProvider({
plugins: [
new DocumentLoad()
]
});
// Now
const { registerInstrumentations } = require('@opentelemetry/instrumentation');
const provider = new WebTracerProvider();
registerInstrumentations({
instrumentations: [
new DocumentLoad(),
],
});
```
- `registerInstrumentations` supports loading old plugins and instrumentations together. It also supports setting tracer provider and meter provider on instrumentations
[PR-1874](https://github.com/open-telemetry/opentelemetry-js/pull/1874) More specific API type names
Some types exported from `"@opentelemetry/api"` have been changed to be more specific.
- `AttributeValue` renamed to `SpanAttributeValue`
- `Attributes` renamed to `SpanAttributes`
- `EntryTtl` renamed to `BaggageEntryTtl`
- `EntryValue` renamed to `BaggageEntryValue`
- `Status` renamed to `SpanStatus`
- `StatusCode` renamed to `SpanStatusCode`
## 0.15.0 to 0.16.0
[PR-1863](https://github.com/open-telemetry/opentelemetry-js/pull/1863) removed public attributes `keepAlive` and `httpAgentOptions` from Node.js `CollectorTraceExporter` and `CollectorMetricExporter`
## 0.14.0 to 0.15.0
[PR-1764](https://github.com/open-telemetry/opentelemetry-js/pull/1764) removed some APIs from `Tracer`:
- `Tracer.getCurrentSpan()`: use `api.getSpan(api.context.active())`
- `Tracer.withSpan(span)`: use `api.context.with(api.setSpan(api.context.active(), span))`
- `Tracer.bind(target)`: use `api.context.bind(target)`
[PR-1797](https://github.com/open-telemetry/opentelemetry-js/pull/1797) chore!: split metrics into its own api package:
- Any references to `require("@opentelemetry/api").metrics` will need to be changed to `require("@opentelemetry/api-metrics").metrics`
[PR-1725](https://github.com/open-telemetry/opentelemetry-js/pull/1725) Use new gRPC default port
- The default port used by `@opentelemetry/exporter-collector-grpc` is changed from `55680` to `4317`
[PR-1749](https://github.com/open-telemetry/opentelemetry-js/pull/1749) chore: improve naming of span related context APIs
- Rename `[gs]etActiveSpan()` to `[gs]etSpan()`
- Rename `setExtractedSpanContext()` to `setSpanContext()`
- Rename `getParentSpanContext()` to `getSpanContext()`

475
doc/upgrade-to-2.x.md Normal file
View File

@ -0,0 +1,475 @@
# Upgrade to OpenTelemetry JS SDK 2.x
In late February 2025, the OpenTelemetry JavaScript project released the first versions of "JS SDK 2.x" packages, which include a number of *breaking changes*. This document shows how to migrate to the new 2.x. For the most part, this document *only covers breaking changes*. Refer to the full changelogs for these releases here:
- [CHANGELOG for stable SDK packages](https://github.com/open-telemetry/opentelemetry-js/blob/main/CHANGELOG.md)
- [CHANGELOG for experimental SDK packages](https://github.com/open-telemetry/opentelemetry-js/blob/main/experimental/CHANGELOG.md)
<!-- TODO: update these changelog links to the 2.0.0 and 0.200.0 anchors when we have a final release. -->
Per [OpenTelemetry guidelines](https://opentelemetry.io/docs/specs/otel/versioning-and-stability/#sdk-support), the 1.x versions of stable SDK packages will be supported for one year from the 2.0.0 release.
If you have any questions about the 2.x changes, please ask! You can reach the OTel JS community on the [#otel-js](https://cloud-native.slack.com/archives/C01NL1GRPQR) channel of the [CNCF Slack](https://slack.cncf.io/), [open a Discussion issue](https://github.com/open-telemetry/opentelemetry-js/issues/new?template=discussion.md) on the repository, or join the weekly [OTel JS SIG zoom call](https://docs.google.com/document/d/1tCyoQK49WVcE-x8oryZOTTToFm7sIeUhxFPm9g-qL1k/edit).
## What is JS SDK 2.x?
"JS SDK 2.x" encompasses new releases of the `@opentelemetry/*` JavaScript packages published from the [opentelemetry-js.git](https://github.com/open-telemetry/opentelemetry-js) repository, except the API and semantic-conventions packages &mdash; categories 3 and 4 in the groupings below. The package versions for this new major will be `>=2.0.0` for the stable and `>=0.200.0` for the unstable packages. (The jump to `0.200.x` was intentional, to hopefully help signal that these packages are in the "2.x generation".)
If your usage of OpenTelemetry does not *directly* use these packages, then you most likely will not need to change your code to migrate. You still need to be aware of the new minimum versions of Node.js, TypeScript, and ES that are supported.
<details>
<summary>Categories of OpenTelemetry JS packages</summary>
The OpenTelemetry JS SIG is responsible for numerous packages, all published to npm under the `@opentelemetry/` org, and developed in two git repositories: [opentelemetry-js.git](https://github.com/open-telemetry/opentelemetry-js) (sometimes called the "core" repo) and [opentelemetry-js-contrib.git](https://github.com/open-telemetry/opentelemetry-js-contrib) (the "contrib" repo). For the sake of this document, these packages can be grouped into these categories:
1. The [API](../api/) (`@opentelemetry/api`). The API is versioned independently of all other packages. Its version is *not* being changed as part of "JS SDK 2.x".
2. The [Semantic Conventions](../semantic-conventions/) (`@opentelemetry/semantic-conventions`). This package follows the [versioning](https://github.com/open-telemetry/semantic-conventions/releases) of the language-independent Semantic Conventions. It is *not* being changed as part of "JS SDK 2.x".
3. [Stable packages from opentelemetry-js.git](../packages/). These are packages that have reached "1.x". These packages are all versioned together, and are at version "1.30.0" at the time of writing.
4. [Unstable packages from opentelemetry-js.git](../experimental/packages/). These are packages deemed still experimental. They are all at "0.x" versions. These packages are all versioned together, and are at version "0.57.0" at the time of writing.
5. All packages from opentelemetry-js-contrib.git. These packages are all versioned independently. These packages are not considered part of the "JS SDK 2.0" release. However, eventually they will update to use JS SDK 2.x releases.
"JS SDK 2.x" refers to categories 3 and 4.
</details>
<details>
<summary>The full set of "JS SDK 2.x" packages</summary>
| Package | Version |
| ------- | ------- |
| @opentelemetry/context-async-hooks | 2.0.0 |
| @opentelemetry/context-zone | 2.0.0 |
| @opentelemetry/context-zone-peer-dep | 2.0.0 |
| @opentelemetry/core | 2.0.0 |
| @opentelemetry/exporter-jaeger | 2.0.0 |
| @opentelemetry/exporter-zipkin | 2.0.0 |
| @opentelemetry/propagator-b3 | 2.0.0 |
| @opentelemetry/propagator-jaeger | 2.0.0 |
| @opentelemetry/resources | 2.0.0 |
| @opentelemetry/sdk-metrics | 2.0.0 |
| @opentelemetry/sdk-trace-base | 2.0.0 |
| @opentelemetry/sdk-trace-node | 2.0.0 |
| @opentelemetry/sdk-trace-web | 2.0.0 |
| @opentelemetry/shim-opentracing | 2.0.0 |
| @opentelemetry/api-events | 0.200.0 |
| @opentelemetry/api-logs | 0.200.0 |
| @opentelemetry/exporter-logs-otlp-grpc | 0.200.0 |
| @opentelemetry/exporter-logs-otlp-http | 0.200.0 |
| @opentelemetry/exporter-logs-otlp-proto | 0.200.0 |
| @opentelemetry/exporter-metrics-otlp-grpc | 0.200.0 |
| @opentelemetry/exporter-metrics-otlp-http | 0.200.0 |
| @opentelemetry/exporter-metrics-otlp-proto | 0.200.0 |
| @opentelemetry/exporter-prometheus | 0.200.0 |
| @opentelemetry/exporter-trace-otlp-grpc | 0.200.0 |
| @opentelemetry/exporter-trace-otlp-http | 0.200.0 |
| @opentelemetry/exporter-trace-otlp-proto | 0.200.0 |
| @opentelemetry/instrumentation | 0.200.0 |
| @opentelemetry/instrumentation-fetch | 0.200.0 |
| @opentelemetry/instrumentation-grpc | 0.200.0 |
| @opentelemetry/instrumentation-http | 0.200.0 |
| @opentelemetry/instrumentation-xml-http-request | 0.200.0 |
| @opentelemetry/opentelemetry-browser-detector | 0.200.0 |
| @opentelemetry/otlp-exporter-base | 0.200.0 |
| @opentelemetry/otlp-grpc-exporter-base | 0.200.0 |
| @opentelemetry/otlp-transformer | 0.200.0 |
| @opentelemetry/sampler-jaeger-remote | 0.200.0 |
| @opentelemetry/sdk-events | 0.200.0 |
| @opentelemetry/sdk-logs | 0.200.0 |
| @opentelemetry/sdk-node | 0.200.0 |
| @opentelemetry/shim-opencensus | 0.200.0 |
| @opentelemetry/web-common | 0.200.0 |
</details>
## 💥 Node.js supported versions
The **minimum supported Node.js has been raised to `^18.19.0 || >=20.6.0`**. This means that support for Node.js 14 and 16 has been dropped.
> [!NOTE]
>
> - The minimum supported Node.js versions for `@opentelemetry/api` (Node.js v8) and `@opentelemetry/semantic-conventions` (Node.js v14) are *not* changing as part of "JS SDK 2.x".
> - The particular minimum *minor* versions of Node.js 18 and 20 were selected to include support for Node.js's `--import` flag and `module.register()` API. It is expected that this will provide a smoother experience for improved automatic ES module instrumentation.
>
> Related issues and PRs:
> [#5395](https://github.com/open-telemetry/opentelemetry-js/issues/5395)
## 💥 TypeScript supported versions
The **minimum supported TypeScript version has been raised to 5.0.4**.
As well, going forward all packages published from this repository will **drop support for old versions of `typescript` in minor releases**. We will only drop support for versions that are older than 2 years.
Important: Both of these changes (typescript@5.0.4, dropping old TypeScript versions in minor releases) **also apply to the `@opentelemetry/api` and `@opentelemetry/semantic-conventions` packages**, even though those two packages aren't otherwise considered part of the "JS SDK 2.x" update.
> [!NOTE]
> Related issues and PRs:
> [#5145](https://github.com/open-telemetry/opentelemetry-js/pull/5145)
## 💥 ES2022 compilation target
The **compilation target for transpiled TypeScript has been raised to ES2022** (from ES2017) for all packages (except `@opentelemetry/api`, `@opentelemetry/api-logs`, `@opentelemetry/api-events`, and `@opentelemetry/semantic-conventions`).
For Browser usage, this drops support for any browser versions that do not support ES2022 features.
For Node.js usage, this already follows from the new minimum supported Node.js versions mentioned above.
> [!NOTE]
> Related issues and PRs:
> [#5393](https://github.com/open-telemetry/opentelemetry-js/issues/5393)
> [#5456](https://github.com/open-telemetry/opentelemetry-js/pull/5456)
## 💥 Drop `window.OTEL_*` support in browsers
For browser users, support for `window.OTEL_*` environment variable configuration (previous handled by the `envDetector`) has been dropped. OpenTelemetry bootstrap code for the browser should be configured via code.
> [!NOTE]
> Related issues and PRs:
> [#5217](https://github.com/open-telemetry/opentelemetry-js/issues/5217)
> [#5455](https://github.com/open-telemetry/opentelemetry-js/pull/5455)
> [#5472](https://github.com/open-telemetry/opentelemetry-js/pull/5472)
> [#5465](https://github.com/open-telemetry/opentelemetry-js/pull/5465)
> [#5473](https://github.com/open-telemetry/opentelemetry-js/pull/5473)
## 💥 `@opentelemetry/resources` API changes
Perhaps the most likely API change you will need to update for is from the `@opentelemetry/resources` package.
<br/>
The `Resource` *class* is no longer exported; instead use new utility functions.
- Creating a resource: `new Resource(...)` -> `resourceFromAttributes(...)`
- Getting the default resource: `Resource.default()` -> `defaultResource()`
- Getting an empty resource: `Resource.empty()` or `Resource.EMPTY` -> `emptyResource()`
- TypeScript interface for a resource: `IResource` -> `Resource`
```ts
// Before
import { Resource } from '@opentelemetry/resources';
new Resource({ ... }); // Create a resource
Resource.default(); // Get a resource with the default attributes
Resource.empty(); // Get an empty resource
// After
import { resourceFromAttributes, defaultResource, emptyResource } from '@opentelemetry/resources';
resourceFromAttributes({ ... });
defaultResource();
emptyResource();
```
<br/>
"Sync" and async resource detectors have been unified. For example, where before there were both `hostDetector` and `hostDetectorSync`, now there is only `hostDetector` which may be used in all cases.
- `envDetectorSync` -> `envDetector`
- `hostDetectorSync` -> `hostDetector`
- `osDetectorSync` -> `osDetector`
- `processDetectorSync` -> `processDetector`
- `serviceInstanceIdDetectorSync` -> `serviceInstanceIdDetector`
- `detectResourcesSync` -> `detectResources`
<br/>
The `browserDetector` and `browserDetectorSync` exports were dropped. This resource detector was long ago replaced by the (semantic-conventions-compliant) browser detector in the separate `@opentelemetry/opentelemetry-browser-detector` package.
- `browserDetector` or `browserDetectorSync` -> `import { browserDetector } from '@opentelemetry/opentelemetry-browser-detector'`
<br/>
As mentioned above, support for `window.OTEL_*` environment variable configuration in browsers has been dropped. This means that the `envDetector` in browsers is now a no-op.
- `envDetector` in a browser -> manually create a resource with the API
<br/>
In TypeScript code, the `ResourceAttributes` type was replaced with the `Attributes` type from the 'api' package. Though unlikely, it is possible this could be a breaking change because it raised the minimum `peerDependencies` entry for `@opentelemetry/api` from `1.0.0` to `1.3.0`.
- type `ResourceAttributes` -> `import type { Attributes } from '@opentelemetry/api';`
<br/>
> [!NOTE]
>
> - In general, the OTel JS packages are trending away from exporting *classes* because that results in exporting types with internal details that inhibit later refactoring. See [#5283](https://github.com/open-telemetry/opentelemetry-js/issues/5283) for details.
> - The unification of sync and async resource detectors simplified the API, clarified the behavior for merging results from multiple detectors, and laid the groundwork for supporting OpenTelemetry *Entities* in the future. See [#5350](https://github.com/open-telemetry/opentelemetry-js/pull/5350) for details.
>
> Related issues and PRs:
> [#5421](https://github.com/open-telemetry/opentelemetry-js/pull/5421)
> [#5467](https://github.com/open-telemetry/opentelemetry-js/pull/5467)
> [#5350](https://github.com/open-telemetry/opentelemetry-js/pull/5350)
> [#5420](https://github.com/open-telemetry/opentelemetry-js/issues/5420)
> [#5217](https://github.com/open-telemetry/opentelemetry-js/issues/5217)
> [#5016](https://github.com/open-telemetry/opentelemetry-js/issues/5016)
## 💥 `@opentelemetry/core` API changes
The environment variable utilities have changed to no longer have one large load and parse of all possible `OTEL_*` environment variables. Instead there are `get{Type}FromEnv()` utilities to handle the various [specified OpenTelemetry SDK environment variable types](https://opentelemetry.io/docs/specs/otel/configuration/sdk-environment-variables/#configuration-types).
The caller should now handle default values. The authority for default values is the [OpenTelemetry Environment Variable Spec](https://opentelemetry.io/docs/specs/otel/configuration/sdk-environment-variables/#general-sdk-configuration). The previously used defaults in the 1.x code can be seen [here](https://github.com/open-telemetry/opentelemetry-js/blob/e9d3c71918635d490b6a9ac9f8259265b38394d0/packages/opentelemetry-core/src/utils/environment.ts#L154-L239).
- `getEnv().OTEL_FOO` -> `get{Type}FromEnv('OTEL_FOO') ?? defaultValue`
- `getStringFromEnv()`
- `getNumberFromEnv()`
- `getBooleanFromEnv()`
- `getStringListFromEnv()`
- `diagLogLevelFromString()` for reading `OTEL_LOG_LEVEL`
- `getEnvWithoutDefaults().OTEL_FOO` -> `get{Type}FromEnv('OTEL_FOO')`
- The following have been removed without replacement:
- `DEFAULT_ENVIRONMENT`
- `ENVIRONMENT`
- `RAW_ENVIRONMENT`
- `parseEnvironment`
For example:
```ts
// Before
import { getEnv, getEnvWithoutDefaults } from '@opentelemetry/core';
const flavor = getEnv().OTEL_EXPORTER_OTLP_PROTOCOL;
const limit = getEnv().OTEL_BSP_MAX_QUEUE_SIZE;
const level = getEnv().OTEL_LOG_LEVEL;
// After
import { getStringFromEnv, getNumberFromEnv, diagLogLevelFromString } from '@opentelemetry/core';
const flavor = getStringFromEnv('OTEL_EXPORTER_OTLP_PROTOCOL') ?? 'http/protobuf';
const limit = getNumberFromEnv('OTEL_BSP_MAX_QUEUE_SIZE') ?? 2048;
const level = diagLogLevelFromString(getStringFromEnv('OTEL_LOG_LEVEL'));
```
<br/>
A number of deprecated, obsolete, unused, and accidentally exported functions and variables have been removed from the `core` package. (If there is a replacement, it is mentioned with `-> ...`.)
- `IdGenerator` and `RandomIdGenerator` (deprecated)
- type `InstrumentationLibrary` (deprecated) -> type `InstrumentationScope`
- `AlwaysOnSampler` (deprecated) -> moved to `@opentelemetry/sdk-trace-base`
- `AlwaysOffSampler` (deprecated) -> moved to `@opentelemetry/sdk-trace-base`
- `ParentBasedSampler` (deprecated) -> moved to `@opentelemetry/sdk-trace-base`
- `TraceIdRatioSampler` (deprecated) -> moved to `@opentelemetry/sdk-trace-base`
- `TracesSamplerValues` (was only used internally)
- `VERSION`
- `isWrapped` -> use `isWrapped` from `@opentelemetry/instrumentation`
- `ShimWrapped` -> use `ShimWrapped` from `@opentelemetry/instrumentation`
- `hexToBase64`
- `hexToBinary`
- `baggageUtils.getKeyPairs` (unintentionally exported)
- `baggageUtils.serializeKeyPairs` (unintentionally exported)
- `baggageUtils.parseKeyPairsIntoRecord` -> `parseKeyPairsIntoRecord`
- `baggageUtils.parsePairKeyValue` (unintentionally exported)
- `TimeOriginLegacy`
- `isAttributeKey` (unintentionally exported)
- `DEFAULT_ATTRIBUTE_VALUE_LENGTH_LIMIT` -> use `Infinity`
- `DEFAULT_ATTRIBUTE_VALUE_COUNT_LIMIT` -> use `128`
- `DEFAULT_SPAN_ATTRIBUTE_PER_EVENT_COUNT_LIMIT` -> use `128`
- `DEFAULT_SPAN_ATTRIBUTE_PER_LINK_COUNT_LIMIT` -> use `128`
<br/>
> [!NOTE]
>
> - The `getEnv()` et al API changes avoid a problem of requiring an update to
> `@opentelemetry/core` for any added `OTEL_*` envvars, including in unstable
> packages and packages maintained in the separate contrib repository.
> See [#5443](https://github.com/open-telemetry/opentelemetry-js/pull/5443).
>
> Related issues and PRs:
> [#5443](https://github.com/open-telemetry/opentelemetry-js/pull/5443)
> [#5481](https://github.com/open-telemetry/opentelemetry-js/pull/5481)
> [#5475](https://github.com/open-telemetry/opentelemetry-js/pull/5475)
> [#5309](https://github.com/open-telemetry/opentelemetry-js/pull/5309)
> [#5308](https://github.com/open-telemetry/opentelemetry-js/pull/5308)
> [#5316](https://github.com/open-telemetry/opentelemetry-js/pull/5316)
> [#5406](https://github.com/open-telemetry/opentelemetry-js/pull/5406)
> [#5444](https://github.com/open-telemetry/opentelemetry-js/pull/5444)
> [#5504](https://github.com/open-telemetry/opentelemetry-js/pull/5504)
## 💥 Tracing SDK API changes
This section describes API changes in the set of packages that implement the tracing SDK: `@opentelemetry/sdk-trace-base`, `@opentelemetry/sdk-trace-node`, `@opentelemetry/sdk-trace-web`.
Tracing was the first signal to have an SDK. Over time, and as the Metrics and Logs SDKs were added, the API design separating functionality between the `{Tracer,Meter,Logs}Provider`s APIs and the higher level `NodeSDK` (in `@opentelemetry/sdk-node`) improved. The Tracing SDK was left with some cruft that is being removed in JS SDK 2.0. (See [#5290](https://github.com/open-telemetry/opentelemetry-js/issues/5290) for motivation.)
- removed `BasicTracerProvider#addSpanProcessor(...)` -> use constructor options to the TracerProvider class
- made `BasicTracerProvider#getActiveSpanProcessor()` private
- made `BasicTracerProvider#resource` private
- `BasicTracerProvider` and `NodeTracerProvider` will no longer use the `OTEL_TRACES_EXPORTER` envvar to create exporters -> This functionality already resides in `NodeSDK` (from `@opentelemetry/sdk-node`).
- `BasicTracerProvider` and `NodeTracerProvider` will no longer use the `OTEL_PROPAGATORS` envvar to create propagators -> This functionality already resides in `NodeSDK` (from `@opentelemetry/sdk-node`).
- The following internal properties were removed from `BasicTracerProvider`: `_registeredExporters`, `_getSpanExporter`, `_buildExporterFromEnv`
- The following exports were dropped from `@opentelemetry/sdk-trace-*`:
- `EXPORTER_FACTORY` is not used anymore and has been removed
- `PROPAGATOR_FACTORY` is not used anymore and has been removed
- `ForceFlushState` was intended for internal use and has been removed
- the `Tracer` class was unintentionally exported and has been removed
- to obtain a `Tracer`, please use `BasicTracerProvider#getTracer()`, `NodeTracerProvider#getTracer()` or `WebTracerProvider#getTracer()`
- to reference the `Tracer` type, please use the `Tracer` type from `@opentelemetry/api`
- removed `BasicTracerProvider#register()` -> use `NodeTracerProvider#register()` or `WebTracerProvider#register()`, or call `trace.setGlobalTracerProvider()` et al manually (see [#5503](https://github.com/open-telemetry/opentelemetry-js/pull/5503))
<br/>
The export of the `Span` class has been removed. It was not intended to be used directly. One should always use methods on a `Tracer` instance (e.g. `startSpan()`) for creating spans.
- `new Span(...)` -> use `tracer.startSpan(...)`
<br/>
The `parentSpanId` field on the `Span` and `ReadableSpan` interfaces was replaced by `parentSpanContext`, to adhere to the OTel spec. [#5450](https://github.com/open-telemetry/opentelemetry-js/pull/5450)
- `span.parentSpanId` -> `span.parentSpanContext?.spanId`
<br/>
As mentioned above in the "core" section, `InstrumentationLibrary` has been changed to `InstrumentationScope`:
- `ReadableSpan.instrumentationLibrary` -> `ReadableSpan.instrumentationScope`
<br/>
When invalid data is set on `OTEL_TRACES_SAMPLER`, the SDK now uses `ParentBasedAlwaysOnSampler` rather than `AlwaysOnSampler`, per [spec](https://opentelemetry.io/docs/specs/otel/configuration/sdk-environment-variables/#general-sdk-configuration).
> [!NOTE]
> Related issues and PRs:
> [#5290](https://github.com/open-telemetry/opentelemetry-js/issues/5290)
> [#5134](https://github.com/open-telemetry/opentelemetry-js/pull/5134)
> [#5192](https://github.com/open-telemetry/opentelemetry-js/pull/5192)
> [#5239](https://github.com/open-telemetry/opentelemetry-js/pull/5239)
> [#5355](https://github.com/open-telemetry/opentelemetry-js/pull/5355)
> [#5405](https://github.com/open-telemetry/opentelemetry-js/pull/5405)
> [#5048](https://github.com/open-telemetry/opentelemetry-js/pull/5048)
> [#5450](https://github.com/open-telemetry/opentelemetry-js/pull/5450)
> [#5308](https://github.com/open-telemetry/opentelemetry-js/pull/5308)
> [#5503](https://github.com/open-telemetry/opentelemetry-js/pull/5503)
## 💥 `@opentelemetry/sdk-metrics` API changes
The Metrics SDK now internally uses the `Gauge` and `MetricAdvice` types from the API package, which requires bumping its peer dependency.
- bumped minimum version of `@opentelemetry/api` peer dependency to 1.9.0
<br/>
The `View` *class* has been removed in favor of passing an object of `type ViewOptions` to a MeterProvider. As well, the `*Aggregation` classes have been removed in favor of `type AggregationOption` and the `AggregationType` enum. (See [#4931](https://github.com/open-telemetry/opentelemetry-js/pull/4931) for motivation.)
- removed class `View` -> pass a `type ViewOptions` object to a MeterProvider
- removed `Aggregation` -> pass a `type ViewOptions` object to a MeterProvider
- removed `DefaultAggregation` -> pass a ViewOptions object with `type: AggregationType.DEFAULT`
- removed `DropAggregation` -> pass a ViewOptions object with `type: AggregationType.DROP`
- removed `ExponentialHistogramAggregation` -> pass a ViewOptions object with `type: AggregationType.EXPONENTIAL_HISTOGRAM`
- removed `ExplicitBucketHistogramAggregation` -> pass a ViewOptions object with `type: AggregationType.EXPLICIT_BUCKET_HISTOGRAM`
- removed `HistogramAggregation` -> pass a ViewOptions object with `type: AggregationType.EXPLICIT_BUCKET_HISTOGRAM`
- removed `LastValueAggregation` -> pass a ViewOptions object with `type: AggregationType.LAST_VALUE`
- removed `SumAggregation` -> pass a ViewOptions object with `type: AggregationType.SUM`
For example:
```js
// Before
import {
MeterProvider,
View,
InstrumentType,
ExplicitBucketHistogramAggregation
} from '@opentelemetry/sdk-metrics';
const provider = new MeterProvider({
views: [
new View({
instrumentName: 'http.server.duration',
instrumentType: InstrumentType.HISTOGRAM,
aggregation: new ExplicitBucketHistogramAggregation([0, 1, 5, 10, 15, 20, 25, 30]),
})
]
});
// After
import {MeterProvider, InstrumentType, AggregationType} from '@opentelemetry/sdk-metrics';
const provider = new MeterProvider({
views: [
{ // type ViewOptions
instrumentName: 'http.server.duration',
instrumentType: InstrumentType.HISTOGRAM,
aggregation: { // type AggregationOption
type: AggregationType.EXPLICIT_BUCKET_HISTOGRAM,
options: {
boundaries: [0, 1, 5, 10, 15, 20, 25, 30],
}
}
}
]
});
```
<br/>
The `attributeKeys` View option has been replaced with more capable filtering. (See [#4532](https://github.com/open-telemetry/opentelemetry-js/pull/4532).)
- `attributeKeys` `View` option -> use the `attributesProcessors` ViewOptions property, and `createAllowListAttributesProcessor()` or `createDenyListAttributesProcessor()`
For example:
```js
// Before
import {MeterProvider, View} from '@opentelemetry/sdk-metrics';
const provider = new MeterProvider({
views: [
new View({
attributeKeys: ['attrib1'],
})
]
});
// After
import {MeterProvider, createAllowListAttributesProcessor} from '@opentelemetry/sdk-metrics';
const provider = new MeterProvider({
views: [
{
attributesProcessors: [
createAllowListAttributesProcessor(['attrib1']),
],
}
]
});
```
<br/>
Some deprecated things have been removed:
- drop deprecated `type` field on interface `MetricDescriptor`
- drop deprecated `InstrumentDescriptor` type -> use `MetricDescriptor` instead
<br/>
The following changes were made to MetricReader-related APIs:
- removed `MeterProvider.addMetricReader()` -> use the `readers` constructor option
- new `IMetricReader` interface -> This is preferred to the `MetricReader` abstract class. The `MeterProviderOptions` `readers` constructor option now uses this slightly narrower type.
- If you accept `MetricReader` in your public interface, prefer accepting the more general `IMetricReader` type instead to avoid unintentional breaking changes.
<br/>
> [!NOTE]
> Related issues and PRs:
> [#5254](https://github.com/open-telemetry/opentelemetry-js/pull/5254)
> [#4931](https://github.com/open-telemetry/opentelemetry-js/pull/4931)
> [#4532](https://github.com/open-telemetry/opentelemetry-js/pull/4532)
> [#5291](https://github.com/open-telemetry/opentelemetry-js/pull/5291)
> [#5266](https://github.com/open-telemetry/opentelemetry-js/pull/5266)
> [#4419](https://github.com/open-telemetry/opentelemetry-js/pull/4419)
> [#5311](https://github.com/open-telemetry/opentelemetry-js/pull/5311)
## 💥 Other changes
This section describes the remaining breaking changes, not otherwise mentioned in a section above.
Usage of the deprecated `SpanAttributes` and `MetricAttributes` types from the API package has been changed to use the `Attributes` type.
- bumped minimum version of `@opentelemetry/api` peer dependency to 1.1.0 for the following packages: `@opentelemetry/core` [#4408](https://github.com/open-telemetry/opentelemetry-js/pull/4408), `@opentelemetry/resources` [#4428](https://github.com/open-telemetry/opentelemetry-js/pull/4428), `@opentelemetry/sdk-trace-base` [#5009](https://github.com/open-telemetry/opentelemetry-js/pull/5009), `@opentelemetry/shim-opentracing` [#4430](https://github.com/open-telemetry/opentelemetry-js/pull/4430)
<br/>
And finally:
- `@opentelemetry/sdk-node`: The type of `NodeSDKConfiguration.metricReader` has narrowed slightly from `MetricReader` to `IMetricReader`. [#5311](https://github.com/open-telemetry/opentelemetry-js/pull/5311)
- `@opentelemetry/exporter-jaeger`: `ReadableSpan.instrumentationLibrary` -> `ReadableSpan.instrumentationScope` [#5308](https://github.com/open-telemetry/opentelemetry-js/pull/5308)
- `@opentelemetry/exporter-zipkin`: `ReadableSpan.instrumentationLibrary` -> `ReadableSpan.instrumentationScope` [#5308](https://github.com/open-telemetry/opentelemetry-js/pull/5308)
- `@opentelemetry/exporter-prometheus`: Any non-monotonic sums will now be treated as counters and will now include the `_total` suffix. [#5291](https://github.com/open-telemetry/opentelemetry-js/pull/5291) [#5266 (comment)](https://github.com/open-telemetry/opentelemetry-js/pull/5266#issuecomment-2556564698)
- `@opentelemetry/shim-opencenus`: stop mapping removed Instrument `type` to OpenTelemetry metrics [#5291](https://github.com/open-telemetry/opentelemetry-js/pull/5291)
- `@opentelemetry/instrumentation-fetch`: Passthrough original response to `applyCustomAttributes` hook, rather than cloning the response. This means it is no longer possibly to consume the response in `applyCustomAttributes`. [#5281](https://github.com/open-telemetry/opentelemetry-js/pull/5281)

View File

@ -2,6 +2,7 @@
# CHANGELOG
All notable changes to experimental packages in this project will be documented in this file.
For notes on migrating to 2.x / 0.200.x see [the upgrade guide](doc/upgrade-to-2.x.md).
## Unreleased

View File

@ -19,7 +19,7 @@
"predocs-test": "npm run docs",
"docs": "typedoc --readme none && touch docs/.nojekyll",
"docs-deploy": "gh-pages --dotfiles --dist docs",
"docs:test": "linkinator docs --silent --retry && linkinator doc/*.md --skip http://localhost:3000 --skip http://localhost:9464 --silent --retry",
"docs:test": "linkinator docs --silent --retry && linkinator doc/*.md --skip http://localhost:3000 --skip http://localhost:9464 --silent --retry --directory-listing",
"lint": "lerna run lint && npm run lint:markdown && npm run lint:semconv-deps",
"lint:changed": "lerna run --concurrency 1 --stream lint --since HEAD --exclude-dependents",
"lint:fix": "lerna run lint:fix && npm run lint:markdown:fix",