Middlewares
withTracing
Wrap sends in distributed tracing spans
withTracing wraps each send in a tracing span using the supplied tracer. The tracer interface is structurally compatible with OpenTelemetry's Tracer.startActiveSpan, so an OTel tracer can be passed directly with no adapter.
import { withTracing } from '@betternotify/core/middlewares';
import { trace } from '@opentelemetry/api';
const welcome = rpc
.email()
.input(schema)
.subject(fn)
.template(adapter)
.use(withTracing({
tracer: trace.getTracer('betternotify'),
}));Options
Prop
Type
Span attributes
Every span gets two attributes:
betternotify.route— the dot-path route ID (e.g."transactional.welcome")betternotify.message_id— the UUID for this send attempt
On success, span status is set to ok. On failure, the exception is recorded and status is set to error.
Custom span names
withTracing({
tracer,
name: ({ route }) => `email.${route}`,
})