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
317import * as api from '@opentelemetry/api' ;
4- import { setupTracing } from "./tracer" ;
5- const tracer = setupTracing ( 'example-mysql-client' ) ;
618import * as http from 'http' ;
19+ // eslint-disable-next-line import/extensions
20+ import { setupTracing } from './tracer' ;
21+
22+ const tracer = setupTracing ( 'example-mysql-client' ) ;
723
824/** A function which makes requests and handles response. */
925function makeRequest ( ) {
@@ -17,90 +33,109 @@ function makeRequest() {
1733
1834 api . context . with ( api . trace . setSpan ( api . ROOT_CONTEXT , span ) , ( ) => {
1935 queries += 1 ;
20- http . get ( {
21- host : 'localhost' ,
22- port : 8080 ,
23- path : '/connection/query' ,
24- } , ( response ) => {
25- const body : any [ ] = [ ] ;
26- response . on ( 'data' , ( chunk ) => body . push ( chunk ) ) ;
27- response . on ( 'end' , ( ) => {
28- responses += 1 ;
29- console . log ( body . toString ( ) ) ;
30- if ( responses === queries ) span . end ( ) ;
31- } ) ;
32- } ) ;
36+ http . get (
37+ {
38+ host : 'localhost' ,
39+ port : 8080 ,
40+ path : '/connection/query' ,
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+ ) ;
3352 } ) ;
3453 api . context . with ( api . trace . setSpan ( api . ROOT_CONTEXT , span ) , ( ) => {
3554 queries += 1 ;
36- http . get ( {
37- host : 'localhost' ,
38- port : 8080 ,
39- path : '/pool/query' ,
40- } , ( response ) => {
41- const body : any [ ] = [ ] ;
42- response . on ( 'data' , ( chunk ) => body . push ( chunk ) ) ;
43- response . on ( 'end' , ( ) => {
44- responses += 1 ;
45- console . log ( body . toString ( ) ) ;
46- if ( responses === queries ) span . end ( ) ;
47- } ) ;
48- } ) ;
55+ http . get (
56+ {
57+ host : 'localhost' ,
58+ port : 8080 ,
59+ path : '/pool/query' ,
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+ ) ;
4971 } ) ;
5072 api . context . with ( api . trace . setSpan ( api . ROOT_CONTEXT , span ) , ( ) => {
5173 queries += 1 ;
52- http . get ( {
53- host : 'localhost' ,
54- port : 8080 ,
55- path : '/pool/query-with-2-connections' ,
56- } , ( response ) => {
57- const body : any [ ] = [ ] ;
58- response . on ( 'data' , ( chunk ) => body . push ( chunk ) ) ;
59- response . on ( 'end' , ( ) => {
60- responses += 1 ;
61- console . log ( body . toString ( ) ) ;
62- if ( responses === queries ) span . end ( ) ;
63- } ) ;
64- } ) ;
74+ http . get (
75+ {
76+ host : 'localhost' ,
77+ port : 8080 ,
78+ path : '/pool/query-with-2-connections' ,
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+ ) ;
6590 } ) ;
6691 api . context . with ( api . trace . setSpan ( api . ROOT_CONTEXT , span ) , ( ) => {
6792 queries += 1 ;
68- http . get ( {
69- host : 'localhost' ,
70- port : 8080 ,
71- path : '/pool/query-2-pools' ,
72- } , ( response ) => {
73- const body : any [ ] = [ ] ;
74- response . on ( 'data' , ( chunk ) => body . push ( chunk ) ) ;
75- response . on ( 'end' , ( ) => {
76- responses += 1 ;
77- console . log ( body . toString ( ) ) ;
78- if ( responses === queries ) span . end ( ) ;
79- } ) ;
80- } ) ;
93+ http . get (
94+ {
95+ host : 'localhost' ,
96+ port : 8080 ,
97+ path : '/pool/query-2-pools' ,
98+ } ,
99+ response => {
100+ const body : any [ ] = [ ] ;
101+ response . on ( 'data' , chunk => body . push ( chunk ) ) ;
102+ response . on ( 'end' , ( ) => {
103+ responses += 1 ;
104+ console . log ( body . toString ( ) ) ;
105+ if ( responses === queries ) span . end ( ) ;
106+ } ) ;
107+ }
108+ ) ;
81109 } ) ;
82110 api . context . with ( api . trace . setSpan ( api . ROOT_CONTEXT , span ) , ( ) => {
83111 queries += 1 ;
84- http . get ( {
85- host : 'localhost' ,
86- port : 8080 ,
87- path : '/cluster/query' ,
88- } , ( response ) => {
89- const body : any [ ] = [ ] ;
90- response . on ( 'data' , ( chunk ) => body . push ( chunk ) ) ;
91- response . on ( 'end' , ( ) => {
92- responses += 1 ;
93- console . log ( body . toString ( ) ) ;
94- if ( responses === queries ) span . end ( ) ;
95- } ) ;
96- } ) ;
112+ http . get (
113+ {
114+ host : 'localhost' ,
115+ port : 8080 ,
116+ path : '/cluster/query' ,
117+ } ,
118+ response => {
119+ const body : any [ ] = [ ] ;
120+ response . on ( 'data' , chunk => body . push ( chunk ) ) ;
121+ response . on ( 'end' , ( ) => {
122+ responses += 1 ;
123+ console . log ( body . toString ( ) ) ;
124+ if ( responses === queries ) span . end ( ) ;
125+ } ) ;
126+ }
127+ ) ;
97128 } ) ;
98129
99130 // The process must live for at least the interval past any traces that
100131 // must be exported, or some risk being lost if they are recorded after the
101132 // last export.
102- console . log ( 'Sleeping 5 seconds before shutdown to ensure all records are flushed.' ) ;
103- setTimeout ( ( ) => { console . log ( 'Completed.' ) ; } , 5000 ) ;
133+ console . log (
134+ 'Sleeping 5 seconds before shutdown to ensure all records are flushed.'
135+ ) ;
136+ setTimeout ( ( ) => {
137+ console . log ( 'Completed.' ) ;
138+ } , 5000 ) ;
104139}
105140
106141makeRequest ( ) ;
0 commit comments