Skip to content

Commit f21374e

Browse files
committed
chore!: update to JS SDK 2.x
- instr-bunyan and examples/bunyan
1 parent 353dbb0 commit f21374e

File tree

6 files changed

+259
-34
lines changed

6 files changed

+259
-34
lines changed

examples/bunyan/app.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,19 +14,21 @@
1414
* limitations under the License.
1515
*/
1616

17+
'use strict';
18+
1719
// A small example that shows using OpenTelemetry's instrumentation of
1820
// Bunyan loggers. Usage:
1921
// node --require ./telemetry.js app.js
2022

2123
const otel = require('@opentelemetry/api');
2224
const bunyan = require('bunyan');
2325

24-
const log = bunyan.createLogger({name: 'myapp', level: 'debug'});
26+
const log = bunyan.createLogger({ name: 'myapp', level: 'debug' });
2527

26-
log.debug({foo: 'bar'}, 'hi');
28+
log.debug({ foo: 'bar' }, 'hi');
2729

2830
const tracer = otel.trace.getTracer('example');
29-
tracer.startActiveSpan('manual-span', span => {
31+
tracer.startActiveSpan('manual-span', (span) => {
3032
log.info('this record will have trace_id et al fields for the current span');
3133
span.end();
3234
});

examples/bunyan/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@
1818
"dependencies": {
1919
"@opentelemetry/api": "^1.3.0",
2020
"@opentelemetry/instrumentation-bunyan": "^0.34.0",
21-
"@opentelemetry/resources": "^1.8.0",
22-
"@opentelemetry/sdk-node": "^0.48.0",
21+
"@opentelemetry/resources": "^2.0.0-dev.0",
22+
"@opentelemetry/sdk-node": "^0.200.0-dev.0",
2323
"bunyan": "^1.8.15"
2424
}
2525
}

examples/bunyan/telemetry.js

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,42 +14,44 @@
1414
* limitations under the License.
1515
*/
1616

17+
'use strict';
18+
1719
// Setup telemetry for tracing and Bunyan logging.
1820
//
1921
// This writes OTel spans and log records to the console for simplicity. In a
2022
// real setup you would configure exporters to send to remote observability apps
2123
// for viewing and analysis.
2224

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');
2527
// api.diag.setLogger(new api.DiagConsoleLogger(), api.DiagLogLevel.DEBUG);
2628

2729
const { BunyanInstrumentation } = require('@opentelemetry/instrumentation-bunyan');
2830

2931
const sdk = new NodeSDK({
3032
serviceName: 'bunyan-example',
3133
resourceDetectors: [
32-
envDetectorSync,
34+
envDetector,
3335
// ProcessDetector adds `process.pid` (among other resource attributes),
3436
// which replaces the usual Bunyan `pid` field.
35-
processDetectorSync,
37+
processDetector,
3638
// The HostDetector adds `host.name` and `host.arch` fields. `host.name`
3739
// replaces the usual Bunyan `hostname` field. HostDetector is *not* a
3840
// default detector of the `NodeSDK`.
39-
hostDetectorSync
41+
hostDetector,
4042
],
4143
spanProcessor: new tracing.SimpleSpanProcessor(new tracing.ConsoleSpanExporter()),
4244
logRecordProcessor: new logs.SimpleLogRecordProcessor(new logs.ConsoleLogRecordExporter()),
4345
instrumentations: [
4446
new BunyanInstrumentation(),
45-
]
46-
})
47-
process.on("SIGTERM", () => {
47+
],
48+
});
49+
process.on('SIGTERM', () => {
4850
sdk
4951
.shutdown()
5052
.then(
5153
() => {},
52-
(err) => console.log("warning: error shutting down OTel SDK", err)
54+
(err) => console.log('warning: error shutting down OTel SDK', err),
5355
)
5456
.finally(() => process.exit(0));
5557
});

package-lock.json

Lines changed: 233 additions & 12 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)