@sophonz/custom-log
v0.0.9
Published
Readme
@sophonz/custom-log
Custom structured logging helper for OpenTelemetry with screen context and session tracking.
Records custom log events as OTel spans and logs, automatically enriching them with screen name, session ID, and URL context.
Part of the Sophonz OpenTelemetry suite.
Install
bun add @sophonz/custom-log
# or
pnpm add @sophonz/custom-log
# or
npm install @sophonz/custom-logUsage
import { recordLog } from '@sophonz/custom-log';
recordLog('User clicked button', {
userId: '12345',
section: 'checkout'
});
// With custom tracer and logger
recordLog('Payment processed', { amount: '99.99' }, {
tracer: myTracer,
logger: myLogger,
screenNameOption: {
screenNameType: 'full',
urlWithSearchParams: true
}
});API
recordLog(message, attributes?, hint?)
Records a structured log entry as both a span and a log record.
Parameters:
message(string | object) - Log message or structured dataattributes(object, optional) - Additional key-value attributeshint(object, optional)tracer- Custom OTel tracer (uses default if not provided)logger- Custom OTel logger for log recordsscreenNameOption- Configuration for screen name generation
Auto-enriched attributes:
session.id- RUM session IDapp.screen.name- Current screen/page nameapp.screen.type- Always 'page'app.span.type- Always 'log'component- Always 'log' (span only)level- Log level (always 'info')message- Log message
The keys come from @sophonz/semantic-conventions; import the constants rather
than typing the strings.
Peer Dependencies
@opentelemetry/api@^1.9.1
License
See LICENSE in this package.
Part of sophonz-js.
