Skip to content

Instantly share code, notes, and snippets.

@rumart
Last active July 29, 2025 13:29
Show Gist options
  • Select an option

  • Save rumart/93ca8e06ded57091570b40a59b665f2f to your computer and use it in GitHub Desktop.

Select an option

Save rumart/93ca8e06ded57091570b40a59b665f2f to your computer and use it in GitHub Desktop.
Otel-logger.js example used in blog post https://rudimartinsen.com/2025/07/27/otel-instrumenting-app/
// otel-logger.js
const { logs } = require('@opentelemetry/api-logs');
// Get the global logger provider (set in instrumentation.js)
const appName = process.env.OTEL_SERVICE_NAME || 'my-app';
const logger = logs.getLogger(appName);
// Optional: wrap it with convenience methods
function logInfo(message, attributes = {}) {
logger.emit({
severityText: 'INFO',
body: message,
attributes,
});
}
function logError(message, attributes = {}) {
logger.emit({
severityText: 'ERROR',
body: message,
attributes,
});
}
// Export the logger and helper methods
module.exports = {
logger,
logInfo,
logError,
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment