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
+ */
2
16
3
17
import * as api from '@opentelemetry/api' ;
4
- import { setupTracing } from "./tracer" ;
5
- const tracer = setupTracing ( 'example-mysql-client' ) ;
6
18
import * as http from 'http' ;
19
+ // eslint-disable-next-line import/extensions
20
+ import { setupTracing } from './tracer' ;
21
+
22
+ const tracer = setupTracing ( 'example-mysql-client' ) ;
7
23
8
24
/** A function which makes requests and handles response. */
9
25
function makeRequest ( ) {
@@ -17,90 +33,109 @@ function makeRequest() {
17
33
18
34
api . context . with ( api . trace . setSpan ( api . ROOT_CONTEXT , span ) , ( ) => {
19
35
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
+ ) ;
33
52
} ) ;
34
53
api . context . with ( api . trace . setSpan ( api . ROOT_CONTEXT , span ) , ( ) => {
35
54
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
+ ) ;
49
71
} ) ;
50
72
api . context . with ( api . trace . setSpan ( api . ROOT_CONTEXT , span ) , ( ) => {
51
73
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
+ ) ;
65
90
} ) ;
66
91
api . context . with ( api . trace . setSpan ( api . ROOT_CONTEXT , span ) , ( ) => {
67
92
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
+ ) ;
81
109
} ) ;
82
110
api . context . with ( api . trace . setSpan ( api . ROOT_CONTEXT , span ) , ( ) => {
83
111
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
+ ) ;
97
128
} ) ;
98
129
99
130
// The process must live for at least the interval past any traces that
100
131
// must be exported, or some risk being lost if they are recorded after the
101
132
// 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 ) ;
104
139
}
105
140
106
141
makeRequest ( ) ;
0 commit comments