Email SDK
PluginsBuilt-in plugins

Observability plugin

Emit send, retry, and error events through isolated log, metric, and trace callbacks.

observabilityPlugin calls each configured observer with Promise.allSettled, so observer failures do not reject the send.

src/email.ts
import { observabilityPlugin } from "@opencoredev/email-sdk/plugins/observability";

const email = createEmailClient({
  adapters: [adapter],
  plugins: [
    observabilityPlugin({
      log(event) {
        console.info(event.type, {
          adapter: event.adapter,
          attempt: event.attempt,
        });
      },
    }),
  ],
});

Event types

TypeEmitted whenAdditional fields
email.sentAn adapter succeeds.responseId?
email.retryA retry is scheduled.nextAttempt, delayMs, error
email.errorAn adapter reaches terminal failure.error

Every event includes the adapter, attempt, redacted message facts, and optional send metadata.

Default redaction

The built-in redactor keeps:

  • subject
  • recipient counts
  • whether HTML or text exists
  • attachment count
  • tag names
  • metadata keys

It excludes bodies, addresses, attachment contents, and metadata values. If subjects are sensitive, provide redactMessage and return a stricter RedactedEmailMessage.

src/email.ts
observabilityPlugin({
  redactMessage(message) {
    return {
      subject: "[redacted]",
      toCount: Array.isArray(message.to) ? message.to.length : 1,
      ccCount: 0,
      bccCount: 0,
      hasHtml: Boolean(message.html),
      hasText: Boolean(message.text),
      attachmentCount: message.attachments?.length ?? 0,
      tagNames: [],
      metadataKeys: [],
    };
  },
});

Hooks and middleware

Understand lifecycle ordering and failure isolation.

Telemetry and privacy

Separate SDK analytics from your application observability.

On this page