|
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 | | -import { setupTracing } from "./tracer"; |
4 | | -const tracer = setupTracing('example-redis-client'); |
5 | 17 | import * as api from '@opentelemetry/api'; |
6 | | -import { default as axios } from 'axios'; |
| 18 | +import * as axios from 'axios'; |
| 19 | +// eslint-disable-next-line import/extensions |
| 20 | +import { setupTracing } from './tracer'; |
| 21 | + |
| 22 | +const tracer = setupTracing('example-redis-client'); |
7 | 23 |
|
8 | | -function makeRequest() { |
| 24 | +async function makeRequest() { |
9 | 25 | const span = tracer.startSpan('client.makeRequest()', { |
10 | 26 | kind: api.SpanKind.CLIENT, |
11 | 27 | }); |
12 | 28 |
|
13 | | - api.context.with(api.trace.setSpan(api.ROOT_CONTEXT, span), async () => { |
14 | | - try { |
15 | | - const res = await axios.get('http://localhost:8080/run_test'); |
16 | | - span.setStatus({ code: api.SpanStatusCode.OK }); |
17 | | - console.log(res.statusText); |
18 | | - } catch (e) { |
19 | | - if(e instanceof Error) { |
20 | | - span.setStatus({ code: api.SpanStatusCode.ERROR, message: e.message }); |
| 29 | + await api.context.with( |
| 30 | + api.trace.setSpan(api.ROOT_CONTEXT, span), |
| 31 | + async () => { |
| 32 | + try { |
| 33 | + const res = await axios.get('http://localhost:8080/run_test'); |
| 34 | + span.setStatus({ code: api.SpanStatusCode.OK }); |
| 35 | + console.log(res.statusText); |
| 36 | + } catch (e) { |
| 37 | + if (e instanceof Error) { |
| 38 | + span.setStatus({ |
| 39 | + code: api.SpanStatusCode.ERROR, |
| 40 | + message: e.message, |
| 41 | + }); |
| 42 | + } |
21 | 43 | } |
| 44 | + span.end(); |
| 45 | + console.log( |
| 46 | + 'Sleeping 5 seconds before shutdown to ensure all records are flushed.' |
| 47 | + ); |
| 48 | + setTimeout(() => { |
| 49 | + console.log('Completed.'); |
| 50 | + }, 5000); |
22 | 51 | } |
23 | | - span.end(); |
24 | | - console.log('Sleeping 5 seconds before shutdown to ensure all records are flushed.'); |
25 | | - setTimeout(() => { console.log('Completed.'); }, 5000); |
26 | | - }); |
| 52 | + ); |
27 | 53 | } |
28 | 54 |
|
29 | | -makeRequest(); |
| 55 | +makeRequest().catch(err => console.log(err)); |
0 commit comments