File tree Expand file tree Collapse file tree 15 files changed +58
-60
lines changed
opentelemetry-context-zone-peer-dep
opentelemetry-context-zone Expand file tree Collapse file tree 15 files changed +58
-60
lines changed Original file line number Diff line number Diff line change @@ -37,9 +37,8 @@ exporter.shutdown();
3737function 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 ) {
Original file line number Diff line number Diff line change @@ -39,9 +39,8 @@ setTimeout(() => {
3939function 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 ) {
Original file line number Diff line number Diff line change 11'use strict' ;
22
3+ const api = require ( '@opentelemetry/api' ) ;
34const tracer = require ( './tracer' ) ( 'example-grpc-client' ) ;
45// eslint-disable-next-line import/order
56const 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 } ` ,
Original file line number Diff line number Diff line change 11'use strict' ;
22
3+ const api = require ( '@opentelemetry/api' ) ;
34const tracer = require ( './tracer' ) ( ( 'example-grpc-server' ) ) ;
45// eslint-disable-next-line import/order
56const grpc = require ( '@grpc/grpc-js' ) ;
@@ -21,11 +22,10 @@ function startServer() {
2122}
2223
2324function 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 } ) ;
Original file line number Diff line number Diff line change 11'use strict' ;
22
3+ const api = require ( '@opentelemetry/api' ) ;
34const tracer = require ( './tracer' ) ( 'example-grpc-client' ) ;
45// eslint-disable-next-line import/order
56const 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 } ` ,
Original file line number Diff line number Diff line change 11'use strict' ;
22
3+ const api = require ( '@opentelemetry/api' ) ;
34const tracer = require ( './tracer' ) ( ( 'example-grpc-server' ) ) ;
45// eslint-disable-next-line import/order
56const grpc = require ( 'grpc' ) ;
@@ -20,7 +21,7 @@ function startServer() {
2021}
2122
2223function 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()' , {
Original file line number Diff line number Diff line change 11'use strict' ;
22
3+ const api = require ( '@opentelemetry/api' ) ;
34const tracer = require ( './tracer' ) ( 'example-http-client' ) ;
45// eslint-disable-next-line import/order
56const 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 ,
Original file line number Diff line number Diff line change 11'use strict' ;
22
3+ const api = require ( '@opentelemetry/api' ) ;
34const tracer = require ( './tracer' ) ( 'example-http-server' ) ;
45// eslint-disable-next-line import/order
56const http = require ( 'http' ) ;
@@ -19,11 +20,10 @@ function startServer(port) {
1920
2021/** A function which handles requests and send response. */
2122function 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 } ) ;
Original file line number Diff line number Diff line change 11'use strict' ;
22
3+ const api = require ( '@opentelemetry/api' ) ;
34const tracer = require ( './tracer' ) ( 'example-https-client' ) ;
45// eslint-disable-next-line import/order
56const 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 ,
Original file line number Diff line number Diff line change 11'use strict' ;
22
3+ const api = require ( '@opentelemetry/api' ) ;
34// eslint-disable-next-line import/order
45const tracer = require ( './tracer' ) ( 'example-https-server' ) ;
56const fs = require ( 'fs' ) ;
@@ -24,11 +25,10 @@ function startServer(port) {
2425
2526/** A function which handles requests and send response. */
2627function 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 } ) ;
You can’t perform that action at this time.
0 commit comments