-
Notifications
You must be signed in to change notification settings - Fork 72
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
examples(get-started-tracetest-cloud): add simple console exporter
- Loading branch information
1 parent
331c9f1
commit 7e94122
Showing
3 changed files
with
29 additions
and
1 deletion.
There are no files selected for viewing
1 change: 1 addition & 0 deletions
1
examples/get-started-cloud-based-managed-tracetest/local/package-lock.json
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
25 changes: 25 additions & 0 deletions
25
examples/get-started-cloud-based-managed-tracetest/local/tracing.console.js
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,25 @@ | ||
// Sample for exporting traces to the console. | ||
|
||
const { NodeSDK } = require('@opentelemetry/sdk-node'); | ||
const { ConsoleSpanExporter } = require('@opentelemetry/sdk-trace-node'); | ||
const { getNodeAutoInstrumentations } = require('@opentelemetry/auto-instrumentations-node'); | ||
|
||
// Configure Console Trace Exporter | ||
const traceExporter = new ConsoleSpanExporter(); | ||
|
||
// Initialize the OpenTelemetry Node SDK | ||
const sdk = new NodeSDK({ | ||
traceExporter, | ||
instrumentations: [getNodeAutoInstrumentations()], | ||
}); | ||
|
||
// Start the SDK (this enables tracing) | ||
sdk.start(); | ||
|
||
// Graceful shutdown on exit | ||
process.on('SIGTERM', () => { | ||
sdk.shutdown().then(() => { | ||
console.log('OpenTelemetry tracing terminated'); | ||
process.exit(0); | ||
}); | ||
}); |