Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add action mailer instrumentation #1280

Merged
merged 24 commits into from
Aug 20, 2021
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
5050c05
adds process.action_mailer instrumentation without spec
ericmustin Apr 22, 2019
af4c122
fix typo on active support notificaiton event name
ericmustin Apr 22, 2019
0e4945b
add specs and contrib doc information
ericmustin Apr 22, 2019
94ca301
fix comments typo
ericmustin Apr 22, 2019
aa3615a
rubocop and typo fix
ericmustin Apr 22, 2019
4e6c209
update actionmailer integration, add delivery event
ericmustin Dec 8, 2020
e06f91e
add tests and seperate payload information for different spans
ericmustin Dec 8, 2020
ad9d215
Merge branch 'master' into issue_250_actionmailer_instrumentation
ericmustin Dec 8, 2020
1457b14
remove old specs
ericmustin Dec 8, 2020
954a4b9
Merge branch 'master' into issue_250_actionmailer_instrumentation
marcotc Dec 8, 2020
26bd78c
update with master
ericmustin Jul 29, 2021
759a627
update to check auto instrumentation
ericmustin Aug 4, 2021
1be73af
update specs for action mailer span types
ericmustin Aug 4, 2021
ef5133e
linting
ericmustin Aug 4, 2021
96402e3
add span type to events, wip tests
ericmustin Aug 4, 2021
93e1177
merge upstream
ericmustin Aug 4, 2021
668958c
use correct span type constants and linting
ericmustin Aug 4, 2021
4f48406
Merge branch 'master' into issue_250_actionmailer_instrumentation
ericmustin Aug 4, 2021
b43fa1a
sorbet updates
ericmustin Aug 5, 2021
6f39604
add note on test helpers
ericmustin Aug 5, 2021
fb70948
Merge branch 'master' into issue_250_actionmailer_instrumentation
ericmustin Aug 18, 2021
e2cac58
action_mailer: add email_data config option
ericmustin Aug 18, 2021
c929fc6
action_mailer: clean up formatting and fix config naming
ericmustin Aug 18, 2021
c21540f
action_mailer: fix constants
ericmustin Aug 18, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/GettingStarted.md
Original file line number Diff line number Diff line change
Expand Up @@ -494,6 +494,7 @@ Where `options` is an optional `Hash` that accepts the following parameters:
| --- | ----------- | ------- |
| `analytics_enabled` | Enable analytics for spans produced by this integration. `true` for on, `nil` to defer to global setting, `false` for off. | `false` |
| `service_name` | Service name used for `action_mailer` instrumentation | `'action_mailer'` |
| `email_data` | Whether or not to append additional email payload metadata to `action_mailer.deliver` spans. Fields include `['subject', 'to', 'from', 'bcc', 'cc', 'date', 'perform_deliveries']`. | `false` |

### Active Model Serializers

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ class Settings < Contrib::Configuration::Settings
end

option :service_name, default: Ext::SERVICE_NAME
option :email_data, default: false
end
end
end
Expand Down
13 changes: 13 additions & 0 deletions lib/ddtrace/contrib/action_mailer/events/deliver.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,19 @@ def process(span, event, _id, payload)
span.span_type = span_type
span.set_tag(Ext::TAG_MAILER, payload[:mailer])
span.set_tag(Ext::TAG_MSG_ID, payload[:message_id])

# Since email date can contain PII we disable by default
# Some of these fields can be either strings or arrays, so we try to normalize
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

# https://github.com/rails/rails/blob/18707ab17fa492eb25ad2e8f9818a320dc20b823/actionmailer/lib/action_mailer/base.rb#L742-L754
if configuration[:email_data] == true
span.set_tag(Ext::TAG_SUBJECT, payload[:subject].to_s) if payload[:subject]
span.set_tag(Ext::TAG_TO, payload[:to].join(',')) if payload[:to]
span.set_tag(Ext::TAG_FROM, payload[:from].join(',')) if payload[:from]
span.set_tag(Ext::TAG_BCC, payload[:bcc].join(',')) if payload[:bcc]
span.set_tag(Ext::TAG_CC, payload[:cc].join(',')) if payload[:cc]
span.set_tag(Ext::TAG_DATE, payload[:date].to_s) if payload[:date]
span.set_tag(Ext::TAG_PERFORM_DELIVERIES, payload[:perform_deliveries]) if payload[:perform_deliveries]
end
end
end
end
Expand Down
8 changes: 8 additions & 0 deletions lib/ddtrace/contrib/action_mailer/ext.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,14 @@ module Ext
TAG_ACTION = 'action_mailer.action'.freeze
TAG_MAILER = 'action_mailer.mailer'.freeze
TAG_MSG_ID = 'action_mailer.message_id'.freeze

TAG_SUBJECT = 'action_mailer.subject'.freeze
TAG_TO = 'action_mailer.to'.freeze
TAG_FROM = 'action_mailer.from'.freeze
TAG_BCC = 'action_mailer.bcc'.freeze
TAG_CC = 'action_mailer.cc'.freeze
TAG_DATE = 'action_mailer.date'.freeze
TAG_PERFORM_DELIVERIES = 'action_mailer.perform_deliveries'.freeze
end
end
end
Expand Down
6 changes: 5 additions & 1 deletion spec/ddtrace/contrib/action_mailer/helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,11 @@
default from: 'test@example.com'

def test_mail(_arg)
mail(to: 'test@example.com', body: 'sk test')
mail(to: 'test@example.com',
body: 'sk test',
subject: 'miniswan',
bcc: 'test_a@example.com,test_b@example.com',
cc: ['test_c@example.com', 'test_d@example.com'])
end
end
)
Expand Down
21 changes: 21 additions & 0 deletions spec/ddtrace/contrib/action_mailer/patcher_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -86,5 +86,26 @@

it_behaves_like 'measured span for integration', true
end

context 'with email_data enabled' do
let(:configuration_options) { { email_data: true } }

it 'is expected to add additional email date to deliver span' do
expect(deliver_span).to_not be nil
expect(deliver_span.service).to eq('action_mailer')
expect(deliver_span.name).to eq('action_mailer.deliver')
expect(deliver_span.resource).to eq(mailer)
expect(deliver_span.get_tag('action_mailer.mailer')).to eq(mailer)
expect(deliver_span.span_type).to eq('worker')
expect(deliver_span.get_tag('action_mailer.message_id')).to_not be nil
expect(deliver_span.status).to_not eq(Datadog::Ext::Errors::STATUS)

expect(deliver_span.get_tag('action_mailer.to')).to eq('test@example.com')
expect(deliver_span.get_tag('action_mailer.from')).to eq('test@example.com')
expect(deliver_span.get_tag('action_mailer.subject')).to eq('miniswan')
expect(deliver_span.get_tag('action_mailer.bcc')).to eq('test_a@example.com,test_b@example.com')
expect(deliver_span.get_tag('action_mailer.cc')).to eq('test_c@example.com,test_d@example.com')
end
end
end
end