EmailProvidersOpenTelemetry

OpenTelemetry

Add observability to email sending with OpenTelemetry instrumentation in @visulima/email

OpenTelemetry Provider

The OpenTelemetry provider wraps any other provider with OpenTelemetry instrumentation, adding distributed tracing and metrics to your email sending operations.

Runtime Support: Depends on the wrapped provider

Prerequisites

Install OpenTelemetry packages:

npm install @opentelemetry/api @opentelemetry/sdk-trace-base

Setup

import { createMail } from "@visulima/email";
import { opentelemetryProvider } from "@visulima/email/providers/opentelemetry";
import { resendProvider } from "@visulima/email/providers/resend";

const mail = createMail(
    opentelemetryProvider({
        provider: resendProvider({ apiKey: process.env.RESEND_API_KEY! }),
        serviceName: "my-email-service",
        recordContent: false,
    }),
);

Configuration

The OpenTelemetryConfig interface extends BaseConfig with the following options:

OptionTypeRequiredDefaultDescription
providerProvider | ProviderFactoryYes-The provider to wrap with instrumentation
serviceNamestringNo"email"Service name for OpenTelemetry spans
recordContentbooleanNofalseWhether to record email content in spans
tracerTracerNoGlobalCustom OpenTelemetry tracer instance
debugbooleanNofalseEnable debug logging
loggerConsoleNo-Custom logger instance

Basic Usage

import { MailMessage } from "@visulima/email";

const message = new MailMessage()
    .to("user@example.com")
    .from("sender@example.com")
    .subject("Hello with Tracing")
    .html("<h1>Hello World</h1>");

const result = await mail.send(message);
// Spans will be created automatically for the send operation

Custom Tracer

You can provide a custom tracer instance:

import { trace } from "@opentelemetry/api";

const tracer = trace.getTracer("my-app", "1.0.0");

const mail = createMail(
    opentelemetryProvider({
        provider: resendProvider({ apiKey: "re_xxx" }),
        tracer,
        serviceName: "email-service",
    }),
);

Recording Content

By default, email content is not recorded in spans for privacy reasons. Enable it for debugging:

const mail = createMail(
    opentelemetryProvider({
        provider: resendProvider({ apiKey: "re_xxx" }),
        recordContent: true, // Records email content in spans
    }),
);

Supported Features

The OpenTelemetry provider supports whatever features the underlying provider supports. It transparently proxies all operations while adding instrumentation.

Support

Contribute to our work and keep us going

Community is the heart of open source. The success of our packages wouldn't be possible without the incredible contributions of users, testers, and developers who collaborate with us every day.Want to get involved? Here are some tips on how you can make a meaningful impact on our open source projects.

Ready to help us out?

Be sure to check out the package's contribution guidelines first. They'll walk you through the process on how to properly submit an issue or pull request to our repositories.

Submit a pull request

Found something to improve? Fork the repo, make your changes, and open a PR. We review every contribution and provide feedback to help you get merged.

Good first issues

Simple issues suited for people new to open source development, and often a good place to start working on a package.
View good first issues