1- 'use strict' ;
1+ /*
2+ * Copyright The OpenTelemetry Authors
3+ *
4+ * Licensed under the Apache License, Version 2.0 (the "License");
5+ * you may not use this file except in compliance with the License.
6+ * You may obtain a copy of the License at
7+ *
8+ * https://www.apache.org/licenses/LICENSE-2.0
9+ *
10+ * Unless required by applicable law or agreed to in writing, software
11+ * distributed under the License is distributed on an "AS IS" BASIS,
12+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+ * See the License for the specific language governing permissions and
14+ * limitations under the License.
15+ */
216
3- import * as api from '@opentelemetry/api' ;
4- import { setupTracing } from './tracer' ;
5-
6- const tracer = setupTracing ( 'example-mongodb-http-client' )
17+ import * as api from '@opentelemetry/api' ;
718import * as http from 'http' ;
19+ // eslint-disable-next-line import/extensions
20+ import { setupTracing } from './tracer' ;
821
22+ const tracer = setupTracing ( 'example-mongodb-http-client' ) ;
923
1024/** A function which makes requests and handles response. */
1125function makeRequest ( ) {
@@ -19,58 +33,71 @@ function makeRequest() {
1933
2034 api . context . with ( api . trace . setSpan ( api . ROOT_CONTEXT , span ) , ( ) => {
2135 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- } ) ;
36+ http . get (
37+ {
38+ host : 'localhost' ,
39+ port : 8080 ,
40+ path : '/collection/' ,
41+ } ,
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+ }
51+ ) ;
3552 } ) ;
3653 api . context . with ( api . trace . setSpan ( api . ROOT_CONTEXT , span ) , ( ) => {
3754 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- } ) ;
55+ http . get (
56+ {
57+ host : 'localhost' ,
58+ port : 8080 ,
59+ path : '/insert/' ,
60+ } ,
61+ response => {
62+ const body : any = [ ] ;
63+ response . on ( 'data' , chunk => body . push ( chunk ) ) ;
64+ response . on ( 'end' , ( ) => {
65+ responses += 1 ;
66+ console . log ( body . toString ( ) ) ;
67+ if ( responses === queries ) span . end ( ) ;
68+ } ) ;
69+ }
70+ ) ;
5171 } ) ;
5272 api . context . with ( api . trace . setSpan ( api . ROOT_CONTEXT , span ) , ( ) => {
5373 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- } ) ;
74+ http . get (
75+ {
76+ host : 'localhost' ,
77+ port : 8080 ,
78+ path : '/get/' ,
79+ } ,
80+ response => {
81+ const body : any = [ ] ;
82+ response . on ( 'data' , chunk => body . push ( chunk ) ) ;
83+ response . on ( 'end' , ( ) => {
84+ responses += 1 ;
85+ console . log ( body . toString ( ) ) ;
86+ if ( responses === queries ) span . end ( ) ;
87+ } ) ;
88+ }
89+ ) ;
6790 } ) ;
6891
6992 // The process must live for at least the interval past any traces that
7093 // must be exported, or some risk being lost if they are recorded after the
7194 // last export.
72- console . log ( 'Sleeping 5 seconds before shutdown to ensure all records are flushed.' ) ;
73- setTimeout ( ( ) => { console . log ( 'Completed.' ) ; } , 5000 ) ;
95+ console . log (
96+ 'Sleeping 5 seconds before shutdown to ensure all records are flushed.'
97+ ) ;
98+ setTimeout ( ( ) => {
99+ console . log ( 'Completed.' ) ;
100+ } , 5000 ) ;
74101}
75102
76103makeRequest ( ) ;
0 commit comments