Skip to content

Commit

Permalink
fix: fix js example code, update dice generator
Browse files Browse the repository at this point in the history
  • Loading branch information
oscar60310 committed Nov 8, 2024
1 parent 5b80dbb commit 3d2c550
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 14 deletions.
4 changes: 2 additions & 2 deletions content/en/docs/languages/js/getting-started/nodejs.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ const PORT: number = parseInt(process.env.PORT || '8080');
const app: Express = express();

function getRandomNumber(min: number, max: number) {
return Math.floor(Math.random() * (max - min) + min);
return Math.floor(Math.random() * (max - min + 1) + min);
}

app.get('/rolldice', (req, res) => {
Expand All @@ -102,7 +102,7 @@ const PORT = parseInt(process.env.PORT || '8080');
const app = express();

function getRandomNumber(min, max) {
return Math.floor(Math.random() * (max - min) + min);
return Math.floor(Math.random() * (max - min + 1) + min);
}

app.get('/rolldice', (req, res) => {
Expand Down
24 changes: 12 additions & 12 deletions content/en/docs/languages/js/instrumentation.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ TypeScript) and add the following code to it:
```ts
/*dice.ts*/
function rollOnce(min: number, max: number) {
return Math.floor(Math.random() * (max - min) + min);
return Math.floor(Math.random() * (max - min + 1) + min);
}

export function rollTheDice(rolls: number, min: number, max: number) {
Expand All @@ -92,7 +92,7 @@ export function rollTheDice(rolls: number, min: number, max: number) {
```js
/*dice.js*/
function rollOnce(min, max) {
return Math.floor(Math.random() * (max - min) + min);
return Math.floor(Math.random() * (max - min + 1) + min);
}

function rollTheDice(rolls, min, max) {
Expand Down Expand Up @@ -558,7 +558,7 @@ import { trace } from '@opentelemetry/api';
const tracer = trace.getTracer('dice-lib');

function rollOnce(min: number, max: number) {
return Math.floor(Math.random() * (max - min) + min);
return Math.floor(Math.random() * (max - min + 1) + min);
}

export function rollTheDice(rolls: number, min: number, max: number) {
Expand All @@ -579,7 +579,7 @@ const { trace } = require('@opentelemetry/api');
const tracer = trace.getTracer('dice-lib');

function rollOnce(min, max) {
return Math.floor(Math.random() * (max - min) + min);
return Math.floor(Math.random() * (max - min + 1) + min);
}

function rollTheDice(rolls, min, max) {
Expand Down Expand Up @@ -707,7 +707,7 @@ nested operation. The following sample creates a nested span that tracks
```ts
function rollOnce(i: number, min: number, max: number) {
return tracer.startActiveSpan(`rollOnce:${i}`, (span: Span) => {
const result = Math.floor(Math.random() * (max - min) + min);
const result = Math.floor(Math.random() * (max - min + 1) + min);
span.end();
return result;
});
Expand All @@ -732,7 +732,7 @@ export function rollTheDice(rolls: number, min: number, max: number) {
```js
function rollOnce(i, min, max) {
return tracer.startActiveSpan(`rollOnce:${i}`, (span) => {
const result = Math.floor(Math.random() * (max - min) + min);
const result = Math.floor(Math.random() * (max - min + 1) + min);
span.end();
return result;
});
Expand Down Expand Up @@ -849,7 +849,7 @@ information about the current operation that it's tracking.
```ts
function rollOnce(i: number, min: number, max: number) {
return tracer.startActiveSpan(`rollOnce:${i}`, (span: Span) => {
const result = Math.floor(Math.random() * (max - min) + min);
const result = Math.floor(Math.random() * (max - min + 1) + min);

// Add an attribute to the span
span.setAttribute('dicelib.rolled', result.toString());
Expand All @@ -865,7 +865,7 @@ function rollOnce(i: number, min: number, max: number) {
```js
function rollOnce(i, min, max) {
return tracer.startActiveSpan(`rollOnce:${i}`, (span) => {
const result = Math.floor(Math.random() * (max - min) + min);
const result = Math.floor(Math.random() * (max - min + 1) + min);

// Add an attribute to the span
span.setAttribute('dicelib.rolled', result.toString());
Expand Down Expand Up @@ -1466,7 +1466,7 @@ const tracer = trace.getTracer('dice-lib');
const meter = metrics.getMeter('dice-lib');

function rollOnce(min: number, max: number) {
return Math.floor(Math.random() * (max - min) + min);
return Math.floor(Math.random() * (max - min + 1) + min);
}

export function rollTheDice(rolls: number, min: number, max: number) {
Expand All @@ -1488,7 +1488,7 @@ const tracer = trace.getTracer('dice-lib');
const meter = metrics.getMeter('dice-lib');

function rollOnce(min, max) {
return Math.floor(Math.random() * (max - min) + min);
return Math.floor(Math.random() * (max - min + 1) + min);
}

function rollTheDice(rolls, min, max) {
Expand Down Expand Up @@ -1523,7 +1523,7 @@ const counter = meter.createCounter('dice-lib.rolls.counter');

function rollOnce(min: number, max: number) {
counter.add(1);
return Math.floor(Math.random() * (max - min) + min);
return Math.floor(Math.random() * (max - min + 1) + min);
}
```

Expand All @@ -1535,7 +1535,7 @@ const counter = meter.createCounter('dice-lib.rolls.counter');

function rollOnce(min, max) {
counter.add(1);
return Math.floor(Math.random() * (max - min) + min);
return Math.floor(Math.random() * (max - min + 1) + min);
}
```

Expand Down

0 comments on commit 3d2c550

Please sign in to comment.