Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[javascript] move to SDK 2.x #6441

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions content/en/docs/languages/js/_index.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ OpenTelemetry.
OpenTelemetry JavaScript has no official supported list of browsers. It is aimed
to work on currently supported versions of major browsers.

OpenTelemetry JavaScript follows DefinitelyType's support policy for TypeScript
which sets a support window of 2 years. Support for TypeScript versions older
than 2 years will be dropped in minor releases of OpenTelemetry JavaScript.

For more details on runtime support see
[this overview](https://github.com/open-telemetry/opentelemetry-js#supported-runtimes).

Expand Down
65 changes: 39 additions & 26 deletions content/en/docs/languages/js/instrumentation.md
Original file line number Diff line number Diff line change
Expand Up @@ -221,14 +221,14 @@ import {
PeriodicExportingMetricReader,
ConsoleMetricExporter,
} from '@opentelemetry/sdk-metrics';
import { Resource } from '@opentelemetry/resources';
import { resourceFromAttributes } from '@opentelemetry/resources';
import {
ATTR_SERVICE_NAME,
ATTR_SERVICE_VERSION,
} from '@opentelemetry/semantic-conventions';

const sdk = new NodeSDK({
resource: new Resource({
resource: resourceFromAttributes({
[ATTR_SERVICE_NAME]: 'yourServiceName',
[ATTR_SERVICE_VERSION]: '1.0',
}),
Expand All @@ -251,14 +251,14 @@ const {
PeriodicExportingMetricReader,
ConsoleMetricExporter,
} = require('@opentelemetry/sdk-metrics');
const { Resource } = require('@opentelemetry/resources');
const { resourceFromAttributes } = require('@opentelemetry/resources');
const {
ATTR_SERVICE_NAME,
ATTR_SERVICE_VERSION,
} = require('@opentelemetry/semantic-conventions');

const sdk = new NodeSDK({
resource: new Resource({
resource: resourceFromAttributes({
[ATTR_SERVICE_NAME]: 'dice-server',
[ATTR_SERVICE_VERSION]: '0.1.0',
}),
Expand Down Expand Up @@ -349,7 +349,10 @@ SDK initialization code in it:
{{< tabpane text=true >}} {{% tab TypeScript %}}

```ts
import { Resource } from '@opentelemetry/resources';
import {
defaultResource,
resourceFromAttributes,
} from '@opentelemetry/resources';
import {
ATTR_SERVICE_NAME,
ATTR_SERVICE_VERSION,
Expand All @@ -360,8 +363,8 @@ import {
ConsoleSpanExporter,
} from '@opentelemetry/sdk-trace-base';

const resource = Resource.default().merge(
new Resource({
const resource = defaultResource().merge(
resourceFromAttributes({
[ATTR_SERVICE_NAME]: 'service-name-here',
[ATTR_SERVICE_VERSION]: '0.1.0',
}),
Expand All @@ -382,7 +385,10 @@ provider.register();

```js
const opentelemetry = require('@opentelemetry/api');
const { Resource } = require('@opentelemetry/resources');
const {
defaultResource,
resourceFromAttributes,
} = require('@opentelemetry/resources');
const {
ATTR_SERVICE_NAME,
ATTR_SERVICE_VERSION,
Expand All @@ -393,8 +399,8 @@ const {
BatchSpanProcessor,
} = require('@opentelemetry/sdk-trace-base');

const resource = Resource.default().merge(
new Resource({
const resource = defaultResource().merge(
resourceFromAttributes({
[ATTR_SERVICE_NAME]: 'service-name-here',
[ATTR_SERVICE_VERSION]: '0.1.0',
}),
Expand Down Expand Up @@ -1286,14 +1292,17 @@ import {
MeterProvider,
PeriodicExportingMetricReader,
} from '@opentelemetry/sdk-metrics';
import { Resource } from '@opentelemetry/resources';
import {
defaultResource,
resourceFromAttributes,
} from '@opentelemetry/resources';
import {
ATTR_SERVICE_NAME,
ATTR_SERVICE_VERSION,
} from '@opentelemetry/semantic-conventions';

const resource = Resource.default().merge(
new Resource({
const resource = defaultResource().merge(
resourceFromAttributes({
[ATTR_SERVICE_NAME]: 'dice-server',
[ATTR_SERVICE_VERSION]: '0.1.0',
}),
Expand Down Expand Up @@ -1323,14 +1332,17 @@ const {
PeriodicExportingMetricReader,
ConsoleMetricExporter,
} = require('@opentelemetry/sdk-metrics');
const { Resource } = require('@opentelemetry/resources');
const {
defaultResource,
resourceFromAttributes,
} = require('@opentelemetry/resources');
const {
ATTR_SERVICE_NAME,
ATTR_SERVICE_VERSION,
} = require('@opentelemetry/semantic-conventions');

const resource = Resource.default().merge(
new Resource({
const resource = defaultResource().merge(
resourceFromAttributes({
[ATTR_SERVICE_NAME]: 'service-name-here',
[ATTR_SERVICE_VERSION]: '0.1.0',
}),
Expand Down Expand Up @@ -1761,33 +1773,34 @@ with `http` by using `http*`.
Filter attributes on all metric types:

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

Drop all instruments with the meter name `pubsub`:

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

Define explicit bucket sizes for the Histogram named `http.server.duration`:

```js
const histogramView = new View({
aggregation: new ExplicitBucketHistogramAggregation([
0, 1, 5, 10, 15, 20, 25, 30,
]),
const histogramView = {
aggregation: {
type: AggregationType.EXPLICIT_BUCKET_HISTOGRAM,
options: { boundaries: [0, 1, 5, 10, 15, 20, 25, 30] },
},
instrumentName: 'http.server.duration',
instrumentType: InstrumentType.HISTOGRAM,
});
};
```

#### Attach to meter provider
Expand Down
4 changes: 2 additions & 2 deletions content/en/docs/languages/js/resources.md
Original file line number Diff line number Diff line change
Expand Up @@ -91,12 +91,12 @@ configuration option, where you can set them. For example you can update the

```javascript
...
const { Resource } = require('@opentelemetry/resources');
const { resourceFromAttributes } = require('@opentelemetry/resources');
const { SEMRESATTRS_SERVICE_NAME, SEMRESATTRS_SERVICE_NAMESPACE, SEMRESATTRS_SERVICE_VERSION, SEMRESATTRS_SERVICE_INSTANCE_ID } = require('@opentelemetry/semantic-conventions');
...
const sdk = new opentelemetry.NodeSDK({
...
resource: new Resource({
resource: resourceFromAttributes({
[ SEMRESATTRS_SERVICE_NAME ]: "yourServiceName",
[ SEMRESATTRS_SERVICE_NAMESPACE ]: "yourNameSpace",
[ SEMRESATTRS_SERVICE_VERSION ]: "1.0",
Expand Down
15 changes: 7 additions & 8 deletions content/en/docs/languages/js/serverless.md
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ service. Please make sure that you provide a `SERVICE_NAME` and that you set the
```javascript
/* otelwrapper.js */

const { Resource } = require('@opentelemetry/resources');
const { resourceFromAttributes } = require('@opentelemetry/resources');
const {
SEMRESATTRS_SERVICE_NAME,
} = require('@opentelemetry/semantic-conventions');
Expand Down Expand Up @@ -271,13 +271,12 @@ Add the following to your `package.json`:
"@google-cloud/functions-framework": "^3.0.0",
"@opentelemetry/api": "^1.9.0",
"@opentelemetry/auto-instrumentations-node": "^0.56.1",
"@opentelemetry/exporter-trace-otlp-http": "^0.57.2",
"@opentelemetry/instrumentation": "^0.57.2",
"@opentelemetry/sdk-node": "^0.57.2",
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note for reviewers: this dependency was removed on purpose - it is not used in the above code so it can be safely dropped, which will reduce install size 🙂

"@opentelemetry/sdk-trace-base": "^1.30.1",
"@opentelemetry/sdk-trace-node": "^1.30.1",
"@opentelemetry/resources": "^1.30.1",
"@opentelemetry/semantic-conventions": "^1.30.0"
"@opentelemetry/exporter-trace-otlp-http": "^0.200.0",
"@opentelemetry/instrumentation": "^0.200.0",
"@opentelemetry/sdk-trace-base": "^2.0.0",
"@opentelemetry/sdk-trace-node": "^2.0.0",
"@opentelemetry/resources": "^2.0.0",
"@opentelemetry/semantic-conventions": "^2.0.0"
}
}
```
Expand Down