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

Fix: fix dice number generator in JS examples #5565

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: 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