|
14 | 14 | * limitations under the License. |
15 | 15 | */ |
16 | 16 |
|
| 17 | +'use strict'; |
| 18 | + |
17 | 19 | // Setup telemetry for tracing and Bunyan logging. |
18 | 20 | // |
19 | 21 | // This writes OTel spans and log records to the console for simplicity. In a |
20 | 22 | // real setup you would configure exporters to send to remote observability apps |
21 | 23 | // for viewing and analysis. |
22 | 24 |
|
23 | | -const { NodeSDK, tracing, logs, api } = require('@opentelemetry/sdk-node'); |
24 | | -const { envDetectorSync, hostDetectorSync, processDetectorSync } = require('@opentelemetry/resources'); |
| 25 | +const { NodeSDK, tracing, logs } = require('@opentelemetry/sdk-node'); |
| 26 | +const { envDetector, hostDetector, processDetector } = require('@opentelemetry/resources'); |
25 | 27 | // api.diag.setLogger(new api.DiagConsoleLogger(), api.DiagLogLevel.DEBUG); |
26 | 28 |
|
27 | 29 | const { BunyanInstrumentation } = require('@opentelemetry/instrumentation-bunyan'); |
28 | 30 |
|
29 | 31 | const sdk = new NodeSDK({ |
30 | 32 | serviceName: 'bunyan-example', |
31 | 33 | resourceDetectors: [ |
32 | | - envDetectorSync, |
| 34 | + envDetector, |
33 | 35 | // ProcessDetector adds `process.pid` (among other resource attributes), |
34 | 36 | // which replaces the usual Bunyan `pid` field. |
35 | | - processDetectorSync, |
| 37 | + processDetector, |
36 | 38 | // The HostDetector adds `host.name` and `host.arch` fields. `host.name` |
37 | 39 | // replaces the usual Bunyan `hostname` field. HostDetector is *not* a |
38 | 40 | // default detector of the `NodeSDK`. |
39 | | - hostDetectorSync |
| 41 | + hostDetector, |
40 | 42 | ], |
41 | 43 | spanProcessor: new tracing.SimpleSpanProcessor(new tracing.ConsoleSpanExporter()), |
42 | 44 | logRecordProcessor: new logs.SimpleLogRecordProcessor(new logs.ConsoleLogRecordExporter()), |
43 | 45 | instrumentations: [ |
44 | 46 | new BunyanInstrumentation(), |
45 | | - ] |
46 | | -}) |
47 | | -process.on("SIGTERM", () => { |
| 47 | + ], |
| 48 | +}); |
| 49 | +process.on('SIGTERM', () => { |
48 | 50 | sdk |
49 | 51 | .shutdown() |
50 | 52 | .then( |
51 | 53 | () => {}, |
52 | | - (err) => console.log("warning: error shutting down OTel SDK", err) |
| 54 | + (err) => console.log('warning: error shutting down OTel SDK', err), |
53 | 55 | ) |
54 | 56 | .finally(() => process.exit(0)); |
55 | 57 | }); |
|
0 commit comments