Skip to content

Commit

Permalink
examples(get-started-tracetest-cloud): add simple console exporter
Browse files Browse the repository at this point in the history
  • Loading branch information
adnanrahic committed Sep 20, 2024
1 parent 331c9f1 commit 7e94122
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 1 deletion.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
"description": "",
"main": "index.js",
"scripts": {
"start": "node app.js"
"start": "node app.js",
"tracing.console": "node -r ./tracing.console.js app.js"
},
"keywords": [],
"author": "",
Expand All @@ -13,6 +14,7 @@
"@opentelemetry/auto-instrumentations-node": "^0.50.0",
"@opentelemetry/exporter-trace-otlp-grpc": "^0.53.0",
"@opentelemetry/sdk-node": "^0.53.0",
"@opentelemetry/sdk-trace-node": "^1.26.0",
"express": "^4.21.0"
}
}
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);
});
});

0 comments on commit 7e94122

Please sign in to comment.