Skip to content

Commit

Permalink
docs: fix code example in README (open-telemetry#4726)
Browse files Browse the repository at this point in the history
  • Loading branch information
trentm authored and Zirak committed Sep 14, 2024
1 parent 477b427 commit e3706bd
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions packages/sdk-metrics/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@ const { MeterProvider } = require('@opentelemetry/sdk-metrics');
// To create an instrument, you first need to initialize the Meter provider.
// NOTE: The default OpenTelemetry meter provider does not record any metric instruments.
// Registering a working meter provider allows the API methods to record instruments.
opentelemetry.setGlobalMeterProvider(new MeterProvider());
opentelemetry.metrics.setGlobalMeterProvider(new MeterProvider());

// To record a metric event, we used the global singleton meter to create an instrument.
const counter = opentelemetry.getMeter('default').createCounter('foo');
const counter = opentelemetry.metrics.getMeter('default').createCounter('foo');

// record a metric event.
counter.add(1, { attributeKey: 'attribute-value' });
Expand All @@ -40,7 +40,7 @@ In conditions, we may need to setup an async instrument to observe costly events

```js
// Creating an async instrument, similar to synchronous instruments
const observableCounter = opentelemetry.getMeter('default')
const observableCounter = opentelemetry.metrics.getMeter('default')
.createObservableCounter('observable-counter');

// Register a single-instrument callback to the async instrument.
Expand All @@ -50,7 +50,7 @@ observableCounter.addCallback(async (observableResult) => {
});

// Register a multi-instrument callback and associate it with a set of async instruments.
opentelemetry.getMeter('default')
opentelemetry.metrics.getMeter('default')
.addBatchObservableCallback(batchObservableCallback, [ observableCounter ]);
async function batchObservableCallback(batchObservableResult) {
// ... do async stuff
Expand Down

0 comments on commit e3706bd

Please sign in to comment.