11'use strict' ;
22
3- import * as api from '@opentelemetry/api' ;
3+ import * as api from '@opentelemetry/api' ;
44import { setupTracing } from './tracer' ;
55
6- const tracer = setupTracing ( 'example-mongodb-http-client' )
6+ const tracer = setupTracing ( 'example-mongodb-http-client' ) ;
77import * as http from 'http' ;
88
9-
109/** A function which makes requests and handles response. */
1110function makeRequest ( ) {
1211 // span corresponds to outgoing requests. Here, we have manually created
@@ -19,58 +18,71 @@ function makeRequest() {
1918
2019 api . context . with ( api . trace . setSpan ( api . ROOT_CONTEXT , span ) , ( ) => {
2120 queries += 1 ;
22- http . get ( {
23- host : 'localhost' ,
24- port : 8080 ,
25- path : '/collection/' ,
26- } , ( response ) => {
27- const body : any = [ ] ;
28- response . on ( 'data' , ( chunk ) => body . push ( chunk ) ) ;
29- response . on ( 'end' , ( ) => {
30- responses += 1 ;
31- console . log ( body . toString ( ) ) ;
32- if ( responses === queries ) span . end ( ) ;
33- } ) ;
34- } ) ;
21+ http . get (
22+ {
23+ host : 'localhost' ,
24+ port : 8080 ,
25+ path : '/collection/' ,
26+ } ,
27+ response => {
28+ const body : any = [ ] ;
29+ response . on ( 'data' , chunk => body . push ( chunk ) ) ;
30+ response . on ( 'end' , ( ) => {
31+ responses += 1 ;
32+ console . log ( body . toString ( ) ) ;
33+ if ( responses === queries ) span . end ( ) ;
34+ } ) ;
35+ }
36+ ) ;
3537 } ) ;
3638 api . context . with ( api . trace . setSpan ( api . ROOT_CONTEXT , span ) , ( ) => {
3739 queries += 1 ;
38- http . get ( {
39- host : 'localhost' ,
40- port : 8080 ,
41- path : '/insert/' ,
42- } , ( response ) => {
43- const body : any = [ ] ;
44- response . on ( 'data' , ( chunk ) => body . push ( chunk ) ) ;
45- response . on ( 'end' , ( ) => {
46- responses += 1 ;
47- console . log ( body . toString ( ) ) ;
48- if ( responses === queries ) span . end ( ) ;
49- } ) ;
50- } ) ;
40+ http . get (
41+ {
42+ host : 'localhost' ,
43+ port : 8080 ,
44+ path : '/insert/' ,
45+ } ,
46+ response => {
47+ const body : any = [ ] ;
48+ response . on ( 'data' , chunk => body . push ( chunk ) ) ;
49+ response . on ( 'end' , ( ) => {
50+ responses += 1 ;
51+ console . log ( body . toString ( ) ) ;
52+ if ( responses === queries ) span . end ( ) ;
53+ } ) ;
54+ }
55+ ) ;
5156 } ) ;
5257 api . context . with ( api . trace . setSpan ( api . ROOT_CONTEXT , span ) , ( ) => {
5358 queries += 1 ;
54- http . get ( {
55- host : 'localhost' ,
56- port : 8080 ,
57- path : '/get/' ,
58- } , ( response ) => {
59- const body : any = [ ] ;
60- response . on ( 'data' , ( chunk ) => body . push ( chunk ) ) ;
61- response . on ( 'end' , ( ) => {
62- responses += 1 ;
63- console . log ( body . toString ( ) ) ;
64- if ( responses === queries ) span . end ( ) ;
65- } ) ;
66- } ) ;
59+ http . get (
60+ {
61+ host : 'localhost' ,
62+ port : 8080 ,
63+ path : '/get/' ,
64+ } ,
65+ response => {
66+ const body : any = [ ] ;
67+ response . on ( 'data' , chunk => body . push ( chunk ) ) ;
68+ response . on ( 'end' , ( ) => {
69+ responses += 1 ;
70+ console . log ( body . toString ( ) ) ;
71+ if ( responses === queries ) span . end ( ) ;
72+ } ) ;
73+ }
74+ ) ;
6775 } ) ;
6876
6977 // The process must live for at least the interval past any traces that
7078 // must be exported, or some risk being lost if they are recorded after the
7179 // last export.
72- console . log ( 'Sleeping 5 seconds before shutdown to ensure all records are flushed.' ) ;
73- setTimeout ( ( ) => { console . log ( 'Completed.' ) ; } , 5000 ) ;
80+ console . log (
81+ 'Sleeping 5 seconds before shutdown to ensure all records are flushed.'
82+ ) ;
83+ setTimeout ( ( ) => {
84+ console . log ( 'Completed.' ) ;
85+ } , 5000 ) ;
7486}
7587
7688makeRequest ( ) ;
0 commit comments