Skip to content

Commit 752f76f

Browse files
committed
chore: update samples and readme
1 parent 7286e6d commit 752f76f

File tree

15 files changed

+58
-60
lines changed

15 files changed

+58
-60
lines changed

examples/basic-tracer-node/index.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,8 @@ exporter.shutdown();
3737
function doWork(parent) {
3838
// Start another span. In this example, the main method already started a
3939
// span, so that'll be the parent span, and this will be a child span.
40-
const span = tracer.startSpan('doWork', {
41-
parent,
42-
});
40+
const ctx = opentelemetry.setActiveSpan(opentelemetry.context.active(), parent);
41+
const span = tracer.startSpan('doWork', undefined, ctx);
4342

4443
// simulate some random work.
4544
for (let i = 0; i <= Math.floor(Math.random() * 40000000); i += 1) {

examples/collector-exporter-node/tracing.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,8 @@ setTimeout(() => {
3939
function doWork(parent) {
4040
// Start another span. In this example, the main method already started a
4141
// span, so that'll be the parent span, and this will be a child span.
42-
const span = tracer.startSpan('doWork', {
43-
parent,
44-
});
42+
const ctx = opentelemetry.setActiveSpan(opentelemetry.context.active(), parent);
43+
const span = tracer.startSpan('doWork', undefined, ctx);
4544

4645
// simulate some random work.
4746
for (let i = 0; i <= Math.floor(Math.random() * 40000000); i += 1) {

examples/grpc-js/client.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
'use strict';
22

3+
const api = require('@opentelemetry/api');
34
const tracer = require('./tracer')('example-grpc-client');
45
// eslint-disable-next-line import/order
56
const grpc = require('@grpc/grpc-js');
@@ -14,7 +15,7 @@ function main() {
1415
// the span, which is created to track work that happens outside of the
1516
// request lifecycle entirely.
1617
const span = tracer.startSpan('client.js:main()');
17-
tracer.withSpan(span, () => {
18+
api.context.with(api.setActiveSpan(api.context.active(), span), () => {
1819
console.log('Client traceId ', span.context().traceId);
1920
const client = new services.GreeterClient(
2021
`localhost:${PORT}`,

examples/grpc-js/server.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
'use strict';
22

3+
const api = require('@opentelemetry/api');
34
const tracer = require('./tracer')(('example-grpc-server'));
45
// eslint-disable-next-line import/order
56
const grpc = require('@grpc/grpc-js');
@@ -21,11 +22,10 @@ function startServer() {
2122
}
2223

2324
function sayHello(call, callback) {
24-
const currentSpan = tracer.getCurrentSpan();
25+
const currentSpan = api.getActiveSpan(api.context.active());
2526
// display traceid in the terminal
2627
console.log(`traceid: ${currentSpan.context().traceId}`);
2728
const span = tracer.startSpan('server.js:sayHello()', {
28-
parent: currentSpan,
2929
kind: 1, // server
3030
attributes: { key: 'value' },
3131
});

examples/grpc/client.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
'use strict';
22

3+
const api = require('@opentelemetry/api');
34
const tracer = require('./tracer')('example-grpc-client');
45
// eslint-disable-next-line import/order
56
const grpc = require('grpc');
@@ -14,7 +15,7 @@ function main() {
1415
// the span, which is created to track work that happens outside of the
1516
// request lifecycle entirely.
1617
const span = tracer.startSpan('client.js:main()');
17-
tracer.withSpan(span, () => {
18+
api.context.with(api.setActiveSpan(api.context.active(), span), () => {
1819
console.log('Client traceId ', span.context().traceId);
1920
const client = new services.GreeterClient(
2021
`localhost:${PORT}`,

examples/grpc/server.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
'use strict';
22

3+
const api = require('@opentelemetry/api');
34
const tracer = require('./tracer')(('example-grpc-server'));
45
// eslint-disable-next-line import/order
56
const grpc = require('grpc');
@@ -20,7 +21,7 @@ function startServer() {
2021
}
2122

2223
function sayHello(call, callback) {
23-
const currentSpan = tracer.getCurrentSpan();
24+
const currentSpan = api.getActiveSpan(api.context.active());
2425
// display traceid in the terminal
2526
console.log(`traceid: ${currentSpan.context().traceId}`);
2627
const span = tracer.startSpan('server.js:sayHello()', {

examples/http/client.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
'use strict';
22

3+
const api = require('@opentelemetry/api');
34
const tracer = require('./tracer')('example-http-client');
45
// eslint-disable-next-line import/order
56
const http = require('http');
@@ -10,7 +11,7 @@ function makeRequest() {
1011
// the span, which is created to track work that happens outside of the
1112
// request lifecycle entirely.
1213
const span = tracer.startSpan('makeRequest');
13-
tracer.withSpan(span, () => {
14+
api.context.with(api.setActiveSpan(api.context.active(), span), () => {
1415
http.get({
1516
host: 'localhost',
1617
port: 8080,

examples/http/server.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
'use strict';
22

3+
const api = require('@opentelemetry/api');
34
const tracer = require('./tracer')('example-http-server');
45
// eslint-disable-next-line import/order
56
const http = require('http');
@@ -19,11 +20,10 @@ function startServer(port) {
1920

2021
/** A function which handles requests and send response. */
2122
function handleRequest(request, response) {
22-
const currentSpan = tracer.getCurrentSpan();
23+
const currentSpan = api.getActiveSpan(api.context.active());
2324
// display traceid in the terminal
2425
console.log(`traceid: ${currentSpan.context().traceId}`);
2526
const span = tracer.startSpan('handleRequest', {
26-
parent: currentSpan,
2727
kind: 1, // server
2828
attributes: { key: 'value' },
2929
});

examples/https/client.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
'use strict';
22

3+
const api = require('@opentelemetry/api');
34
const tracer = require('./tracer')('example-https-client');
45
// eslint-disable-next-line import/order
56
const https = require('https');
@@ -10,7 +11,7 @@ function makeRequest() {
1011
// the span, which is created to track work that happens outside of the
1112
// request lifecycle entirely.
1213
const span = tracer.startSpan('makeRequest');
13-
tracer.withSpan(span, () => {
14+
api.context.with(api.setActiveSpan(api.context.active(), span), () => {
1415
https.get({
1516
host: 'localhost',
1617
port: 443,

examples/https/server.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
'use strict';
22

3+
const api = require('@opentelemetry/api');
34
// eslint-disable-next-line import/order
45
const tracer = require('./tracer')('example-https-server');
56
const fs = require('fs');
@@ -24,11 +25,10 @@ function startServer(port) {
2425

2526
/** A function which handles requests and send response. */
2627
function handleRequest(request, response) {
27-
const currentSpan = tracer.getCurrentSpan();
28+
const currentSpan = api.getActiveSpan(api.context.active());
2829
// display traceid in the terminal
2930
console.log(`traceid: ${currentSpan.context().traceId}`);
3031
const span = tracer.startSpan('handleRequest', {
31-
parent: currentSpan,
3232
kind: 1, // server
3333
attributes: { key: 'value' },
3434
});

0 commit comments

Comments
 (0)