Skip to content

Commit a2304c9

Browse files
Flarnamayurkale22dyladan
authored
chore: remove tracer apis not part of spec (#1764)
Co-authored-by: Mayur Kale <[email protected]> Co-authored-by: Daniel Dyla <[email protected]>
1 parent 16a3316 commit a2304c9

File tree

49 files changed

+310
-478
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+310
-478
lines changed

README.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,16 @@ To request automatic tracing support for a module not on this list, please [file
225225
|----------------------------------------------------------|-----------------------------------------------------------------------------------------|
226226
| [@opentelemetry/shim-opentracing][otel-shim-opentracing] | OpenTracing shim allows existing OpenTracing instrumentation to report to OpenTelemetry |
227227

228+
## Upgrade guidelines
229+
230+
### 0.14.0 to 0.15.0
231+
232+
[PR-1764](https://github.com/open-telemetry/opentelemetry-js/pull/1764) removed some APIs from `Tracer`:
233+
234+
- `Tracer.getCurrentSpan()`: use `api.getSpan(api.context.active())`
235+
- `Tracer.withSpan(span)`: use `api.context.with(api.setSpan(api.context.active(), span))`
236+
- `Tracer.bind(target)`: use `api.context.bind(target)`
237+
228238
## Useful links
229239

230240
- For more information on OpenTelemetry, visit: <https://opentelemetry.io/>

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.setSpan(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.setSpan(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.setSpan(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.getSpan(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.setSpan(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.getSpan(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.setSpan(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.getSpan(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.setSpan(api.context.active(), span), () => {
1415
https.get({
1516
host: 'localhost',
1617
port: 443,

0 commit comments

Comments
 (0)