-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
The Elastic SDK now adds a global Logger Provider. mockotlpserver now has a 'logs-summary' printer to nicely show received 'ExportLogsServiceRequest' data, and the 'json' printer will normalize the service request data similar to as is being done for Trace and Metrics service requests. 'examples/bunyan-logging-app.js' shows using a Bunyan logger with 'examples/start-elastic-sdk.js' which shows how to start the Elastic distro SDK manually, including how to specify custom instrumentations -- in this case the Bunyan instrumentation. Refs: #41
- Loading branch information
Showing
12 changed files
with
957 additions
and
74 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
// Usage: | ||
// node -r @elastic/opentelemetry-node/start.js bunyan-logging-app.js | ||
|
||
const path = require('path'); | ||
const otel = require('@opentelemetry/api'); | ||
const bunyan = require('bunyan'); | ||
|
||
const log = bunyan.createLogger({name: path.parse(__filename).name}); | ||
|
||
log.info({foo: 'bar'}, 'hi there'); | ||
log.warn(new Error('boom'), 'oops'); | ||
log.debug('hi at debug-level'); | ||
|
||
const tracer = otel.trace.getTracer('example'); | ||
tracer.startActiveSpan('manual-span', (span) => { | ||
log.info('this record will have trace-correlation fields'); | ||
span.end(); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
/** | ||
* Setup and start the Elastic OpenTelemetry Node.js SDK distro. | ||
* | ||
* This is an alternative to the `node -r @elastic/opentelemetry-node/start.js` | ||
* convenience for starting the SDK. Starting the SDK manually via a local | ||
* file can be useful to allow configuring the SDK with code. | ||
* | ||
* Usage: | ||
* node -r ./start-elastic-sdk.js SCRIPT.js | ||
*/ | ||
|
||
const path = require('path'); | ||
|
||
const {ElasticNodeSDK} = require('@elastic/opentelemetry-node'); | ||
|
||
// TODO: remove BunyanInstrumentation manual usage when the distro includes it by default | ||
const { | ||
BunyanInstrumentation, | ||
} = require('@opentelemetry/instrumentation-bunyan'); | ||
|
||
const sdk = new ElasticNodeSDK({ | ||
serviceName: path.parse(process.argv[1]).name, | ||
instrumentations: [ | ||
// One can **override** the instrumentations provided by ElasticNodeSDK | ||
// by specifying `instrumentations`. How to **extended** the set of | ||
// instrumentations provided by ElasticNodeSDK is to be determined (TODO). | ||
new BunyanInstrumentation(), | ||
], | ||
}); | ||
|
||
process.on('SIGTERM', async () => { | ||
try { | ||
await sdk.shutdown(); | ||
} catch (err) { | ||
console.warn('warning: error shutting down OTel SDK', err); | ||
} | ||
process.exit(); | ||
}); | ||
|
||
process.once('beforeExit', async () => { | ||
// Flush recent telemetry data if about the shutdown. | ||
try { | ||
await sdk.shutdown(); | ||
} catch (err) { | ||
console.warn('warning: error shutting down OTel SDK', err); | ||
} | ||
}); | ||
|
||
sdk.start(); |
Oops, something went wrong.