|
| 1 | +[[overview]] |
| 2 | += Jakarta Mail Instrumentation |
| 3 | + |
| 4 | +Micrometer provides Jakarta Mail instrumentation. |
| 5 | + |
| 6 | +== Installing |
| 7 | + |
| 8 | +It is recommended to use the BOM provided by Micrometer (or your framework if any), you can see how to configure it xref:../installing.adoc[here]. The examples below assume you are using a BOM. |
| 9 | + |
| 10 | +=== Gradle |
| 11 | + |
| 12 | +After the BOM is xref:../installing.adoc[configured], add the following dependency: |
| 13 | + |
| 14 | +[source,groovy] |
| 15 | +---- |
| 16 | +implementation 'io.micrometer:micrometer-jakarta9' |
| 17 | +---- |
| 18 | + |
| 19 | +NOTE: The version is not needed for this dependency since it is defined by the BOM. |
| 20 | + |
| 21 | +=== Maven |
| 22 | + |
| 23 | +After the BOM is xref:../installing.adoc[configured], add the following dependency: |
| 24 | + |
| 25 | +[source,xml] |
| 26 | +---- |
| 27 | +<dependency> |
| 28 | + <groupId>io.micrometer</groupId> |
| 29 | + <artifactId>micrometer-jakarta9</artifactId> |
| 30 | +</dependency> |
| 31 | +---- |
| 32 | + |
| 33 | +NOTE: The version is not needed for this dependency since it is defined by the BOM. |
| 34 | + |
| 35 | +== Usage |
| 36 | + |
| 37 | +Here is how a Jakarta Mail `Transport` can be instrumented for observability: |
| 38 | + |
| 39 | +[source,java] |
| 40 | +---- |
| 41 | +import io.micrometer.jakarta9.instrument.mail.InstrumentedTransport; |
| 42 | +
|
| 43 | +Session session = Session.getInstance(new Properties()); |
| 44 | +ObservationRegistry registry = ... |
| 45 | +
|
| 46 | +Transport original = session.getTransport("smtp"); |
| 47 | +Transport transport = new InstrumentedTransport(session, original, registry); |
| 48 | +
|
| 49 | +transport.connect("smtp.example.com", 587, "username", "password"); |
| 50 | +
|
| 51 | +MimeMessage message = new MimeMessage(session); |
| 52 | +message.setFrom("from@example.com"); |
| 53 | +message.setRecipients(Message.RecipientType.TO, "to@example.com"); |
| 54 | +message.setSubject("Hello"); |
| 55 | +message.setText("Mail from Micrometer instrumentation"); |
| 56 | +
|
| 57 | +// this operation will create a "mail.send" observation |
| 58 | +transport.sendMessage(message, message.getAllRecipients()); |
| 59 | +---- |
| 60 | + |
| 61 | +== Observations |
| 62 | + |
| 63 | +This instrumentation creates the `"mail.send"` observation when |
| 64 | +`jakarta.mail.Transport.sendMessage` is called. |
| 65 | + |
| 66 | +.Low cardinality keys |
| 67 | +[cols="a,a"] |
| 68 | +|=== |
| 69 | +|Name | Description |
| 70 | +|`server.address` |(SMTP) server address used for sending mails. |
| 71 | +|`server.port` |(SMTP) server port used for sending mails. |
| 72 | +|`network.protocol.name` |Network protocol used for sending mails. |
| 73 | +|=== |
| 74 | + |
| 75 | +.High cardinality keys |
| 76 | +[cols="a,a"] |
| 77 | +|=== |
| 78 | +|Name | Description |
| 79 | +|`smtp.message.from` |Sender of the mail. |
| 80 | +|`smtp.message.to` |Primary (TO) recipient(s) of the mail. |
| 81 | +|`smtp.message.cc` |Carbon copy (CC) recipient(s) of the mail. |
| 82 | +|`smtp.message.bcc` |Blind carbon copy (BCC) recipient(s) of the mail. |
| 83 | +|`smtp.message.newsgroups` |Newsgroup (Usenet news) recipient(s) of the mail. |
| 84 | +|`smtp.message.subject` |Subject line of the mail. |
| 85 | +|`smtp.message.id` |Message ID received from the SMTP server. |
| 86 | +|=== |
0 commit comments