Jakarta Mail Instrumentation
Micrometer provides Jakarta Mail instrumentation.
Installing
It is recommended to use the BOM provided by Micrometer (or your framework if any), you can see how to configure it here. The examples below assume you are using a BOM.
Gradle
After the BOM is configured, add the following dependency:
implementation 'io.micrometer:micrometer-jakarta9'
| The version is not needed for this dependency since it is defined by the BOM. |
Maven
After the BOM is configured, add the following dependency:
<dependency>
<groupId>io.micrometer</groupId>
<artifactId>micrometer-jakarta9</artifactId>
</dependency>
| The version is not needed for this dependency since it is defined by the BOM. |
Usage
Here is how a Jakarta Mail Transport can be instrumented for observability:
import io.micrometer.jakarta9.instrument.mail.InstrumentedTransport;
Session session = Session.getInstance(new Properties());
ObservationRegistry registry = ...
Transport original = session.getTransport("smtp");
Transport transport = new InstrumentedTransport(session, original, registry);
transport.connect("smtp.example.com", 587, "username", "password");
MimeMessage message = new MimeMessage(session);
message.setFrom("[email protected]");
message.setRecipients(Message.RecipientType.TO, "[email protected]");
message.setSubject("Hello");
message.setText("Mail from Micrometer instrumentation");
// this operation will create a "mail.send" observation
transport.sendMessage(message, message.getAllRecipients());
Observations
This instrumentation creates the "mail.send" observation when
jakarta.mail.Transport.sendMessage is called.
Name |
Description |
|
(SMTP) server address used for sending mails. |
|
(SMTP) server port used for sending mails. |
|
Network protocol used for sending mails. |
Name |
Description |
|
Sender of the mail. |
|
Primary (TO) recipient(s) of the mail. |
|
Carbon copy (CC) recipient(s) of the mail. |
|
Blind carbon copy (BCC) recipient(s) of the mail. |
|
Newsgroup (Usenet news) recipient(s) of the mail. |
|
Subject line of the mail. |
|
Message ID received from the SMTP server. |