Skip to content

Commit

Permalink
Merge branch 'main' into typescript-eslint-v8
Browse files Browse the repository at this point in the history
  • Loading branch information
loganrosen committed Feb 28, 2025
2 parents b8ab542 + 8e50498 commit 8281a76
Show file tree
Hide file tree
Showing 201 changed files with 24,947 additions and 34,589 deletions.
4 changes: 2 additions & 2 deletions .github/ISSUE_TEMPLATE/bug_report.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -67,14 +67,14 @@ body:
const opentelemetry = require('@opentelemetry/sdk-node');
const { getNodeAutoInstrumentations } = require('@opentelemetry/auto-instrumentations-node');
const { ConsoleSpanExporter } = require('@opentelemetry/sdk-trace-base');
const { Resource } = require('@opentelemetry/resources');
const { resourceFromAttributes } = require('@opentelemetry/resources');
const { SEMRESATTRS_SERVICE_NAME } = require('@opentelemetry/semantic-conventions');
// configure the SDK to export telemetry data to the console
// enable all auto-instrumentations from the meta package
const traceExporter = new ConsoleSpanExporter();
const sdk = new opentelemetry.NodeSDK({
resource: new Resource({
resource: resourceFromAttributes({
[SEMRESATTRS_SERVICE_NAME]: 'my-service',
}),
traceExporter,
Expand Down
20 changes: 20 additions & 0 deletions .github/workflows/fossa.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
name: FOSSA scanning

on:
push:
branches:
- main

permissions:
contents: read

jobs:
fossa:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2

- uses: fossas/fossa-action@93a52ecf7c3ac7eb40f5de77fd69b1a19524de94 # v1.5.0
with:
api-key: ${{secrets.FOSSA_API_KEY}}
team: OpenTelemetry
2 changes: 1 addition & 1 deletion .github/workflows/publish-to-npm.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,4 @@ jobs:
# (packages are in-fact published in the correct order), but the race on the registry still applies.
# If this happens, run the workflow again - there should be enough time for everything to settle until this workflow
# attempts to publish again.
run: npx lerna publish --concurrency 1 from-package --no-push --no-private --no-git-tag-version --no-verify-access --yes
run: npx lerna publish --concurrency 1 from-package --no-push --no-private --no-git-tag-version --no-verify-access --dist-tag=canary --yes
34 changes: 34 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ For semantic convention package changes, see the [semconv CHANGELOG](packages/se

### :boom: Breaking Change

* feat(sdk-trace-base)!: Add `parentSpanContext` and remove `parentSpanId` from `Span` and `ReadableSpan` [#5450](/~https://github.com/open-telemetry/opentelemetry-js/pull/5450) @JacksonWeber
* (user-facing): the SDK's `Span`s `parentSpanId` was replaced by `parentSpanContext`, to migrate to the new property, please replace `span.parentSpanId` -> `span.parentSpanContext?.spanId`
* feat(sdk-metrics)!: drop deprecated `type` field on `MetricDescriptor` [#5291](/~https://github.com/open-telemetry/opentelemetry-js/pull/5291) @chancancode
* feat(sdk-metrics)!: drop deprecated `InstrumentDescriptor` type; use `MetricDescriptor` instead [#5277](/~https://github.com/open-telemetry/opentelemetry-js/pull/5266) @chancancode
* feat(sdk-metrics)!: bump minimum version of `@opentelemetry/api` peer dependency to 1.9.0 [#5254](/~https://github.com/open-telemetry/opentelemetry-js/pull/5254) @chancancode
Expand Down Expand Up @@ -93,15 +95,46 @@ For semantic convention package changes, see the [semconv CHANGELOG](packages/se
* (user-facing): `baggageUtils.parsePairKeyValue` was an internal utility function that was unintentionally exported. It has been removed without replacement.
* (user-facing): `TimeOriginLegacy` has been removed without replacement.
* (user-facing): `isAttributeKey` was an internal utility function that was unintentionally exported. It has been removed without replacement.
* feat(sdk-trace-base)!: do not read environment variables from window in browsers [#5445](/~https://github.com/open-telemetry/opentelemetry-js/pull/5455) @pichlermarc
* (user-facing): all configuration previously possible via `window.OTEL_*` is now not supported anymore, please pass configuration options to constructors instead.
* Note: Node.js environment variable configuration continues to work as-is.
* feat(exporter-zipkin)!: do not read environment variables from window in browsers [#5465](/~https://github.com/open-telemetry/opentelemetry-js/pull/5465) @pichlermarc
* (user-facing): all configuration previously possible via `window.OTEL_*` is now not supported anymore, please pass configuration options to constructors instead.
* Note: Node.js environment variable configuration continues to work as-is.
* feat(resource)!: Remove resource class export in favor of functions and types only to aid in cross-version compatibility [#5421](/~https://github.com/open-telemetry/opentelemetry-js/pull/5421)
* Renames `Resource` class to `ResourceImpl` and makes it package-private
* Renames `IResource` interface to `Resource`
* Export function `resourceFromAttributes` to create a `Resource` from a `DetectedAttributes` object
* Export function `defaultResource` to create a default resource [#5467](/~https://github.com/open-telemetry/opentelemetry-js/pull/5467) @pichlermarc
* Export function `emptyResource` to create an empty resource [#5467](/~https://github.com/open-telemetry/opentelemetry-js/pull/5467) @pichlermarc
* Only export types and functions. This aids in cross-version compatibility and makes it more easily extensible in the future.
* feat(resources)!: do not read environment variables from window in browsers [#5466](/~https://github.com/open-telemetry/opentelemetry-js/pull/5466) @pichlermarc
* (user-facing): all configuration previously possible via `window.OTEL_*` is now not supported anymore
* If you have been using the `envDetector` in browser environments, please migrate to manually creating a resource.
* Note: Node.js environment variable configuration continues to work as-is.
* fix(sdk-trace-base)!: use `ParentBasedAlwaysOnSampler` over `AlwaysOnSampler` when bogus data is supplied to `OTEL_TRACES_SAMPLER`
* this aligns the SDK implementation with the specification
* feat(core)!: drop `getEnv()`, `getEnvWithoutDefaults()` [#5481](/~https://github.com/open-telemetry/opentelemetry-js/pull/5481) @pichlermarc
* (user-facing): `getEnv()` has been replaced by `getStringFromEnv()`, `getNumberFromEnv()`, `getBooleanFromEnv()`, `getStringListFromEnv()`
* these new functions do not include defaults, please inline any defaults if necessary (example: `getStringFromEnv("OTEL_FOO") ?? "my-default"`)
* to find the previously used defaults, please see [here](/~https://github.com/open-telemetry/opentelemetry-js/blob/e9d3c71918635d490b6a9ac9f8259265b38394d0/packages/opentelemetry-core/src/utils/environment.ts#L154-L239)
* (user-facing): `getEnvWithoutDefaults()` has been replaced by `getStringFromEnv()`, `getNumberFromEnv()`, `getBooleanFromEnv()`, `getStringListFromEnv()`
* (user-facing): `DEFAULT_ENVIRONMENT` has been removed, please inline any defaults from now on
* to find the previously used defaults, please see [here](/~https://github.com/open-telemetry/opentelemetry-js/blob/e9d3c71918635d490b6a9ac9f8259265b38394d0/packages/opentelemetry-core/src/utils/environment.ts#L154-L239)
* (user-facing): `ENVIRONMENT` has been removed without replacement
* (user-facing): `RAW_ENVIRONMENT` has been removed without replacement
* (user-facing): `parseEnvironment` has been removed without replacement
* feat(sdk-trace-base): remove `BasicTracerProvider#register()` to improve tree-shaking [#5503](/~https://github.com/open-telemetry/opentelemetry-js/pull/5503) @pichlermarc
* (user-facing): `BasicTracerProvider#register()` has been removed
* to register a global propagator, please use `propagation.setGlobalPropagator()` from `@opentelemetry/api`
* to register a global context manager, please use `context.setGlobalContextManager()` from `@opentelemetry/api`
* feat!: set compilation target to ES2022 for all packages except `@opentelemetry/api`, `@opentelemetry/api-logs`, `@opentelemetry/api-events`, and `@opentelemetry/semantic-conventions` [#5456](/~https://github.com/open-telemetry/opentelemetry-js/pull/5456) @david-luna
* (user-facing): drops browser runtimes which do not support ES2022 features
* feat(core)! drop unused constants [#5504](/~https://github.com/open-telemetry/opentelemetry-js/pull/5504) @pichlermarc
* (user-facing): `DEFAULT_ATTRIBUTE_VALUE_LENTGHT_LIMIT` has been removed, please use `Infinity` instead
* (user-facing): `DEFAULT_ATTRIBUTE_VALUE_COUNT_LIMIT` has been removed, please use `128` instead
* (user-facing): `DEFAULT_SPAN_ATTRIBUTE_PER_EVENT_COUNT_LIMIT` has been removed, please use `128` instead
* (user-facing): `DEFAULT_SPAN_ATTRIBUTE_PER_LINK_COUNT_LIMIT` has been removed, please use `128` instead

### :rocket: (Enhancement)

Expand All @@ -110,6 +143,7 @@ For semantic convention package changes, see the [semconv CHANGELOG](packages/se
* feat(sdk-trace-base): add stack trace warning to debug instrumentation [#5363](/~https://github.com/open-telemetry/opentelemetry-js/pull/5363) @neilfordyce
* feat(core): add more scalable replacements for getEnv(), getEnvWithoutDefaults() [#5443](/~https://github.com/open-telemetry/opentelemetry-js/pull/5443) @pichlermarc
* refactor(exporter-jaeger): migrate away from getEnv() [#5464](/~https://github.com/open-telemetry/opentelemetry-js/pull/5464) @pichlermarc
* feat(core): add `diagLogLevelFromString` utility [#5475](/~https://github.com/open-telemetry/opentelemetry-js/pull/5475) @pichlermarc

### :bug: (Bug Fix)

Expand Down
9 changes: 1 addition & 8 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,15 +85,8 @@ for general practices for OpenTelemetry project.
#### Conventional commit

The Conventional Commits specification is a lightweight convention on top of commit messages. It provides an easy set of rules for creating an explicit commit history; which makes it easier to write automated tools on top of. This convention dovetails with SemVer, by describing the features, fixes, and breaking changes made in commit messages. You can see examples [here](https://www.conventionalcommits.org/en/v1.0.0-beta.4/#examples).
We use [commitlint](/~https://github.com/conventional-changelog/commitlint) and [husky](/~https://github.com/typicode/husky) to prevent bad commit message.
For example, you want to submit the following commit message `git commit -s -am "my bad commit"`.
You will receive the following error :

```text
✖ type must be one of [ci, feat, fix, docs, style, refactor, perf, test, revert, chore] [type-enum]
```

Here an example that will pass the verification: `git commit -s -am "chore(opentelemetry-core): update deps"`
It is recommended to have your commit messages follow the Conventional Commits specification, with possible types listed in [.commitlint.rc.yml](.commitlintrc.yml). Here an example that uses the recommended format: `git commit -s -am "chore(opentelemetry-core): update deps"`

### Changelog

Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -141,9 +141,9 @@ underlying language features used.
The current minumum language feature support is set as [ECMAScript 2020](https://262.ecma-international.org/11.0/) that are available
in all modern browsers / runtimes.

This means that if you are targeting or your end-users are using a browser / runtime that does not support ES2020, you will need
This means that if you are targeting or your end-users are using a browser / runtime that does not support ES2022, you will need
to transpile the code and provide any necessary polyfills for the missing features to ensure compatibility with your target
environments. Any support issues that arise from using a browser or runtime that does not support ES2020 will be closed as "won't fix".
environments. Any support issues that arise from using a browser or runtime that does not support ES2022 will be closed as "won't fix".

This minimum support level is subject to change as the project evolves and as the underlying language features evolve.

Expand Down
4 changes: 2 additions & 2 deletions api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,8 @@
},
"devDependencies": {
"@types/mocha": "10.0.10",
"@types/node": "18.6.5",
"@types/sinon": "17.0.3",
"@types/node": "^8.10.66",
"@types/sinon": "17.0.4",
"@types/webpack": "5.28.5",
"@types/webpack-env": "1.16.3",
"babel-plugin-istanbul": "7.0.0",
Expand Down
2 changes: 1 addition & 1 deletion api/src/platform/browser/globalThis.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,5 +34,5 @@ export const _globalThis: typeof globalThis =
: typeof window === 'object'
? window
: typeof global === 'object'
? global
? (global as unknown as typeof globalThis)
: ({} as typeof globalThis);
4 changes: 3 additions & 1 deletion api/test/common/baggage/Baggage.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,9 @@ describe('Baggage', () => {

const entry = bag.getEntry('key');
assert.ok(entry);
entry.value = 'mutated';
if (entry) {
entry.value = 'mutated';
}

assert.strictEqual(bag.getEntry('key')?.value, 'value');
});
Expand Down
4 changes: 2 additions & 2 deletions api/test/tree-shaking/tree-shaking.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
import * as assert from 'assert';
import { webpack, Stats } from 'webpack';
import * as path from 'path';
import { Union } from 'unionfs';
import { IFS, Union } from 'unionfs';
import { fs as mfs } from 'memfs';
import * as realFs from 'fs';

Expand Down Expand Up @@ -86,7 +86,7 @@ describe('tree-shaking', function () {
});

const fs = new Union();
fs.use(mfs as any).use(realFs);
fs.use(mfs as any).use(realFs as unknown as IFS);

// direct webpack to use unionfs for file input
// needs workaround from /~https://github.com/webpack/webpack/issues/18242#issuecomment-2018116985 since webpack 5.91.0
Expand Down
5 changes: 5 additions & 0 deletions api/tsconfig.esm.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
{
"extends": "../tsconfig.base.esm.json",
"compilerOptions": {
"lib": [
"es2017",
"dom"
],
"outDir": "build/esm",
"rootDir": "src",
"target": "es2017",
"tsBuildInfoFile": "build/esm/tsconfig.esm.tsbuildinfo"
},
"include": [
Expand Down
5 changes: 5 additions & 0 deletions api/tsconfig.esnext.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
{
"extends": "../tsconfig.base.esnext.json",
"compilerOptions": {
"lib": [
"es2017",
"dom"
],
"outDir": "build/esnext",
"rootDir": "src",
"target": "es2017",
"tsBuildInfoFile": "build/esnext/tsconfig.esnext.tsbuildinfo"
},
"include": [
Expand Down
7 changes: 6 additions & 1 deletion api/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
{
"extends": "../tsconfig.base.json",
"compilerOptions": {
"lib": [
"es2017",
"dom"
],
"outDir": "build",
"rootDir": "."
"rootDir": ".",
"target": "es2017"
},
"files": [],
"include": [
Expand Down
52 changes: 28 additions & 24 deletions doc/metrics.md
Original file line number Diff line number Diff line change
Expand Up @@ -362,13 +362,15 @@ for the resulting metric. The first step is select to the metrics to whom the Vi
is relevant, the second step is to configure the customizations for the the selected
metrics.

A Metric View is a class that can be instantiated via:
A Metric View can be added to a `MeterProvider` like so

````typescript
const view = new View({
name: 'metric-view', // optionally, give the view a unique name
// select instruments with a specific name
instrumentName: 'http.server.duration',
new MeterProvider({
views: [{
name: 'metric-view', // optionally, give the view a unique name
// select instruments with a specific name
instrumentName: 'http.server.duration',
}]
});
````

Expand Down Expand Up @@ -396,20 +398,22 @@ should be used to define the bucket sizes for the Histogram instrument.
Below an example is given how you can define explicit buckets for a histogram.

```typescript
// Define view for the histogram metric
const histogramView = new View({
aggregation: new ExplicitBucketHistogramAggregation([0, 1, 5, 10, 15, 20, 25, 30]),
instrumentName: 'http.server.duration',
instrumentType: InstrumentType.HISTOGRAM,
});

// Note, the instrumentName is the same as the name that has been passed for
// the Meter#createHistogram function

// Create an instance of the metric provider
const meterProvider = new MeterProvider({
views: [
histogramView
// Define view for the histogram metric
{
aggregation: {
type: AggregationType.EXPLICIT_BUCKET_HISTOGRAM,
options: {
boundaries: [0, 1, 5, 10, 15, 20, 25, 30],
}
},
// Note, the instrumentName is the same as the name that has been passed for
// the Meter#createHistogram function
instrumentName: 'http.server.duration',
instrumentType: InstrumentType.HISTOGRAM,
}
]
});

Expand Down Expand Up @@ -441,20 +445,20 @@ instruments with a specific name:
The following view drops all instruments that are associated with a meter named `pubsub`:

```typescript
const dropView = new View({
aggregation: new DropAggregation(),
{
aggregation: { type: AggregationType.DROP },
meterName: 'pubsub',
});
}
```

Alternatively, you can also drop instruments with a specific instrument name,
for example, all instruments of which the name starts with `http`:

```typescript
const dropView = new View({
aggregation: new DropAggregation(),
{
aggregation: { type: AggregationType.DROP },
instrumentName: 'http*',
});
}
```

### Customizing the metric attributes of instrument
Expand All @@ -467,12 +471,12 @@ In the example below will drop all attributes except attribute `environment` for
all instruments.

```typescript
new View({
{
// only export the attribute 'environment'
attributeKeys: ['environment'],
// apply the view to all instruments
instrumentName: '*',
})
}
```

## Exporting measurements
Expand Down
29 changes: 18 additions & 11 deletions examples/basic-tracer-node/index.js
Original file line number Diff line number Diff line change
@@ -1,24 +1,17 @@
'use strict';

const opentelemetry = require('@opentelemetry/api');
const { Resource } = require('@opentelemetry/resources');
const { resourceFromAttributes } = require('@opentelemetry/resources');
const { SEMRESATTRS_SERVICE_NAME } = require('@opentelemetry/semantic-conventions');
const { BasicTracerProvider, ConsoleSpanExporter, SimpleSpanProcessor } = require('@opentelemetry/sdk-trace-base');
const { JaegerExporter } = require('@opentelemetry/exporter-jaeger');
const { AsyncLocalStorageContextManager } = require("@opentelemetry/context-async-hooks");
const {CompositePropagator, W3CTraceContextPropagator, W3CBaggagePropagator} = require("@opentelemetry/core");

// Configure span processor to send spans to the exporter
const exporter = new JaegerExporter({
endpoint: 'http://localhost:14268/api/traces',
});
const provider = new BasicTracerProvider({
resource: new Resource({
[SEMRESATTRS_SERVICE_NAME]: 'basic-service',
}),
spanProcessors: [
new SimpleSpanProcessor(exporter),
new SimpleSpanProcessor(new ConsoleSpanExporter()),
]
});

/**
* Initialize the OpenTelemetry APIs to use the BasicTracerProvider bindings.
Expand All @@ -29,7 +22,21 @@ const provider = new BasicTracerProvider({
* do not register a global tracer provider, instrumentation which calls these
* methods will receive no-op implementations.
*/
provider.register();
opentelemetry.trace.setGlobalTracerProvider(new BasicTracerProvider({
resource: resourceFromAttributes({
[SEMRESATTRS_SERVICE_NAME]: 'basic-service',
}),
spanProcessors: [
new SimpleSpanProcessor(exporter),
new SimpleSpanProcessor(new ConsoleSpanExporter()),
]
}));
opentelemetry.context.setGlobalContextManager(new AsyncLocalStorageContextManager());
opentelemetry.propagation.setGlobalPropagator(new CompositePropagator({ propagators: [
new W3CTraceContextPropagator(),
new W3CBaggagePropagator()]
}));

const tracer = opentelemetry.trace.getTracer('example-basic-tracer-node');

// Create a span. A span must be closed.
Expand Down
4 changes: 2 additions & 2 deletions examples/esm-http-ts/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {
ConsoleSpanExporter,
SimpleSpanProcessor,
} from '@opentelemetry/sdk-trace-base';
import { Resource } from '@opentelemetry/resources';
import { resourceFromAttributes } from '@opentelemetry/resources';
import { SEMRESATTRS_SERVICE_NAME } from '@opentelemetry/semantic-conventions';
import http from 'http';

Expand All @@ -15,7 +15,7 @@ const exporter = new ConsoleSpanExporter();
const processor = new SimpleSpanProcessor(exporter);

const tracerProvider = new NodeTracerProvider({
resource: new Resource({
resource: resourceFromAttributes({
[SEMRESATTRS_SERVICE_NAME]: 'esm-http-ts-example',
}),
spanProcessors: [processor],
Expand Down
Loading

0 comments on commit 8281a76

Please sign in to comment.