Skip to content

Commit 305b421

Browse files
committed
feat: subscribe to process.action_mailer notifications
1 parent 2debf6f commit 305b421

File tree

3 files changed

+24
-17
lines changed

3 files changed

+24
-17
lines changed

instrumentation/action_mailer/README.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ To use the instrumentation, call `use` with the name of the instrumentation:
2121

2222
```ruby
2323
OpenTelemetry::SDK.configure do |c|
24-
# Use only the ActionMailer instrumentation
24+
# Use only the ActionMailer instrumentation
2525
c.use 'OpenTelemetry::Instrumentation::ActionMailer'
2626
# Use the ActionMailer instrumentation along with the rest of the Rails-related instrumentation
2727
c.use 'OpenTelemetry::Instrumentation::Rails'
@@ -44,8 +44,8 @@ See the table below for details of what [Rails Framework Hook Events](https://gu
4444

4545
| Event Name | Creates Span? | Notes |
4646
| - | - | - |
47-
| `deliver.action_mailer` | :white_check_mark: | Creates an span with kind `internal` and email content and status|
48-
| `process.action_mailer` | :x: | Lack of useful info so ignored |
47+
| `deliver.action_mailer` | :white_check_mark: | Creates a span with kind `internal` and email content and status |
48+
| `process.action_mailer` | :white_check_mark: | Creates a span with kind `internal` that will include email rendering spans |
4949

5050
### Options
5151

@@ -67,9 +67,9 @@ end
6767

6868
## Semantic Conventions
6969

70-
Internal spans are named using the name of the `ActiveSupport` event that was provided (e.g. `action_mailer deliver`).
70+
Internal spans are named using the name of the `ActiveSupport` event that was provided (e.g. `deliver.action_mailer`).
7171

72-
The following attributes from the notification payload for the `deliver.action_mailer` event are attached to `action_mailer deliver` spans:
72+
The following attributes from the notification payload for the `deliver.action_mailer` event are attached:
7373

7474
| Attribute Name | Type | Notes |
7575
| - | - | - |

instrumentation/action_mailer/lib/opentelemetry/instrumentation/action_mailer/instrumentation.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,9 @@ class Instrumentation < OpenTelemetry::Instrumentation::Base
2727
end
2828

2929
option :disallowed_notification_payload_keys, default: [], validate: :array
30+
option :disallowed_process_payload_keys, default: [], validate: :array
3031
option :notification_payload_transform, default: nil, validate: :callable
32+
option :process_payload_transform, default: nil, validate: :callable
3133
option :email_address, default: :omit, validate: %I[omit include]
3234

3335
private

instrumentation/action_mailer/lib/opentelemetry/instrumentation/action_mailer/railtie.rb

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,24 +7,29 @@
77
module OpenTelemetry
88
module Instrumentation
99
module ActionMailer
10-
SUBSCRIPTIONS = %w[
11-
deliver.action_mailer
12-
].freeze
10+
DELIVER_SUBSCRIPTION = 'deliver.action_mailer'
11+
PROCESS_SUBSCRIPTION = 'process.action_mailer'
1312

1413
# This Railtie sets up subscriptions to relevant ActionMailer notifications
1514
class Railtie < ::Rails::Railtie
1615
config.after_initialize do
1716
::OpenTelemetry::Instrumentation::ActiveSupport::Instrumentation.instance.install({})
1817

19-
SUBSCRIPTIONS.each do |subscription_name|
20-
config = ActionMailer::Instrumentation.instance.config
21-
::OpenTelemetry::Instrumentation::ActiveSupport.subscribe(
22-
ActionMailer::Instrumentation.instance.tracer,
23-
subscription_name,
24-
config[:notification_payload_transform],
25-
config[:disallowed_notification_payload_keys]
26-
)
27-
end
18+
config = ActionMailer::Instrumentation.instance.config
19+
20+
::OpenTelemetry::Instrumentation::ActiveSupport.subscribe(
21+
ActionMailer::Instrumentation.instance.tracer,
22+
DELIVER_SUBSCRIPTION,
23+
config[:notification_payload_transform],
24+
config[:disallowed_notification_payload_keys]
25+
)
26+
27+
::OpenTelemetry::Instrumentation::ActiveSupport.subscribe(
28+
ActionMailer::Instrumentation.instance.tracer,
29+
PROCESS_SUBSCRIPTION,
30+
config[:process_payload_transform],
31+
config[:disallowed_process_payload_keys]
32+
)
2833
end
2934
end
3035
end

0 commit comments

Comments
 (0)