From 5050c05d142ebff22b96c13f1187160f8acbf517 Mon Sep 17 00:00:00 2001 From: ericmustin Date: Mon, 22 Apr 2019 12:40:45 +0200 Subject: [PATCH 01/17] adds process.action_mailer instrumentation without spec --- docs/GettingStarted.md | 21 ++++++ lib/ddtrace.rb | 1 + .../action_mailer/configuration/settings.rb | 31 +++++++++ lib/ddtrace/contrib/action_mailer/event.rb | 64 +++++++++++++++++++ lib/ddtrace/contrib/action_mailer/events.rb | 28 ++++++++ .../contrib/action_mailer/events/process.rb | 27 ++++++++ lib/ddtrace/contrib/action_mailer/ext.rb | 16 +++++ .../contrib/action_mailer/integration.rb | 40 ++++++++++++ lib/ddtrace/contrib/action_mailer/patcher.rb | 40 ++++++++++++ 9 files changed, 268 insertions(+) create mode 100644 lib/ddtrace/contrib/action_mailer/configuration/settings.rb create mode 100644 lib/ddtrace/contrib/action_mailer/event.rb create mode 100644 lib/ddtrace/contrib/action_mailer/events.rb create mode 100644 lib/ddtrace/contrib/action_mailer/events/process.rb create mode 100644 lib/ddtrace/contrib/action_mailer/ext.rb create mode 100644 lib/ddtrace/contrib/action_mailer/integration.rb create mode 100644 lib/ddtrace/contrib/action_mailer/patcher.rb diff --git a/docs/GettingStarted.md b/docs/GettingStarted.md index 27e18fbeb74..8f386f7dbcd 100644 --- a/docs/GettingStarted.md +++ b/docs/GettingStarted.md @@ -339,6 +339,27 @@ For a list of available integrations, and their configuration options, please re | Sinatra | `sinatra` | `>= 1.4.5` | *[Link](#sinatra)* | *[Link](https://github.com/sinatra/sinatra)* | | Sucker Punch | `sucker_punch` | `>= 2.0` | *[Link](#sucker-punch)* | *[Link](https://github.com/brandonhilkert/sucker_punch)* | +### Action Mailer + +The Action Mailer integration provides tracing for Rails 5 ActionMailer actions. + +You can enable it through `Datadog.configure`: + +```ruby +require 'ddtrace' + Datadog.configure do |c| + c.use :action_mailer, options +end +``` + +Where `options` is an optional `Hash` that accepts the following parameters: + +| Key | Description | Default | +| --- | ----------- | ------- | +| `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'` | +| `tracer` | `Datadog::Tracer` used to perform instrumentation. Usually you don't need to set this. | `Datadog.tracer` | + ### Active Model Serializers The Active Model Serializers integration traces the `serialize` event for version 0.9+ and the `render` event for version 0.10+. diff --git a/lib/ddtrace.rb b/lib/ddtrace.rb index 6cb0cebd9a6..3db3c75e1e0 100644 --- a/lib/ddtrace.rb +++ b/lib/ddtrace.rb @@ -21,6 +21,7 @@ module Datadog extend Contrib::Extensions end +require 'ddtrace/contrib/action_mailer/integration' require 'ddtrace/contrib/active_model_serializers/integration' require 'ddtrace/contrib/active_record/integration' require 'ddtrace/contrib/aws/integration' diff --git a/lib/ddtrace/contrib/action_mailer/configuration/settings.rb b/lib/ddtrace/contrib/action_mailer/configuration/settings.rb new file mode 100644 index 00000000000..89037b4bfaa --- /dev/null +++ b/lib/ddtrace/contrib/action_mailer/configuration/settings.rb @@ -0,0 +1,31 @@ +require 'ddtrace/contrib/configuration/settings' +require 'ddtrace/contrib/action_mailer/ext' + + module Datadog + module Contrib + module ActionMailer + module Configuration + # Custom settings for the ActionMailer integration + class Settings < Contrib::Configuration::Settings + option :analytics_enabled, + default: -> { env_to_bool(Ext::ENV_ANALYTICS_ENABLED, false) }, + lazy: true + + option :analytics_sample_rate, + default: -> { env_to_float(Ext::ENV_ANALYTICS_SAMPLE_RATE, 1.0) }, + lazy: true + + option :service_name, default: Ext::SERVICE_NAME + option :tracer, default: Datadog.tracer do |value| + (value || Datadog.tracer).tap do |v| + # Make sure to update tracers of all subscriptions + Events.subscriptions.each do |subscription| + subscription.tracer = v + end + end + end + end + end + end + end +end \ No newline at end of file diff --git a/lib/ddtrace/contrib/action_mailer/event.rb b/lib/ddtrace/contrib/action_mailer/event.rb new file mode 100644 index 00000000000..0d323fe8069 --- /dev/null +++ b/lib/ddtrace/contrib/action_mailer/event.rb @@ -0,0 +1,64 @@ +require 'ddtrace/contrib/analytics' +require 'ddtrace/contrib/active_support/notifications/event' +require 'ddtrace/contrib/action_mailer/ext' + + module Datadog + module Contrib + module ActionMailer + # Defines basic behaviors for an ActionMailer event. + module Event + def self.included(base) + base.send(:include, ActiveSupport::Notifications::Event) + base.send(:extend, ClassMethods) + end + + # Class methods for ActionMailer events. + # Note, they share the same process method and before_trace method. + module ClassMethods + def subscription(*args) + super.tap do |subscription| + subscription.before_trace { ensure_clean_context! } + end + end + + def span_options + { service: configuration[:service_name] } + end + + def tracer + configuration[:tracer] + end + + def configuration + Datadog.configuration[:action_mailer] + end + + def process(span, event, _id, payload) + span.service = configuration[:service_name] + span.resource = payload[:mailer] + + # Set analytics sample rate + if Contrib::Analytics.enabled?(configuration[:analytics_enabled]) + Contrib::Analytics.set_sample_rate(span, configuration[:analytics_sample_rate]) + end + span.set_tag(Ext::TAG_ACTION, payload[:action]) + span.set_tag(Ext::TAG_MAILER, payload[:mailer]) + span.set_error(payload[:exception_object]) if payload[:exception_object] + end + + private + + # Context objects are thread-bound. + # If ActionMailer re-uses threads, context from a previous trace + # could leak into the new trace. This "cleans" current context, + # preventing such a leak. This approach mirrors that found in + # contrib/racecar/event.rb + def ensure_clean_context! + return unless configuration[:tracer].call_context.current_span + configuration[:tracer].provider.context = Context.new + end + end + end + end + end +end \ No newline at end of file diff --git a/lib/ddtrace/contrib/action_mailer/events.rb b/lib/ddtrace/contrib/action_mailer/events.rb new file mode 100644 index 00000000000..fb2c457996b --- /dev/null +++ b/lib/ddtrace/contrib/action_mailer/events.rb @@ -0,0 +1,28 @@ +require 'ddtrace/contrib/action_mailer/events/process' + + module Datadog + module Contrib + module ActionMailer + # Defines collection of instrumented ActionMailer events + module Events + ALL = [ + Events::Process + ].freeze + + module_function + + def all + self::ALL + end + + def subscriptions + all.collect(&:subscriptions).collect(&:to_a).flatten + end + + def subscribe! + all.each(&:subscribe!) + end + end + end + end +end \ No newline at end of file diff --git a/lib/ddtrace/contrib/action_mailer/events/process.rb b/lib/ddtrace/contrib/action_mailer/events/process.rb new file mode 100644 index 00000000000..c6a97820bef --- /dev/null +++ b/lib/ddtrace/contrib/action_mailer/events/process.rb @@ -0,0 +1,27 @@ +require 'ddtrace/contrib/action_mailer/ext' +require 'ddtrace/contrib/action_mailer/event' + + module Datadog + module Contrib + module ActionMailer + module Events + # Defines instrumentation for process.action_mailer event + module Process + include ActionMailer::Event + + EVENT_NAME = 'process.action_cable'.freeze + + module_function + + def event_name + self::EVENT_NAME + end + + def span_name + Ext::SPAN_PROCESS + end + end + end + end + end +end \ No newline at end of file diff --git a/lib/ddtrace/contrib/action_mailer/ext.rb b/lib/ddtrace/contrib/action_mailer/ext.rb new file mode 100644 index 00000000000..eb1cb6ada72 --- /dev/null +++ b/lib/ddtrace/contrib/action_mailer/ext.rb @@ -0,0 +1,16 @@ +module Datadog + module Contrib + module ActionMailer + # ActionCable integration constants + module Ext + APP = 'action_mailer'.freeze + ENV_ANALYTICS_ENABLED = 'DD_ACTION_MAILER_ANALYTICS_ENABLED'.freeze + ENV_ANALYTICS_SAMPLE_RATE = 'DD_ACTION_MAILER_ANALYTICS_SAMPLE_RATE'.freeze + SERVICE_NAME = 'action_mailer'.freeze + SPAN_PROCESS = 'process.action_mailer'.freeze + TAG_ACTION = 'action_mailer.action'.freeze + TAG_MAILER = 'action_mailer.mailer'.freeze + end + end + end +end \ No newline at end of file diff --git a/lib/ddtrace/contrib/action_mailer/integration.rb b/lib/ddtrace/contrib/action_mailer/integration.rb new file mode 100644 index 00000000000..d2476f0740d --- /dev/null +++ b/lib/ddtrace/contrib/action_mailer/integration.rb @@ -0,0 +1,40 @@ +require 'ddtrace/contrib/integration' +require 'ddtrace/contrib/action_mailer/configuration/settings' +require 'ddtrace/contrib/action_mailer/patcher' + + module Datadog + module Contrib + module ActionMailer + # Description of ActionMailer integration + class Integration + include Contrib::Integration + + register_as :action_mailer, auto_patch: false + + def self.version + Gem.loaded_specs['rails'] && Gem.loaded_specs['rails'].version + end + + def self.present? + super && defined?(::ActionMailer) + end + + def self.compatible? + # Rails 5 Requires Ruby 2.2.2 or higher + return false if ENV['DISABLE_DATADOG_RAILS'] + super && defined?(::ActiveSupport::Notifications) && + defined?(::Rails::VERSION) && ::Rails::VERSION::MAJOR.to_i >= 5 && + RUBY_VERSION >= '2.2.2' + end + + def default_configuration + Configuration::Settings.new + end + + def patcher + Patcher + end + end + end + end +end \ No newline at end of file diff --git a/lib/ddtrace/contrib/action_mailer/patcher.rb b/lib/ddtrace/contrib/action_mailer/patcher.rb new file mode 100644 index 00000000000..7d6039c4b1e --- /dev/null +++ b/lib/ddtrace/contrib/action_mailer/patcher.rb @@ -0,0 +1,40 @@ +require 'ddtrace/contrib/patcher' +require 'ddtrace/ext/app_types' +require 'ddtrace/contrib/action_mailer/ext' +require 'ddtrace/contrib/action_mailer/events' + + module Datadog + module Contrib + module ActionMailer + # Patcher enables patching of 'action_mailer' module. + module Patcher + include Contrib::Patcher + + module_function + + def patched? + done?(:action_mailer) + end + + def patch + do_once(:action_mailer) do + begin + # Subscribe to ActionMailer events + Events.subscribe! + + # Set service info + configuration = Datadog.configuration[:action_mailer] + configuration[:tracer].set_service_info( + configuration[:service_name], + Ext::APP, + Datadog::Ext::AppTypes::WORKER + ) + rescue StandardError => e + Datadog::Tracer.log.error("Unable to apply ActionMailer integration: #{e}") + end + end + end + end + end + end +end \ No newline at end of file From af4c1229f73a460c77b72b284393619f1507ce4d Mon Sep 17 00:00:00 2001 From: ericmustin Date: Mon, 22 Apr 2019 13:02:14 +0200 Subject: [PATCH 02/17] fix typo on active support notificaiton event name --- lib/ddtrace/contrib/action_mailer/events.rb | 2 +- lib/ddtrace/contrib/action_mailer/events/process.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/ddtrace/contrib/action_mailer/events.rb b/lib/ddtrace/contrib/action_mailer/events.rb index fb2c457996b..5bb26a1f7c1 100644 --- a/lib/ddtrace/contrib/action_mailer/events.rb +++ b/lib/ddtrace/contrib/action_mailer/events.rb @@ -1,6 +1,6 @@ require 'ddtrace/contrib/action_mailer/events/process' - module Datadog +module Datadog module Contrib module ActionMailer # Defines collection of instrumented ActionMailer events diff --git a/lib/ddtrace/contrib/action_mailer/events/process.rb b/lib/ddtrace/contrib/action_mailer/events/process.rb index c6a97820bef..8ecac368de9 100644 --- a/lib/ddtrace/contrib/action_mailer/events/process.rb +++ b/lib/ddtrace/contrib/action_mailer/events/process.rb @@ -9,7 +9,7 @@ module Events module Process include ActionMailer::Event - EVENT_NAME = 'process.action_cable'.freeze + EVENT_NAME = 'process.action_mailer'.freeze module_function From 0e4945b9514d695b951cc009656362a6fdbf7bfd Mon Sep 17 00:00:00 2001 From: ericmustin Date: Mon, 22 Apr 2019 13:34:19 +0200 Subject: [PATCH 03/17] add specs and contrib doc information --- Rakefile | 9 +- docs/GettingStarted.md | 2 + .../contrib/action_mailer/patcher_spec.rb | 90 +++++++++++++++++++ 3 files changed, 100 insertions(+), 1 deletion(-) create mode 100644 spec/ddtrace/contrib/action_mailer/patcher_spec.rb diff --git a/Rakefile b/Rakefile index 213e8a8a48f..f4454ea36f0 100644 --- a/Rakefile +++ b/Rakefile @@ -12,7 +12,7 @@ desc 'Run RSpec' # rubocop:disable Metrics/BlockLength namespace :spec do task all: [:main, - :rails, :railsredis, :railssidekiq, :railsactivejob, + :rails, :railsredis, :railssidekiq, :railsactivejob, :railsactionmailer :elasticsearch, :http, :redis, :sidekiq, :sinatra] RSpec::Core::RakeTask.new(:main) do |t, args| @@ -47,6 +47,10 @@ namespace :spec do t.rspec_opts = args.to_a.join(' ') end + RSpec::Core::RakeTask.new(:railsactionmailer) do |t| + t.pattern = 'spec/ddtrace/contrib/action_mailer/*_spec.rb' + end + RSpec::Core::RakeTask.new(:railsdisableenv) do |t, args| t.pattern = 'spec/ddtrace/contrib/rails/**/*disable_env*_spec.rb' t.rspec_opts = args.to_a.join(' ') @@ -56,6 +60,7 @@ namespace :spec do # rubocop:disable Metrics/LineLength t.pattern = 'spec/**/contrib/{analytics,configurable,integration,patchable,patcher,registerable,registry,configuration/*}_spec.rb' t.rspec_opts = args.to_a.join(' ') + t.exclude_pattern = 'spec/ddtrace/contrib/action_{cable,mailer}/*_spec.rb' end [ @@ -463,7 +468,9 @@ task :ci do sh 'bundle exec appraisal rails4-mysql2 rake spec:rails' sh 'bundle exec appraisal rails4-postgres rake spec:rails' sh 'bundle exec appraisal rails5-mysql2 rake spec:rails' + sh 'bundle exec appraisal rails5-mysql2 rake spec:railsactionmailer' sh 'bundle exec appraisal rails5-postgres rake spec:rails' + sh 'bundle exec appraisal rails5-postgres rake spec:railsactionmailer' end elsif Gem::Version.new('2.4.0') <= Gem::Version.new(RUBY_VERSION) # Main library diff --git a/docs/GettingStarted.md b/docs/GettingStarted.md index 8f386f7dbcd..a5956b2a8d2 100644 --- a/docs/GettingStarted.md +++ b/docs/GettingStarted.md @@ -24,6 +24,7 @@ For descriptions of terminology used in APM, take a look at the [official docume - [Quickstart for OpenTracing](#quickstart-for-opentracing) - [Manual instrumentation](#manual-instrumentation) - [Integration instrumentation](#integration-instrumentation) + - [Action Maile](#action-mailer) - [Active Model Serializers](#active-model-serializers) - [Active Record](#active-record) - [AWS](#aws) @@ -311,6 +312,7 @@ For a list of available integrations, and their configuration options, please re | Name | Key | Versions Supported | How to configure | Gem source | | ------------------------ | -------------------------- | ------------------------ | ----------------------------------- | ------------------------------------------------------------------------------ | +| Action Mailer | `action_mailer` | `>= 5.0, < 6.0` | *[Link](#action-mailer)* | *[Link](https://github.com/rails/rails/tree/master/actionmailer)* | | Active Model Serializers | `active_model_serializers` | `>= 0.9` | *[Link](#active-model-serializers)* | *[Link](https://github.com/rails-api/active_model_serializers)* | | Active Record | `active_record` | `>= 3.2, < 6.0` | *[Link](#active-record)* | *[Link](https://github.com/rails/rails/tree/master/activerecord)* | | AWS | `aws` | `>= 2.0` | *[Link](#aws)* | *[Link](https://github.com/aws/aws-sdk-ruby)* | diff --git a/spec/ddtrace/contrib/action_mailer/patcher_spec.rb b/spec/ddtrace/contrib/action_mailer/patcher_spec.rb new file mode 100644 index 00000000000..0d3bdcadbf8 --- /dev/null +++ b/spec/ddtrace/contrib/action_mailer/patcher_spec.rb @@ -0,0 +1,90 @@ +require 'spec_helper' +require 'ddtrace/contrib/analytics_examples' +require 'rails' +require 'active_support' +require 'ddtrace' + +RSpec.describe 'ActionMailer patcher' do + let(:tracer) { get_test_tracer } + let(:configuration_options) { { tracer: tracer } } + + def all_spans + tracer.writer.spans(:keep) + end + + before(:each) do + if Datadog::Contrib::ActionMailer::Integration.compatible? + Datadog.configure do |c| + c.use :action_mailer, configuration_options + end + else + skip + end + end + + around do |example| + # Reset before and after each example; don't allow global state to linger. + Datadog.registry[:action_mailer].reset_configuration! + example.run + Datadog.registry[:action_mailer].reset_configuration! + end + + describe 'for single process.action_mailer process' do + let(:mailer) { 'UserMailer' } + let(:action) { 'example_welcome_email' } + let(:args) do + [] + end + + let(:span) do + all_spans.select { |s| s.name == Datadog::Contrib::ActionMailer::Ext::SPAN_PROCESS }.first + end + + context 'that doesn\'t raise an error' do + it 'is expected to send a span' do + ActiveSupport::Notifications.instrument('process.action_mailer', payload) + + span.tap do |span| + expect(span).to_not be nil + expect(span.service).to eq('action_mailer') + expect(span.name).to eq('process.action_mailer') + expect(span.resource).to eq(mailer) + expect(span.get_tag('action_mailer.action')).to eq(action) + expect(span.get_tag('action_mailer.mailer')).to eq(mailer) + expect(span.status).to_not eq(Datadog::Ext::Errors::STATUS) + end + end + end + + context 'that raises an error' do + let(:error_class) { Class.new(StandardError) } + + it 'is expected to send a span' do + # Emulate failure + begin + ActiveSupport::Notifications.instrument('process.action_mailer', payload) do + raise error_class + end + rescue error_class + nil + end + + span.tap do |span| + expect(span).to_not be nil + expect(span.service).to eq('action_mailer') + expect(span.name).to eq('process.action_mailer') + expect(span.resource).to eq(mailer) + expect(span.get_tag('action_mailer.process')).to eq(action) + expect(span.get_tag('action_mailer.mailer')).to eq(mailer) + expect(span.status).to eq(Datadog::Ext::Errors::STATUS) + end + end + end + + it_behaves_like 'analytics for integration' do + before { ActiveSupport::Notifications.instrument('process.action_mailer', payload) } + let(:analytics_enabled_var) { Datadog::Contrib::ActionMailer::Ext::ENV_ANALYTICS_ENABLED } + let(:analytics_sample_rate_var) { Datadog::Contrib::ActionMailer::Ext::ENV_ANALYTICS_SAMPLE_RATE } + end + end +end \ No newline at end of file From 94ca30131731b8db2d07e9f821ed5051ad6e6e67 Mon Sep 17 00:00:00 2001 From: ericmustin Date: Mon, 22 Apr 2019 13:37:10 +0200 Subject: [PATCH 04/17] fix comments typo --- lib/ddtrace/contrib/action_mailer/ext.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/ddtrace/contrib/action_mailer/ext.rb b/lib/ddtrace/contrib/action_mailer/ext.rb index eb1cb6ada72..ad7e4807ec7 100644 --- a/lib/ddtrace/contrib/action_mailer/ext.rb +++ b/lib/ddtrace/contrib/action_mailer/ext.rb @@ -1,7 +1,7 @@ module Datadog module Contrib module ActionMailer - # ActionCable integration constants + # ActionMailer integration constants module Ext APP = 'action_mailer'.freeze ENV_ANALYTICS_ENABLED = 'DD_ACTION_MAILER_ANALYTICS_ENABLED'.freeze From aa3615a9c2dba17dd284515b7ad5b7cf09f6520a Mon Sep 17 00:00:00 2001 From: ericmustin Date: Mon, 22 Apr 2019 14:36:35 +0200 Subject: [PATCH 05/17] rubocop and typo fix --- Rakefile | 4 ++-- .../action_mailer/configuration/settings.rb | 8 ++++---- lib/ddtrace/contrib/action_mailer/event.rb | 16 ++++++++-------- lib/ddtrace/contrib/action_mailer/events.rb | 10 +++++----- .../contrib/action_mailer/events/process.rb | 12 ++++++------ lib/ddtrace/contrib/action_mailer/ext.rb | 2 +- lib/ddtrace/contrib/action_mailer/integration.rb | 16 ++++++++-------- lib/ddtrace/contrib/action_mailer/patcher.rb | 12 ++++++------ .../contrib/action_mailer/patcher_spec.rb | 2 +- 9 files changed, 41 insertions(+), 41 deletions(-) diff --git a/Rakefile b/Rakefile index f4454ea36f0..93c1f34e306 100644 --- a/Rakefile +++ b/Rakefile @@ -12,7 +12,7 @@ desc 'Run RSpec' # rubocop:disable Metrics/BlockLength namespace :spec do task all: [:main, - :rails, :railsredis, :railssidekiq, :railsactivejob, :railsactionmailer + :rails, :railsredis, :railssidekiq, :railsactivejob, :railsactionmailer, :elasticsearch, :http, :redis, :sidekiq, :sinatra] RSpec::Core::RakeTask.new(:main) do |t, args| @@ -49,7 +49,7 @@ namespace :spec do RSpec::Core::RakeTask.new(:railsactionmailer) do |t| t.pattern = 'spec/ddtrace/contrib/action_mailer/*_spec.rb' - end + end RSpec::Core::RakeTask.new(:railsdisableenv) do |t, args| t.pattern = 'spec/ddtrace/contrib/rails/**/*disable_env*_spec.rb' diff --git a/lib/ddtrace/contrib/action_mailer/configuration/settings.rb b/lib/ddtrace/contrib/action_mailer/configuration/settings.rb index 89037b4bfaa..841333aec06 100644 --- a/lib/ddtrace/contrib/action_mailer/configuration/settings.rb +++ b/lib/ddtrace/contrib/action_mailer/configuration/settings.rb @@ -1,7 +1,7 @@ require 'ddtrace/contrib/configuration/settings' require 'ddtrace/contrib/action_mailer/ext' - module Datadog +module Datadog module Contrib module ActionMailer module Configuration @@ -11,11 +11,11 @@ class Settings < Contrib::Configuration::Settings default: -> { env_to_bool(Ext::ENV_ANALYTICS_ENABLED, false) }, lazy: true - option :analytics_sample_rate, + option :analytics_sample_rate, default: -> { env_to_float(Ext::ENV_ANALYTICS_SAMPLE_RATE, 1.0) }, lazy: true - option :service_name, default: Ext::SERVICE_NAME + option :service_name, default: Ext::SERVICE_NAME option :tracer, default: Datadog.tracer do |value| (value || Datadog.tracer).tap do |v| # Make sure to update tracers of all subscriptions @@ -28,4 +28,4 @@ class Settings < Contrib::Configuration::Settings end end end -end \ No newline at end of file +end diff --git a/lib/ddtrace/contrib/action_mailer/event.rb b/lib/ddtrace/contrib/action_mailer/event.rb index 0d323fe8069..5bb59065c32 100644 --- a/lib/ddtrace/contrib/action_mailer/event.rb +++ b/lib/ddtrace/contrib/action_mailer/event.rb @@ -2,7 +2,7 @@ require 'ddtrace/contrib/active_support/notifications/event' require 'ddtrace/contrib/action_mailer/ext' - module Datadog +module Datadog module Contrib module ActionMailer # Defines basic behaviors for an ActionMailer event. @@ -21,23 +21,23 @@ def subscription(*args) end end - def span_options + def span_options { service: configuration[:service_name] } end - def tracer + def tracer configuration[:tracer] end - def configuration + def configuration Datadog.configuration[:action_mailer] end - def process(span, event, _id, payload) + def process(span, event, _id, payload) span.service = configuration[:service_name] span.resource = payload[:mailer] - # Set analytics sample rate + # Set analytics sample rate if Contrib::Analytics.enabled?(configuration[:analytics_enabled]) Contrib::Analytics.set_sample_rate(span, configuration[:analytics_sample_rate]) end @@ -46,7 +46,7 @@ def process(span, event, _id, payload) span.set_error(payload[:exception_object]) if payload[:exception_object] end - private + private # Context objects are thread-bound. # If ActionMailer re-uses threads, context from a previous trace @@ -61,4 +61,4 @@ def ensure_clean_context! end end end -end \ No newline at end of file +end diff --git a/lib/ddtrace/contrib/action_mailer/events.rb b/lib/ddtrace/contrib/action_mailer/events.rb index 5bb26a1f7c1..26f920ca04b 100644 --- a/lib/ddtrace/contrib/action_mailer/events.rb +++ b/lib/ddtrace/contrib/action_mailer/events.rb @@ -9,20 +9,20 @@ module Events Events::Process ].freeze - module_function + module_function - def all + def all self::ALL end - def subscriptions + def subscriptions all.collect(&:subscriptions).collect(&:to_a).flatten end - def subscribe! + def subscribe! all.each(&:subscribe!) end end end end -end \ No newline at end of file +end diff --git a/lib/ddtrace/contrib/action_mailer/events/process.rb b/lib/ddtrace/contrib/action_mailer/events/process.rb index 8ecac368de9..f8df8cdd706 100644 --- a/lib/ddtrace/contrib/action_mailer/events/process.rb +++ b/lib/ddtrace/contrib/action_mailer/events/process.rb @@ -1,7 +1,7 @@ require 'ddtrace/contrib/action_mailer/ext' require 'ddtrace/contrib/action_mailer/event' - module Datadog +module Datadog module Contrib module ActionMailer module Events @@ -9,19 +9,19 @@ module Events module Process include ActionMailer::Event - EVENT_NAME = 'process.action_mailer'.freeze + EVENT_NAME = 'process.action_mailer'.freeze - module_function + module_function - def event_name + def event_name self::EVENT_NAME end - def span_name + def span_name Ext::SPAN_PROCESS end end end end end -end \ No newline at end of file +end diff --git a/lib/ddtrace/contrib/action_mailer/ext.rb b/lib/ddtrace/contrib/action_mailer/ext.rb index ad7e4807ec7..5f921ae988e 100644 --- a/lib/ddtrace/contrib/action_mailer/ext.rb +++ b/lib/ddtrace/contrib/action_mailer/ext.rb @@ -13,4 +13,4 @@ module Ext end end end -end \ No newline at end of file +end diff --git a/lib/ddtrace/contrib/action_mailer/integration.rb b/lib/ddtrace/contrib/action_mailer/integration.rb index d2476f0740d..2c8ff5e64dd 100644 --- a/lib/ddtrace/contrib/action_mailer/integration.rb +++ b/lib/ddtrace/contrib/action_mailer/integration.rb @@ -2,24 +2,24 @@ require 'ddtrace/contrib/action_mailer/configuration/settings' require 'ddtrace/contrib/action_mailer/patcher' - module Datadog +module Datadog module Contrib module ActionMailer # Description of ActionMailer integration class Integration include Contrib::Integration - register_as :action_mailer, auto_patch: false + register_as :action_mailer, auto_patch: false - def self.version + def self.version Gem.loaded_specs['rails'] && Gem.loaded_specs['rails'].version end - def self.present? + def self.present? super && defined?(::ActionMailer) end - def self.compatible? + def self.compatible? # Rails 5 Requires Ruby 2.2.2 or higher return false if ENV['DISABLE_DATADOG_RAILS'] super && defined?(::ActiveSupport::Notifications) && @@ -27,14 +27,14 @@ def self.compatible? RUBY_VERSION >= '2.2.2' end - def default_configuration + def default_configuration Configuration::Settings.new end - def patcher + def patcher Patcher end end end end -end \ No newline at end of file +end diff --git a/lib/ddtrace/contrib/action_mailer/patcher.rb b/lib/ddtrace/contrib/action_mailer/patcher.rb index 7d6039c4b1e..d4a05b701e8 100644 --- a/lib/ddtrace/contrib/action_mailer/patcher.rb +++ b/lib/ddtrace/contrib/action_mailer/patcher.rb @@ -3,26 +3,26 @@ require 'ddtrace/contrib/action_mailer/ext' require 'ddtrace/contrib/action_mailer/events' - module Datadog +module Datadog module Contrib module ActionMailer # Patcher enables patching of 'action_mailer' module. module Patcher include Contrib::Patcher - module_function + module_function - def patched? + def patched? done?(:action_mailer) end - def patch + def patch do_once(:action_mailer) do begin # Subscribe to ActionMailer events Events.subscribe! - # Set service info + # Set service info configuration = Datadog.configuration[:action_mailer] configuration[:tracer].set_service_info( configuration[:service_name], @@ -37,4 +37,4 @@ def patch end end end -end \ No newline at end of file +end diff --git a/spec/ddtrace/contrib/action_mailer/patcher_spec.rb b/spec/ddtrace/contrib/action_mailer/patcher_spec.rb index 0d3bdcadbf8..8598bc358c0 100644 --- a/spec/ddtrace/contrib/action_mailer/patcher_spec.rb +++ b/spec/ddtrace/contrib/action_mailer/patcher_spec.rb @@ -87,4 +87,4 @@ def all_spans let(:analytics_sample_rate_var) { Datadog::Contrib::ActionMailer::Ext::ENV_ANALYTICS_SAMPLE_RATE } end end -end \ No newline at end of file +end From e06f91ee9560fba2856fc65d27e198ed0df81b33 Mon Sep 17 00:00:00 2001 From: ericmustin Date: Tue, 8 Dec 2020 16:51:42 +0100 Subject: [PATCH 06/17] add tests and seperate payload information for different spans --- .../action_mailer/configuration/settings.rb | 4 +- lib/ddtrace/contrib/action_mailer/event.rb | 3 - .../contrib/action_mailer/events/deliver.rb | 7 +++ .../contrib/action_mailer/events/process.rb | 7 +++ lib/ddtrace/contrib/action_mailer/ext.rb | 7 ++- .../contrib/action_mailer/integration.rb | 2 +- lib/ddtrace/contrib/action_mailer/patcher.rb | 2 +- spec/ddtrace/contrib/action_mailer/helpers.rb | 11 ++-- .../contrib/action_mailer/patcher_spec.rb | 57 +++++++++++-------- 9 files changed, 62 insertions(+), 38 deletions(-) diff --git a/lib/ddtrace/contrib/action_mailer/configuration/settings.rb b/lib/ddtrace/contrib/action_mailer/configuration/settings.rb index 0d8cf9766a1..2eb29c67143 100644 --- a/lib/ddtrace/contrib/action_mailer/configuration/settings.rb +++ b/lib/ddtrace/contrib/action_mailer/configuration/settings.rb @@ -13,12 +13,12 @@ class Settings < Contrib::Configuration::Settings end option :analytics_enabled do |o| - o.default { env_to_bool(Ext::ENV_ANALYTICS_ENABLED, false) } + o.default { env_to_bool([Ext::ENV_ANALYTICS_ENABLED, Ext::ENV_ANALYTICS_ENABLED_OLD], false) } o.lazy end option :analytics_sample_rate do |o| - o.default { env_to_float(Ext::ENV_ANALYTICS_SAMPLE_RATE, 1.0) } + o.default { env_to_float([Ext::ENV_ANALYTICS_SAMPLE_RATE, Ext::ENV_ANALYTICS_SAMPLE_RATE_OLD], 1.0) } o.lazy end diff --git a/lib/ddtrace/contrib/action_mailer/event.rb b/lib/ddtrace/contrib/action_mailer/event.rb index c8407124fdc..404437e2827 100644 --- a/lib/ddtrace/contrib/action_mailer/event.rb +++ b/lib/ddtrace/contrib/action_mailer/event.rb @@ -38,9 +38,6 @@ def process(span, event, _id, payload) # Measure service stats Contrib::Analytics.set_measured(span) - span.set_tag(Ext::TAG_ACTION, payload[:action]) - span.set_tag(Ext::TAG_MAILER, payload[:mailer]) - report_if_exception(span, payload) rescue StandardError => e Datadog.logger.debug(e.message) diff --git a/lib/ddtrace/contrib/action_mailer/events/deliver.rb b/lib/ddtrace/contrib/action_mailer/events/deliver.rb index 07899dc1d27..3dac46ac057 100644 --- a/lib/ddtrace/contrib/action_mailer/events/deliver.rb +++ b/lib/ddtrace/contrib/action_mailer/events/deliver.rb @@ -25,6 +25,13 @@ def span_type # ActionMailer creates emails like a controller Datadog::Ext::AppTypes::Worker end + + def process(span, event, _id, payload) + super + + span.set_tag(Ext::TAG_MAILER, payload[:mailer]) + span.set_tag(Ext::TAG_MSG_ID, payload[:message_id]) + end end end end diff --git a/lib/ddtrace/contrib/action_mailer/events/process.rb b/lib/ddtrace/contrib/action_mailer/events/process.rb index 70ebc6c9429..caf6ac7c44e 100644 --- a/lib/ddtrace/contrib/action_mailer/events/process.rb +++ b/lib/ddtrace/contrib/action_mailer/events/process.rb @@ -25,6 +25,13 @@ def span_type # ActionMailer creates emails like a controller Datadog::Ext::AppTypes::Web end + + def process(span, event, _id, payload) + super + + span.set_tag(Ext::TAG_ACTION, payload[:action]) + span.set_tag(Ext::TAG_MAILER, payload[:mailer]) + end end end end diff --git a/lib/ddtrace/contrib/action_mailer/ext.rb b/lib/ddtrace/contrib/action_mailer/ext.rb index 7a551345bd7..f8c5c2ce5ca 100644 --- a/lib/ddtrace/contrib/action_mailer/ext.rb +++ b/lib/ddtrace/contrib/action_mailer/ext.rb @@ -7,11 +7,16 @@ module Ext ENV_ENABLED = 'DD_TRACE_ACTION_MAILER_ENABLED'.freeze ENV_ANALYTICS_ENABLED = 'DD_TRACE_ACTION_MAILER_ANALYTICS_ENABLED'.freeze ENV_ANALYTICS_SAMPLE_RATE = 'DD_TRACE_ACTION_MAILER_ANALYTICS_SAMPLE_RATE'.freeze + + ENV_ANALYTICS_ENABLED_OLD = 'DD_ACTION_MAILER_ANALYTICS_ENABLED'.freeze + + ENV_ANALYTICS_SAMPLE_RATE_OLD = 'DD_ACTION_MAILER_ANALYTICS_SAMPLE_RATE'.freeze SERVICE_NAME = 'action_mailer'.freeze SPAN_PROCESS = 'action_mailer.process'.freeze - SPAN_DELIVER = 'action_mailer.email'.freeze + SPAN_DELIVER = 'action_mailer.deliver'.freeze TAG_ACTION = 'action_mailer.action'.freeze TAG_MAILER = 'action_mailer.mailer'.freeze + TAG_MSG_ID = 'action_mailer.message_id'.freeze end end end diff --git a/lib/ddtrace/contrib/action_mailer/integration.rb b/lib/ddtrace/contrib/action_mailer/integration.rb index 074a8822e66..c061a162ee6 100644 --- a/lib/ddtrace/contrib/action_mailer/integration.rb +++ b/lib/ddtrace/contrib/action_mailer/integration.rb @@ -22,7 +22,7 @@ def self.loaded? end def self.compatible? - super && version >= MINIMUM_VERSION && defined?(::ActiveSupport::Notifications) + super && version >= MINIMUM_VERSION && !defined?(::ActiveSupport::Notifications).nil? end def default_configuration diff --git a/lib/ddtrace/contrib/action_mailer/patcher.rb b/lib/ddtrace/contrib/action_mailer/patcher.rb index ceb856987d0..e7bec9e0bf2 100644 --- a/lib/ddtrace/contrib/action_mailer/patcher.rb +++ b/lib/ddtrace/contrib/action_mailer/patcher.rb @@ -23,4 +23,4 @@ def patch end end end -end \ No newline at end of file +end diff --git a/spec/ddtrace/contrib/action_mailer/helpers.rb b/spec/ddtrace/contrib/action_mailer/helpers.rb index 58a3df7df02..c6c9a3e7dd0 100644 --- a/spec/ddtrace/contrib/action_mailer/helpers.rb +++ b/spec/ddtrace/contrib/action_mailer/helpers.rb @@ -1,23 +1,22 @@ require 'rails' RSpec.shared_context 'ActionMailer helpers' do - before(:each) do if ActionMailer::Base.respond_to?(:delivery_method) - ActionMailer::Base.delivery_method = :test + ActionMailer::Base.delivery_method = :test else ActionMailer::DeliveryJob.delivery_method = :test end stub_const( - "UserMailer", + 'UserMailer', Class.new(ActionMailer::Base) do - default from: "test@example.com" + 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') end end ) end -end \ No newline at end of file +end diff --git a/spec/ddtrace/contrib/action_mailer/patcher_spec.rb b/spec/ddtrace/contrib/action_mailer/patcher_spec.rb index d4411108704..33e475b7034 100644 --- a/spec/ddtrace/contrib/action_mailer/patcher_spec.rb +++ b/spec/ddtrace/contrib/action_mailer/patcher_spec.rb @@ -1,8 +1,9 @@ -require 'spec_helper' +require 'ddtrace/contrib/support/spec_helper' require 'ddtrace/contrib/analytics_examples' require 'rails' require 'active_support' require 'spec/ddtrace/contrib/action_mailer/helpers' +require 'ddtrace/contrib/action_mailer/integration' require 'ddtrace' begin @@ -16,10 +17,6 @@ let(:configuration_options) { {} } - def all_spans - tracer.writer.spans(:keep) - end - before(:each) do if Datadog::Contrib::ActionMailer::Integration.compatible? Datadog.configure do |c| @@ -45,27 +42,45 @@ def all_spans end let(:span) do - puts 'spans are' - puts spans.length spans.select { |s| s.name == Datadog::Contrib::ActionMailer::Ext::SPAN_PROCESS }.first end - before do + let(:deliver_span) do + spans.select { |s| s.name == Datadog::Contrib::ActionMailer::Ext::SPAN_DELIVER }.first + end + + before(:each) do UserMailer.test_mail(1).deliver_now end context 'that doesn\'t raise an error' do - it 'is expected to send a span' do - span.tap do |span| - expect(span).to_not be nil - expect(span.service).to eq('action_mailer') - expect(span.name).to eq('action_mailer.process') - expect(span.resource).to eq(mailer) - expect(span.get_tag('action_mailer.action')).to eq(action) - expect(span.get_tag('action_mailer.mailer')).to eq(mailer) - expect(span.status).to_not eq(Datadog::Ext::Errors::STATUS) - end + it 'is expected to send a process span' do + expect(span).to_not be nil + expect(span.service).to eq('action_mailer') + expect(span.name).to eq('action_mailer.process') + expect(span.resource).to eq(mailer) + expect(span.get_tag('action_mailer.action')).to eq(action) + expect(span.get_tag('action_mailer.mailer')).to eq(mailer) + expect(span.status).to_not eq(Datadog::Ext::Errors::STATUS) + end + + it 'is expected to send a 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.get_tag('action_mailer.message_id')).to_not be nil + expect(deliver_span.status).to_not eq(Datadog::Ext::Errors::STATUS) end + + it_behaves_like 'analytics for integration' do + before { UserMailer.test_mail(1).deliver_now } + let(:analytics_enabled_var) { Datadog::Contrib::ActionMailer::Ext::ENV_ANALYTICS_ENABLED } + let(:analytics_sample_rate_var) { Datadog::Contrib::ActionMailer::Ext::ENV_ANALYTICS_SAMPLE_RATE } + end + + it_behaves_like 'measured span for integration', true end # context 'that raises an error' do @@ -92,11 +107,5 @@ def all_spans # end # end # end - - it_behaves_like 'analytics for integration' do - - let(:analytics_enabled_var) { Datadog::Contrib::ActionMailer::Ext::ENV_ANALYTICS_ENABLED } - let(:analytics_sample_rate_var) { Datadog::Contrib::ActionMailer::Ext::ENV_ANALYTICS_SAMPLE_RATE } - end end end From 1457b1465eda53e03acfe4b4ee6ef6948804976d Mon Sep 17 00:00:00 2001 From: ericmustin Date: Tue, 8 Dec 2020 16:56:19 +0100 Subject: [PATCH 07/17] remove old specs --- .../contrib/action_mailer/patcher_spec.rb | 25 ------------------- 1 file changed, 25 deletions(-) diff --git a/spec/ddtrace/contrib/action_mailer/patcher_spec.rb b/spec/ddtrace/contrib/action_mailer/patcher_spec.rb index 33e475b7034..f17cbc216d8 100644 --- a/spec/ddtrace/contrib/action_mailer/patcher_spec.rb +++ b/spec/ddtrace/contrib/action_mailer/patcher_spec.rb @@ -82,30 +82,5 @@ it_behaves_like 'measured span for integration', true end - - # context 'that raises an error' do - # let(:error_class) { Class.new(StandardError) } - - # it 'is expected to send a span' do - # # Emulate failure - # begin - # ActiveSupport::Notifications.instrument('process.action_mailer', payload) do - # raise error_class - # end - # rescue error_class - # nil - # end - - # span.tap do |span| - # expect(span).to_not be nil - # expect(span.service).to eq('action_mailer') - # expect(span.name).to eq('process.action_mailer') - # expect(span.resource).to eq(mailer) - # expect(span.get_tag('action_mailer.process')).to eq(action) - # expect(span.get_tag('action_mailer.mailer')).to eq(mailer) - # expect(span.status).to eq(Datadog::Ext::Errors::STATUS) - # end - # end - # end end end From 759a6272b9d0b396d38a00989c42061b83bef862 Mon Sep 17 00:00:00 2001 From: ericmustin Date: Wed, 4 Aug 2021 02:36:07 -0400 Subject: [PATCH 08/17] update to check auto instrumentation --- lib/ddtrace/contrib/action_mailer/integration.rb | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/lib/ddtrace/contrib/action_mailer/integration.rb b/lib/ddtrace/contrib/action_mailer/integration.rb index c061a162ee6..1627c941159 100644 --- a/lib/ddtrace/contrib/action_mailer/integration.rb +++ b/lib/ddtrace/contrib/action_mailer/integration.rb @@ -25,12 +25,18 @@ def self.compatible? super && version >= MINIMUM_VERSION && !defined?(::ActiveSupport::Notifications).nil? end + # enabled by rails integration so should only auto instrument + # if detected that it is being used without rails + def auto_instrument? + !Datadog::Contrib::Rails::Utils.railtie_supported? + end + def default_configuration Configuration::Settings.new end def patcher - Patcher + ActionMailer::Patcher end end end From 1be73af74521ff29a68ce3335ecff87cca623b19 Mon Sep 17 00:00:00 2001 From: ericmustin Date: Wed, 4 Aug 2021 03:22:26 -0400 Subject: [PATCH 09/17] update specs for action mailer span types --- lib/ddtrace/contrib/action_mailer/events/deliver.rb | 2 +- lib/ddtrace/contrib/action_mailer/events/process.rb | 4 ++-- spec/ddtrace/contrib/action_mailer/patcher_spec.rb | 2 ++ 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/lib/ddtrace/contrib/action_mailer/events/deliver.rb b/lib/ddtrace/contrib/action_mailer/events/deliver.rb index 3dac46ac057..fcb7a2ef8e3 100644 --- a/lib/ddtrace/contrib/action_mailer/events/deliver.rb +++ b/lib/ddtrace/contrib/action_mailer/events/deliver.rb @@ -22,7 +22,7 @@ def span_name end def span_type - # ActionMailer creates emails like a controller + # deliver.action_mailer sends emails Datadog::Ext::AppTypes::Worker end diff --git a/lib/ddtrace/contrib/action_mailer/events/process.rb b/lib/ddtrace/contrib/action_mailer/events/process.rb index caf6ac7c44e..0d78b884b28 100644 --- a/lib/ddtrace/contrib/action_mailer/events/process.rb +++ b/lib/ddtrace/contrib/action_mailer/events/process.rb @@ -22,8 +22,8 @@ def span_name end def span_type - # ActionMailer creates emails like a controller - Datadog::Ext::AppTypes::Web + # process.action_mailer processes email and renders partial templates + Datadog::Ext::HTTP::TEMPLATE end def process(span, event, _id, payload) diff --git a/spec/ddtrace/contrib/action_mailer/patcher_spec.rb b/spec/ddtrace/contrib/action_mailer/patcher_spec.rb index f17cbc216d8..204f065b453 100644 --- a/spec/ddtrace/contrib/action_mailer/patcher_spec.rb +++ b/spec/ddtrace/contrib/action_mailer/patcher_spec.rb @@ -61,6 +61,7 @@ expect(span.resource).to eq(mailer) expect(span.get_tag('action_mailer.action')).to eq(action) expect(span.get_tag('action_mailer.mailer')).to eq(mailer) + expect(span.span_type).to eq('template') expect(span.status).to_not eq(Datadog::Ext::Errors::STATUS) end @@ -70,6 +71,7 @@ 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) end From ef5133e5329ef25f347a59ae9d532c382c93e8e2 Mon Sep 17 00:00:00 2001 From: ericmustin Date: Wed, 4 Aug 2021 03:26:13 -0400 Subject: [PATCH 10/17] linting --- spec/ddtrace/contrib/action_mailer/helpers.rb | 2 +- spec/ddtrace/contrib/action_mailer/patcher_spec.rb | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/spec/ddtrace/contrib/action_mailer/helpers.rb b/spec/ddtrace/contrib/action_mailer/helpers.rb index c6c9a3e7dd0..e84da1a785f 100644 --- a/spec/ddtrace/contrib/action_mailer/helpers.rb +++ b/spec/ddtrace/contrib/action_mailer/helpers.rb @@ -1,7 +1,7 @@ require 'rails' RSpec.shared_context 'ActionMailer helpers' do - before(:each) do + before do if ActionMailer::Base.respond_to?(:delivery_method) ActionMailer::Base.delivery_method = :test else diff --git a/spec/ddtrace/contrib/action_mailer/patcher_spec.rb b/spec/ddtrace/contrib/action_mailer/patcher_spec.rb index 204f065b453..3c19625799b 100644 --- a/spec/ddtrace/contrib/action_mailer/patcher_spec.rb +++ b/spec/ddtrace/contrib/action_mailer/patcher_spec.rb @@ -17,7 +17,7 @@ let(:configuration_options) { {} } - before(:each) do + before do if Datadog::Contrib::ActionMailer::Integration.compatible? Datadog.configure do |c| c.use :action_mailer, configuration_options @@ -49,7 +49,7 @@ spans.select { |s| s.name == Datadog::Contrib::ActionMailer::Ext::SPAN_DELIVER }.first end - before(:each) do + before do UserMailer.test_mail(1).deliver_now end From 96402e33b97dc747e98f1bfa0293349bb4f919b9 Mon Sep 17 00:00:00 2001 From: ericmustin Date: Wed, 4 Aug 2021 03:50:10 -0400 Subject: [PATCH 11/17] add span type to events, wip tests --- gemfiles/ruby_2.6.7_contrib_old.gemfile | 2 +- gemfiles/ruby_2.6.7_contrib_old.gemfile.lock | 2 +- gemfiles/ruby_2.6.7_core_old.gemfile | 2 +- gemfiles/ruby_2.6.7_core_old.gemfile.lock | 2 +- gemfiles/ruby_2.6.7_cucumber3.gemfile | 2 +- gemfiles/ruby_2.6.7_cucumber3.gemfile.lock | 2 +- gemfiles/ruby_2.6.7_cucumber4.gemfile | 2 +- gemfiles/ruby_2.6.7_cucumber4.gemfile.lock | 2 +- gemfiles/ruby_2.6.7_cucumber5.gemfile | 2 +- gemfiles/ruby_2.6.7_cucumber5.gemfile.lock | 2 +- gemfiles/ruby_2.6.7_rails5_mysql2.gemfile | 2 +- gemfiles/ruby_2.6.7_rails5_mysql2.gemfile.lock | 2 +- gemfiles/ruby_2.6.7_rails5_postgres.gemfile | 2 +- gemfiles/ruby_2.6.7_rails5_postgres.gemfile.lock | 2 +- gemfiles/ruby_2.6.7_rails5_postgres_redis.gemfile | 2 +- gemfiles/ruby_2.6.7_rails5_postgres_redis.gemfile.lock | 2 +- gemfiles/ruby_2.6.7_rails5_postgres_redis_activesupport.gemfile | 2 +- .../ruby_2.6.7_rails5_postgres_redis_activesupport.gemfile.lock | 2 +- gemfiles/ruby_2.6.7_rails5_postgres_sidekiq.gemfile | 2 +- gemfiles/ruby_2.6.7_rails5_postgres_sidekiq.gemfile.lock | 2 +- gemfiles/ruby_2.6.7_rails5_semantic_logger.gemfile | 2 +- gemfiles/ruby_2.6.7_rails5_semantic_logger.gemfile.lock | 2 +- gemfiles/ruby_2.6.7_rails61_mysql2.gemfile | 2 +- gemfiles/ruby_2.6.7_rails61_mysql2.gemfile.lock | 2 +- gemfiles/ruby_2.6.7_rails61_postgres.gemfile | 2 +- gemfiles/ruby_2.6.7_rails61_postgres.gemfile.lock | 2 +- gemfiles/ruby_2.6.7_rails61_postgres_redis.gemfile | 2 +- gemfiles/ruby_2.6.7_rails61_postgres_redis.gemfile.lock | 2 +- gemfiles/ruby_2.6.7_rails61_postgres_sidekiq.gemfile | 2 +- gemfiles/ruby_2.6.7_rails61_postgres_sidekiq.gemfile.lock | 2 +- gemfiles/ruby_2.6.7_rails61_semantic_logger.gemfile | 2 +- gemfiles/ruby_2.6.7_rails61_semantic_logger.gemfile.lock | 2 +- gemfiles/ruby_2.6.7_rails6_mysql2.gemfile | 2 +- gemfiles/ruby_2.6.7_rails6_mysql2.gemfile.lock | 2 +- gemfiles/ruby_2.6.7_rails6_postgres.gemfile | 2 +- gemfiles/ruby_2.6.7_rails6_postgres.gemfile.lock | 2 +- gemfiles/ruby_2.6.7_rails6_postgres_redis.gemfile | 2 +- gemfiles/ruby_2.6.7_rails6_postgres_redis.gemfile.lock | 2 +- gemfiles/ruby_2.6.7_rails6_postgres_redis_activesupport.gemfile | 2 +- .../ruby_2.6.7_rails6_postgres_redis_activesupport.gemfile.lock | 2 +- gemfiles/ruby_2.6.7_rails6_postgres_sidekiq.gemfile | 2 +- gemfiles/ruby_2.6.7_rails6_postgres_sidekiq.gemfile.lock | 2 +- gemfiles/ruby_2.6.7_rails6_semantic_logger.gemfile | 2 +- gemfiles/ruby_2.6.7_rails6_semantic_logger.gemfile.lock | 2 +- gemfiles/ruby_2.6.7_resque2_redis3.gemfile | 2 +- gemfiles/ruby_2.6.7_resque2_redis3.gemfile.lock | 2 +- gemfiles/ruby_2.6.7_resque2_redis4.gemfile | 2 +- gemfiles/ruby_2.6.7_resque2_redis4.gemfile.lock | 2 +- lib/ddtrace/contrib/action_mailer/events/deliver.rb | 1 + lib/ddtrace/contrib/action_mailer/events/process.rb | 1 + 50 files changed, 50 insertions(+), 48 deletions(-) diff --git a/gemfiles/ruby_2.6.7_contrib_old.gemfile b/gemfiles/ruby_2.6.7_contrib_old.gemfile index 0c36b77435a..1fa7351b41f 100644 --- a/gemfiles/ruby_2.6.7_contrib_old.gemfile +++ b/gemfiles/ruby_2.6.7_contrib_old.gemfile @@ -18,7 +18,7 @@ gem "pimpmychangelog", ">= 0.1.2" gem "pry" gem "pry-byebug" gem "pry-stack_explorer" -gem "rake", ">= 10.5", "< 13.0.4" +gem "rake", ">= 10.5" gem "rake-compiler", "~> 1.1", ">= 1.1.1" gem "redcarpet", "~> 3.4" gem "rspec", "~> 3.10" diff --git a/gemfiles/ruby_2.6.7_contrib_old.gemfile.lock b/gemfiles/ruby_2.6.7_contrib_old.gemfile.lock index ac34a33edc3..b8119f9dc26 100644 --- a/gemfiles/ruby_2.6.7_contrib_old.gemfile.lock +++ b/gemfiles/ruby_2.6.7_contrib_old.gemfile.lock @@ -152,7 +152,7 @@ DEPENDENCIES pry pry-byebug pry-stack_explorer - rake (>= 10.5, < 13.0.4) + rake (>= 10.5) rake-compiler (~> 1.1, >= 1.1.1) redcarpet (~> 3.4) rspec (~> 3.10) diff --git a/gemfiles/ruby_2.6.7_core_old.gemfile b/gemfiles/ruby_2.6.7_core_old.gemfile index 6d8b10dd49e..3e255d7bb61 100644 --- a/gemfiles/ruby_2.6.7_core_old.gemfile +++ b/gemfiles/ruby_2.6.7_core_old.gemfile @@ -18,7 +18,7 @@ gem "pimpmychangelog", ">= 0.1.2" gem "pry" gem "pry-byebug" gem "pry-stack_explorer" -gem "rake", ">= 10.5", "< 13.0.4" +gem "rake", ">= 10.5" gem "rake-compiler", "~> 1.1", ">= 1.1.1" gem "redcarpet", "~> 3.4" gem "rspec", "~> 3.10" diff --git a/gemfiles/ruby_2.6.7_core_old.gemfile.lock b/gemfiles/ruby_2.6.7_core_old.gemfile.lock index a6a5918060f..62e4c7f43f8 100644 --- a/gemfiles/ruby_2.6.7_core_old.gemfile.lock +++ b/gemfiles/ruby_2.6.7_core_old.gemfile.lock @@ -148,7 +148,7 @@ DEPENDENCIES pry pry-byebug pry-stack_explorer - rake (>= 10.5, < 13.0.4) + rake (>= 10.5) rake-compiler (~> 1.1, >= 1.1.1) redcarpet (~> 3.4) rspec (~> 3.10) diff --git a/gemfiles/ruby_2.6.7_cucumber3.gemfile b/gemfiles/ruby_2.6.7_cucumber3.gemfile index 3f99e28c16a..b9e9bfb6499 100644 --- a/gemfiles/ruby_2.6.7_cucumber3.gemfile +++ b/gemfiles/ruby_2.6.7_cucumber3.gemfile @@ -18,7 +18,7 @@ gem "pimpmychangelog", ">= 0.1.2" gem "pry" gem "pry-byebug" gem "pry-stack_explorer" -gem "rake", ">= 10.5", "< 13.0.4" +gem "rake", ">= 10.5" gem "rake-compiler", "~> 1.1", ">= 1.1.1" gem "redcarpet", "~> 3.4" gem "rspec", "~> 3.10" diff --git a/gemfiles/ruby_2.6.7_cucumber3.gemfile.lock b/gemfiles/ruby_2.6.7_cucumber3.gemfile.lock index bf018b04317..d2158aa6cfd 100644 --- a/gemfiles/ruby_2.6.7_cucumber3.gemfile.lock +++ b/gemfiles/ruby_2.6.7_cucumber3.gemfile.lock @@ -169,7 +169,7 @@ DEPENDENCIES pry pry-byebug pry-stack_explorer - rake (>= 10.5, < 13.0.4) + rake (>= 10.5) rake-compiler (~> 1.1, >= 1.1.1) redcarpet (~> 3.4) rspec (~> 3.10) diff --git a/gemfiles/ruby_2.6.7_cucumber4.gemfile b/gemfiles/ruby_2.6.7_cucumber4.gemfile index c5f75c06372..e90f14a1a95 100644 --- a/gemfiles/ruby_2.6.7_cucumber4.gemfile +++ b/gemfiles/ruby_2.6.7_cucumber4.gemfile @@ -18,7 +18,7 @@ gem "pimpmychangelog", ">= 0.1.2" gem "pry" gem "pry-byebug" gem "pry-stack_explorer" -gem "rake", ">= 10.5", "< 13.0.4" +gem "rake", ">= 10.5" gem "rake-compiler", "~> 1.1", ">= 1.1.1" gem "redcarpet", "~> 3.4" gem "rspec", "~> 3.10" diff --git a/gemfiles/ruby_2.6.7_cucumber4.gemfile.lock b/gemfiles/ruby_2.6.7_cucumber4.gemfile.lock index 857f90bb408..e4195542e6c 100644 --- a/gemfiles/ruby_2.6.7_cucumber4.gemfile.lock +++ b/gemfiles/ruby_2.6.7_cucumber4.gemfile.lock @@ -201,7 +201,7 @@ DEPENDENCIES pry pry-byebug pry-stack_explorer - rake (>= 10.5, < 13.0.4) + rake (>= 10.5) rake-compiler (~> 1.1, >= 1.1.1) redcarpet (~> 3.4) rspec (~> 3.10) diff --git a/gemfiles/ruby_2.6.7_cucumber5.gemfile b/gemfiles/ruby_2.6.7_cucumber5.gemfile index bbae5e018b7..a6ce63a817a 100644 --- a/gemfiles/ruby_2.6.7_cucumber5.gemfile +++ b/gemfiles/ruby_2.6.7_cucumber5.gemfile @@ -18,7 +18,7 @@ gem "pimpmychangelog", ">= 0.1.2" gem "pry" gem "pry-byebug" gem "pry-stack_explorer" -gem "rake", ">= 10.5", "< 13.0.4" +gem "rake", ">= 10.5" gem "rake-compiler", "~> 1.1", ">= 1.1.1" gem "redcarpet", "~> 3.4" gem "rspec", "~> 3.10" diff --git a/gemfiles/ruby_2.6.7_cucumber5.gemfile.lock b/gemfiles/ruby_2.6.7_cucumber5.gemfile.lock index 4fedd00b078..b7673d6150b 100644 --- a/gemfiles/ruby_2.6.7_cucumber5.gemfile.lock +++ b/gemfiles/ruby_2.6.7_cucumber5.gemfile.lock @@ -201,7 +201,7 @@ DEPENDENCIES pry pry-byebug pry-stack_explorer - rake (>= 10.5, < 13.0.4) + rake (>= 10.5) rake-compiler (~> 1.1, >= 1.1.1) redcarpet (~> 3.4) rspec (~> 3.10) diff --git a/gemfiles/ruby_2.6.7_rails5_mysql2.gemfile b/gemfiles/ruby_2.6.7_rails5_mysql2.gemfile index d3efbed91d4..72ce5841685 100644 --- a/gemfiles/ruby_2.6.7_rails5_mysql2.gemfile +++ b/gemfiles/ruby_2.6.7_rails5_mysql2.gemfile @@ -18,7 +18,7 @@ gem "pimpmychangelog", ">= 0.1.2" gem "pry" gem "pry-byebug" gem "pry-stack_explorer" -gem "rake", ">= 10.5", "< 13.0.4" +gem "rake", ">= 10.5" gem "rake-compiler", "~> 1.1", ">= 1.1.1" gem "redcarpet", "~> 3.4" gem "rspec", "~> 3.10" diff --git a/gemfiles/ruby_2.6.7_rails5_mysql2.gemfile.lock b/gemfiles/ruby_2.6.7_rails5_mysql2.gemfile.lock index c5030db95b1..0aea9ef6376 100644 --- a/gemfiles/ruby_2.6.7_rails5_mysql2.gemfile.lock +++ b/gemfiles/ruby_2.6.7_rails5_mysql2.gemfile.lock @@ -258,7 +258,7 @@ DEPENDENCIES pry-byebug pry-stack_explorer rails (~> 5.2.1) - rake (>= 10.5, < 13.0.4) + rake (>= 10.5) rake-compiler (~> 1.1, >= 1.1.1) redcarpet (~> 3.4) rspec (~> 3.10) diff --git a/gemfiles/ruby_2.6.7_rails5_postgres.gemfile b/gemfiles/ruby_2.6.7_rails5_postgres.gemfile index bf3d6d7444b..29f127e97dc 100644 --- a/gemfiles/ruby_2.6.7_rails5_postgres.gemfile +++ b/gemfiles/ruby_2.6.7_rails5_postgres.gemfile @@ -18,7 +18,7 @@ gem "pimpmychangelog", ">= 0.1.2" gem "pry" gem "pry-byebug" gem "pry-stack_explorer" -gem "rake", ">= 10.5", "< 13.0.4" +gem "rake", ">= 10.5" gem "rake-compiler", "~> 1.1", ">= 1.1.1" gem "redcarpet", "~> 3.4" gem "rspec", "~> 3.10" diff --git a/gemfiles/ruby_2.6.7_rails5_postgres.gemfile.lock b/gemfiles/ruby_2.6.7_rails5_postgres.gemfile.lock index c53978aaee4..2903f5ce672 100644 --- a/gemfiles/ruby_2.6.7_rails5_postgres.gemfile.lock +++ b/gemfiles/ruby_2.6.7_rails5_postgres.gemfile.lock @@ -258,7 +258,7 @@ DEPENDENCIES pry-byebug pry-stack_explorer rails (~> 5.2.1) - rake (>= 10.5, < 13.0.4) + rake (>= 10.5) rake-compiler (~> 1.1, >= 1.1.1) redcarpet (~> 3.4) rspec (~> 3.10) diff --git a/gemfiles/ruby_2.6.7_rails5_postgres_redis.gemfile b/gemfiles/ruby_2.6.7_rails5_postgres_redis.gemfile index 9c0556d68db..1f255d6624f 100644 --- a/gemfiles/ruby_2.6.7_rails5_postgres_redis.gemfile +++ b/gemfiles/ruby_2.6.7_rails5_postgres_redis.gemfile @@ -18,7 +18,7 @@ gem "pimpmychangelog", ">= 0.1.2" gem "pry" gem "pry-byebug" gem "pry-stack_explorer" -gem "rake", ">= 10.5", "< 13.0.4" +gem "rake", ">= 10.5" gem "rake-compiler", "~> 1.1", ">= 1.1.1" gem "redcarpet", "~> 3.4" gem "rspec", "~> 3.10" diff --git a/gemfiles/ruby_2.6.7_rails5_postgres_redis.gemfile.lock b/gemfiles/ruby_2.6.7_rails5_postgres_redis.gemfile.lock index 5d7b412e78a..249437d4fd9 100644 --- a/gemfiles/ruby_2.6.7_rails5_postgres_redis.gemfile.lock +++ b/gemfiles/ruby_2.6.7_rails5_postgres_redis.gemfile.lock @@ -259,7 +259,7 @@ DEPENDENCIES pry-byebug pry-stack_explorer rails (~> 5.2.1) - rake (>= 10.5, < 13.0.4) + rake (>= 10.5) rake-compiler (~> 1.1, >= 1.1.1) redcarpet (~> 3.4) redis (>= 4.0.1) diff --git a/gemfiles/ruby_2.6.7_rails5_postgres_redis_activesupport.gemfile b/gemfiles/ruby_2.6.7_rails5_postgres_redis_activesupport.gemfile index 9c0556d68db..1f255d6624f 100644 --- a/gemfiles/ruby_2.6.7_rails5_postgres_redis_activesupport.gemfile +++ b/gemfiles/ruby_2.6.7_rails5_postgres_redis_activesupport.gemfile @@ -18,7 +18,7 @@ gem "pimpmychangelog", ">= 0.1.2" gem "pry" gem "pry-byebug" gem "pry-stack_explorer" -gem "rake", ">= 10.5", "< 13.0.4" +gem "rake", ">= 10.5" gem "rake-compiler", "~> 1.1", ">= 1.1.1" gem "redcarpet", "~> 3.4" gem "rspec", "~> 3.10" diff --git a/gemfiles/ruby_2.6.7_rails5_postgres_redis_activesupport.gemfile.lock b/gemfiles/ruby_2.6.7_rails5_postgres_redis_activesupport.gemfile.lock index 5d7b412e78a..249437d4fd9 100644 --- a/gemfiles/ruby_2.6.7_rails5_postgres_redis_activesupport.gemfile.lock +++ b/gemfiles/ruby_2.6.7_rails5_postgres_redis_activesupport.gemfile.lock @@ -259,7 +259,7 @@ DEPENDENCIES pry-byebug pry-stack_explorer rails (~> 5.2.1) - rake (>= 10.5, < 13.0.4) + rake (>= 10.5) rake-compiler (~> 1.1, >= 1.1.1) redcarpet (~> 3.4) redis (>= 4.0.1) diff --git a/gemfiles/ruby_2.6.7_rails5_postgres_sidekiq.gemfile b/gemfiles/ruby_2.6.7_rails5_postgres_sidekiq.gemfile index b2976db60bd..60a581ca79f 100644 --- a/gemfiles/ruby_2.6.7_rails5_postgres_sidekiq.gemfile +++ b/gemfiles/ruby_2.6.7_rails5_postgres_sidekiq.gemfile @@ -18,7 +18,7 @@ gem "pimpmychangelog", ">= 0.1.2" gem "pry" gem "pry-byebug" gem "pry-stack_explorer" -gem "rake", ">= 10.5", "< 13.0.4" +gem "rake", ">= 10.5" gem "rake-compiler", "~> 1.1", ">= 1.1.1" gem "redcarpet", "~> 3.4" gem "rspec", "~> 3.10" diff --git a/gemfiles/ruby_2.6.7_rails5_postgres_sidekiq.gemfile.lock b/gemfiles/ruby_2.6.7_rails5_postgres_sidekiq.gemfile.lock index d4271adf40e..ad699ab1139 100644 --- a/gemfiles/ruby_2.6.7_rails5_postgres_sidekiq.gemfile.lock +++ b/gemfiles/ruby_2.6.7_rails5_postgres_sidekiq.gemfile.lock @@ -265,7 +265,7 @@ DEPENDENCIES pry-byebug pry-stack_explorer rails (~> 5.2.1) - rake (>= 10.5, < 13.0.4) + rake (>= 10.5) rake-compiler (~> 1.1, >= 1.1.1) redcarpet (~> 3.4) rspec (~> 3.10) diff --git a/gemfiles/ruby_2.6.7_rails5_semantic_logger.gemfile b/gemfiles/ruby_2.6.7_rails5_semantic_logger.gemfile index 2370ff014ae..94d6ee9beac 100644 --- a/gemfiles/ruby_2.6.7_rails5_semantic_logger.gemfile +++ b/gemfiles/ruby_2.6.7_rails5_semantic_logger.gemfile @@ -18,7 +18,7 @@ gem "pimpmychangelog", ">= 0.1.2" gem "pry" gem "pry-byebug" gem "pry-stack_explorer" -gem "rake", ">= 10.5", "< 13.0.4" +gem "rake", ">= 10.5" gem "rake-compiler", "~> 1.1", ">= 1.1.1" gem "redcarpet", "~> 3.4" gem "rspec", "~> 3.10" diff --git a/gemfiles/ruby_2.6.7_rails5_semantic_logger.gemfile.lock b/gemfiles/ruby_2.6.7_rails5_semantic_logger.gemfile.lock index 148c71bf6c8..76e3979d5ec 100644 --- a/gemfiles/ruby_2.6.7_rails5_semantic_logger.gemfile.lock +++ b/gemfiles/ruby_2.6.7_rails5_semantic_logger.gemfile.lock @@ -257,7 +257,7 @@ DEPENDENCIES pry-stack_explorer rails (~> 5.2.1) rails_semantic_logger (~> 4.0) - rake (>= 10.5, < 13.0.4) + rake (>= 10.5) rake-compiler (~> 1.1, >= 1.1.1) redcarpet (~> 3.4) rspec (~> 3.10) diff --git a/gemfiles/ruby_2.6.7_rails61_mysql2.gemfile b/gemfiles/ruby_2.6.7_rails61_mysql2.gemfile index a6aed0af81d..7572c8a6e69 100644 --- a/gemfiles/ruby_2.6.7_rails61_mysql2.gemfile +++ b/gemfiles/ruby_2.6.7_rails61_mysql2.gemfile @@ -18,7 +18,7 @@ gem "pimpmychangelog", ">= 0.1.2" gem "pry" gem "pry-byebug" gem "pry-stack_explorer" -gem "rake", ">= 10.5", "< 13.0.4" +gem "rake", ">= 10.5" gem "rake-compiler", "~> 1.1", ">= 1.1.1" gem "redcarpet", "~> 3.4" gem "rspec", "~> 3.10" diff --git a/gemfiles/ruby_2.6.7_rails61_mysql2.gemfile.lock b/gemfiles/ruby_2.6.7_rails61_mysql2.gemfile.lock index 2739c3c757f..232ceda8735 100644 --- a/gemfiles/ruby_2.6.7_rails61_mysql2.gemfile.lock +++ b/gemfiles/ruby_2.6.7_rails61_mysql2.gemfile.lock @@ -277,7 +277,7 @@ DEPENDENCIES pry-byebug pry-stack_explorer rails (~> 6.1.0) - rake (>= 10.5, < 13.0.4) + rake (>= 10.5) rake-compiler (~> 1.1, >= 1.1.1) redcarpet (~> 3.4) rspec (~> 3.10) diff --git a/gemfiles/ruby_2.6.7_rails61_postgres.gemfile b/gemfiles/ruby_2.6.7_rails61_postgres.gemfile index 59919f497c3..1dc7716f146 100644 --- a/gemfiles/ruby_2.6.7_rails61_postgres.gemfile +++ b/gemfiles/ruby_2.6.7_rails61_postgres.gemfile @@ -18,7 +18,7 @@ gem "pimpmychangelog", ">= 0.1.2" gem "pry" gem "pry-byebug" gem "pry-stack_explorer" -gem "rake", ">= 10.5", "< 13.0.4" +gem "rake", ">= 10.5" gem "rake-compiler", "~> 1.1", ">= 1.1.1" gem "redcarpet", "~> 3.4" gem "rspec", "~> 3.10" diff --git a/gemfiles/ruby_2.6.7_rails61_postgres.gemfile.lock b/gemfiles/ruby_2.6.7_rails61_postgres.gemfile.lock index e2fc1ebd695..b3d23e37e21 100644 --- a/gemfiles/ruby_2.6.7_rails61_postgres.gemfile.lock +++ b/gemfiles/ruby_2.6.7_rails61_postgres.gemfile.lock @@ -277,7 +277,7 @@ DEPENDENCIES pry-byebug pry-stack_explorer rails (~> 6.1.0) - rake (>= 10.5, < 13.0.4) + rake (>= 10.5) rake-compiler (~> 1.1, >= 1.1.1) redcarpet (~> 3.4) rspec (~> 3.10) diff --git a/gemfiles/ruby_2.6.7_rails61_postgres_redis.gemfile b/gemfiles/ruby_2.6.7_rails61_postgres_redis.gemfile index c734b06a559..337a85f8956 100644 --- a/gemfiles/ruby_2.6.7_rails61_postgres_redis.gemfile +++ b/gemfiles/ruby_2.6.7_rails61_postgres_redis.gemfile @@ -18,7 +18,7 @@ gem "pimpmychangelog", ">= 0.1.2" gem "pry" gem "pry-byebug" gem "pry-stack_explorer" -gem "rake", ">= 10.5", "< 13.0.4" +gem "rake", ">= 10.5" gem "rake-compiler", "~> 1.1", ">= 1.1.1" gem "redcarpet", "~> 3.4" gem "rspec", "~> 3.10" diff --git a/gemfiles/ruby_2.6.7_rails61_postgres_redis.gemfile.lock b/gemfiles/ruby_2.6.7_rails61_postgres_redis.gemfile.lock index 1e43d970643..f907993a2ca 100644 --- a/gemfiles/ruby_2.6.7_rails61_postgres_redis.gemfile.lock +++ b/gemfiles/ruby_2.6.7_rails61_postgres_redis.gemfile.lock @@ -278,7 +278,7 @@ DEPENDENCIES pry-byebug pry-stack_explorer rails (~> 6.1.0) - rake (>= 10.5, < 13.0.4) + rake (>= 10.5) rake-compiler (~> 1.1, >= 1.1.1) redcarpet (~> 3.4) redis (>= 4.2.5) diff --git a/gemfiles/ruby_2.6.7_rails61_postgres_sidekiq.gemfile b/gemfiles/ruby_2.6.7_rails61_postgres_sidekiq.gemfile index 8fd3fc5dadf..c1bf97d1370 100644 --- a/gemfiles/ruby_2.6.7_rails61_postgres_sidekiq.gemfile +++ b/gemfiles/ruby_2.6.7_rails61_postgres_sidekiq.gemfile @@ -18,7 +18,7 @@ gem "pimpmychangelog", ">= 0.1.2" gem "pry" gem "pry-byebug" gem "pry-stack_explorer" -gem "rake", ">= 10.5", "< 13.0.4" +gem "rake", ">= 10.5" gem "rake-compiler", "~> 1.1", ">= 1.1.1" gem "redcarpet", "~> 3.4" gem "rspec", "~> 3.10" diff --git a/gemfiles/ruby_2.6.7_rails61_postgres_sidekiq.gemfile.lock b/gemfiles/ruby_2.6.7_rails61_postgres_sidekiq.gemfile.lock index bdb090259b0..f4fb25bde10 100644 --- a/gemfiles/ruby_2.6.7_rails61_postgres_sidekiq.gemfile.lock +++ b/gemfiles/ruby_2.6.7_rails61_postgres_sidekiq.gemfile.lock @@ -283,7 +283,7 @@ DEPENDENCIES pry-byebug pry-stack_explorer rails (~> 6.1.0) - rake (>= 10.5, < 13.0.4) + rake (>= 10.5) rake-compiler (~> 1.1, >= 1.1.1) redcarpet (~> 3.4) rspec (~> 3.10) diff --git a/gemfiles/ruby_2.6.7_rails61_semantic_logger.gemfile b/gemfiles/ruby_2.6.7_rails61_semantic_logger.gemfile index 57a8fe959ce..f61e18a19e0 100644 --- a/gemfiles/ruby_2.6.7_rails61_semantic_logger.gemfile +++ b/gemfiles/ruby_2.6.7_rails61_semantic_logger.gemfile @@ -18,7 +18,7 @@ gem "pimpmychangelog", ">= 0.1.2" gem "pry" gem "pry-byebug" gem "pry-stack_explorer" -gem "rake", ">= 10.5", "< 13.0.4" +gem "rake", ">= 10.5" gem "rake-compiler", "~> 1.1", ">= 1.1.1" gem "redcarpet", "~> 3.4" gem "rspec", "~> 3.10" diff --git a/gemfiles/ruby_2.6.7_rails61_semantic_logger.gemfile.lock b/gemfiles/ruby_2.6.7_rails61_semantic_logger.gemfile.lock index 37e96dfdc9b..a9da932411f 100644 --- a/gemfiles/ruby_2.6.7_rails61_semantic_logger.gemfile.lock +++ b/gemfiles/ruby_2.6.7_rails61_semantic_logger.gemfile.lock @@ -276,7 +276,7 @@ DEPENDENCIES pry-stack_explorer rails (~> 6.1.0) rails_semantic_logger (~> 4.0) - rake (>= 10.5, < 13.0.4) + rake (>= 10.5) rake-compiler (~> 1.1, >= 1.1.1) redcarpet (~> 3.4) rspec (~> 3.10) diff --git a/gemfiles/ruby_2.6.7_rails6_mysql2.gemfile b/gemfiles/ruby_2.6.7_rails6_mysql2.gemfile index df8e8ceca66..fa602e379d9 100644 --- a/gemfiles/ruby_2.6.7_rails6_mysql2.gemfile +++ b/gemfiles/ruby_2.6.7_rails6_mysql2.gemfile @@ -18,7 +18,7 @@ gem "pimpmychangelog", ">= 0.1.2" gem "pry" gem "pry-byebug" gem "pry-stack_explorer" -gem "rake", ">= 10.5", "< 13.0.4" +gem "rake", ">= 10.5" gem "rake-compiler", "~> 1.1", ">= 1.1.1" gem "redcarpet", "~> 3.4" gem "rspec", "~> 3.10" diff --git a/gemfiles/ruby_2.6.7_rails6_mysql2.gemfile.lock b/gemfiles/ruby_2.6.7_rails6_mysql2.gemfile.lock index 4ad0511842f..4ea9bd1eb4d 100644 --- a/gemfiles/ruby_2.6.7_rails6_mysql2.gemfile.lock +++ b/gemfiles/ruby_2.6.7_rails6_mysql2.gemfile.lock @@ -274,7 +274,7 @@ DEPENDENCIES pry-byebug pry-stack_explorer rails (~> 6.0.0) - rake (>= 10.5, < 13.0.4) + rake (>= 10.5) rake-compiler (~> 1.1, >= 1.1.1) redcarpet (~> 3.4) rspec (~> 3.10) diff --git a/gemfiles/ruby_2.6.7_rails6_postgres.gemfile b/gemfiles/ruby_2.6.7_rails6_postgres.gemfile index fe217055837..65a60abd14c 100644 --- a/gemfiles/ruby_2.6.7_rails6_postgres.gemfile +++ b/gemfiles/ruby_2.6.7_rails6_postgres.gemfile @@ -18,7 +18,7 @@ gem "pimpmychangelog", ">= 0.1.2" gem "pry" gem "pry-byebug" gem "pry-stack_explorer" -gem "rake", ">= 10.5", "< 13.0.4" +gem "rake", ">= 10.5" gem "rake-compiler", "~> 1.1", ">= 1.1.1" gem "redcarpet", "~> 3.4" gem "rspec", "~> 3.10" diff --git a/gemfiles/ruby_2.6.7_rails6_postgres.gemfile.lock b/gemfiles/ruby_2.6.7_rails6_postgres.gemfile.lock index 64cd1e64398..068f5785830 100644 --- a/gemfiles/ruby_2.6.7_rails6_postgres.gemfile.lock +++ b/gemfiles/ruby_2.6.7_rails6_postgres.gemfile.lock @@ -274,7 +274,7 @@ DEPENDENCIES pry-byebug pry-stack_explorer rails (~> 6.0.0) - rake (>= 10.5, < 13.0.4) + rake (>= 10.5) rake-compiler (~> 1.1, >= 1.1.1) redcarpet (~> 3.4) rspec (~> 3.10) diff --git a/gemfiles/ruby_2.6.7_rails6_postgres_redis.gemfile b/gemfiles/ruby_2.6.7_rails6_postgres_redis.gemfile index 6267caaeb06..d4be962bfa4 100644 --- a/gemfiles/ruby_2.6.7_rails6_postgres_redis.gemfile +++ b/gemfiles/ruby_2.6.7_rails6_postgres_redis.gemfile @@ -18,7 +18,7 @@ gem "pimpmychangelog", ">= 0.1.2" gem "pry" gem "pry-byebug" gem "pry-stack_explorer" -gem "rake", ">= 10.5", "< 13.0.4" +gem "rake", ">= 10.5" gem "rake-compiler", "~> 1.1", ">= 1.1.1" gem "redcarpet", "~> 3.4" gem "rspec", "~> 3.10" diff --git a/gemfiles/ruby_2.6.7_rails6_postgres_redis.gemfile.lock b/gemfiles/ruby_2.6.7_rails6_postgres_redis.gemfile.lock index a4524fedafd..db263270303 100644 --- a/gemfiles/ruby_2.6.7_rails6_postgres_redis.gemfile.lock +++ b/gemfiles/ruby_2.6.7_rails6_postgres_redis.gemfile.lock @@ -275,7 +275,7 @@ DEPENDENCIES pry-byebug pry-stack_explorer rails (~> 6.0.0) - rake (>= 10.5, < 13.0.4) + rake (>= 10.5) rake-compiler (~> 1.1, >= 1.1.1) redcarpet (~> 3.4) redis (>= 4.0.1) diff --git a/gemfiles/ruby_2.6.7_rails6_postgres_redis_activesupport.gemfile b/gemfiles/ruby_2.6.7_rails6_postgres_redis_activesupport.gemfile index 6267caaeb06..d4be962bfa4 100644 --- a/gemfiles/ruby_2.6.7_rails6_postgres_redis_activesupport.gemfile +++ b/gemfiles/ruby_2.6.7_rails6_postgres_redis_activesupport.gemfile @@ -18,7 +18,7 @@ gem "pimpmychangelog", ">= 0.1.2" gem "pry" gem "pry-byebug" gem "pry-stack_explorer" -gem "rake", ">= 10.5", "< 13.0.4" +gem "rake", ">= 10.5" gem "rake-compiler", "~> 1.1", ">= 1.1.1" gem "redcarpet", "~> 3.4" gem "rspec", "~> 3.10" diff --git a/gemfiles/ruby_2.6.7_rails6_postgres_redis_activesupport.gemfile.lock b/gemfiles/ruby_2.6.7_rails6_postgres_redis_activesupport.gemfile.lock index a4524fedafd..db263270303 100644 --- a/gemfiles/ruby_2.6.7_rails6_postgres_redis_activesupport.gemfile.lock +++ b/gemfiles/ruby_2.6.7_rails6_postgres_redis_activesupport.gemfile.lock @@ -275,7 +275,7 @@ DEPENDENCIES pry-byebug pry-stack_explorer rails (~> 6.0.0) - rake (>= 10.5, < 13.0.4) + rake (>= 10.5) rake-compiler (~> 1.1, >= 1.1.1) redcarpet (~> 3.4) redis (>= 4.0.1) diff --git a/gemfiles/ruby_2.6.7_rails6_postgres_sidekiq.gemfile b/gemfiles/ruby_2.6.7_rails6_postgres_sidekiq.gemfile index ddc40161e03..80b76a7cd65 100644 --- a/gemfiles/ruby_2.6.7_rails6_postgres_sidekiq.gemfile +++ b/gemfiles/ruby_2.6.7_rails6_postgres_sidekiq.gemfile @@ -18,7 +18,7 @@ gem "pimpmychangelog", ">= 0.1.2" gem "pry" gem "pry-byebug" gem "pry-stack_explorer" -gem "rake", ">= 10.5", "< 13.0.4" +gem "rake", ">= 10.5" gem "rake-compiler", "~> 1.1", ">= 1.1.1" gem "redcarpet", "~> 3.4" gem "rspec", "~> 3.10" diff --git a/gemfiles/ruby_2.6.7_rails6_postgres_sidekiq.gemfile.lock b/gemfiles/ruby_2.6.7_rails6_postgres_sidekiq.gemfile.lock index d803f0a3576..c1350e7fd0c 100644 --- a/gemfiles/ruby_2.6.7_rails6_postgres_sidekiq.gemfile.lock +++ b/gemfiles/ruby_2.6.7_rails6_postgres_sidekiq.gemfile.lock @@ -281,7 +281,7 @@ DEPENDENCIES pry-byebug pry-stack_explorer rails (~> 6.0.0) - rake (>= 10.5, < 13.0.4) + rake (>= 10.5) rake-compiler (~> 1.1, >= 1.1.1) redcarpet (~> 3.4) rspec (~> 3.10) diff --git a/gemfiles/ruby_2.6.7_rails6_semantic_logger.gemfile b/gemfiles/ruby_2.6.7_rails6_semantic_logger.gemfile index 79d0d6beef8..1bc595fc964 100644 --- a/gemfiles/ruby_2.6.7_rails6_semantic_logger.gemfile +++ b/gemfiles/ruby_2.6.7_rails6_semantic_logger.gemfile @@ -18,7 +18,7 @@ gem "pimpmychangelog", ">= 0.1.2" gem "pry" gem "pry-byebug" gem "pry-stack_explorer" -gem "rake", ">= 10.5", "< 13.0.4" +gem "rake", ">= 10.5" gem "rake-compiler", "~> 1.1", ">= 1.1.1" gem "redcarpet", "~> 3.4" gem "rspec", "~> 3.10" diff --git a/gemfiles/ruby_2.6.7_rails6_semantic_logger.gemfile.lock b/gemfiles/ruby_2.6.7_rails6_semantic_logger.gemfile.lock index a49af4f26be..2ef5aa70b22 100644 --- a/gemfiles/ruby_2.6.7_rails6_semantic_logger.gemfile.lock +++ b/gemfiles/ruby_2.6.7_rails6_semantic_logger.gemfile.lock @@ -273,7 +273,7 @@ DEPENDENCIES pry-stack_explorer rails (~> 6.0.0) rails_semantic_logger (~> 4.0) - rake (>= 10.5, < 13.0.4) + rake (>= 10.5) rake-compiler (~> 1.1, >= 1.1.1) redcarpet (~> 3.4) rspec (~> 3.10) diff --git a/gemfiles/ruby_2.6.7_resque2_redis3.gemfile b/gemfiles/ruby_2.6.7_resque2_redis3.gemfile index 9f6b15a63ad..e6c264f0bea 100644 --- a/gemfiles/ruby_2.6.7_resque2_redis3.gemfile +++ b/gemfiles/ruby_2.6.7_resque2_redis3.gemfile @@ -18,7 +18,7 @@ gem "pimpmychangelog", ">= 0.1.2" gem "pry" gem "pry-byebug" gem "pry-stack_explorer" -gem "rake", ">= 10.5", "< 13.0.4" +gem "rake", ">= 10.5" gem "rake-compiler", "~> 1.1", ">= 1.1.1" gem "redcarpet", "~> 3.4" gem "rspec", "~> 3.10" diff --git a/gemfiles/ruby_2.6.7_resque2_redis3.gemfile.lock b/gemfiles/ruby_2.6.7_resque2_redis3.gemfile.lock index 1b74adcdcf1..50b093bc863 100644 --- a/gemfiles/ruby_2.6.7_resque2_redis3.gemfile.lock +++ b/gemfiles/ruby_2.6.7_resque2_redis3.gemfile.lock @@ -173,7 +173,7 @@ DEPENDENCIES pry pry-byebug pry-stack_explorer - rake (>= 10.5, < 13.0.4) + rake (>= 10.5) rake-compiler (~> 1.1, >= 1.1.1) redcarpet (~> 3.4) redis (< 4.0) diff --git a/gemfiles/ruby_2.6.7_resque2_redis4.gemfile b/gemfiles/ruby_2.6.7_resque2_redis4.gemfile index e86caab98fb..3a6a7be78c0 100644 --- a/gemfiles/ruby_2.6.7_resque2_redis4.gemfile +++ b/gemfiles/ruby_2.6.7_resque2_redis4.gemfile @@ -18,7 +18,7 @@ gem "pimpmychangelog", ">= 0.1.2" gem "pry" gem "pry-byebug" gem "pry-stack_explorer" -gem "rake", ">= 10.5", "< 13.0.4" +gem "rake", ">= 10.5" gem "rake-compiler", "~> 1.1", ">= 1.1.1" gem "redcarpet", "~> 3.4" gem "rspec", "~> 3.10" diff --git a/gemfiles/ruby_2.6.7_resque2_redis4.gemfile.lock b/gemfiles/ruby_2.6.7_resque2_redis4.gemfile.lock index a0a3209760f..93defae5c2a 100644 --- a/gemfiles/ruby_2.6.7_resque2_redis4.gemfile.lock +++ b/gemfiles/ruby_2.6.7_resque2_redis4.gemfile.lock @@ -173,7 +173,7 @@ DEPENDENCIES pry pry-byebug pry-stack_explorer - rake (>= 10.5, < 13.0.4) + rake (>= 10.5) rake-compiler (~> 1.1, >= 1.1.1) redcarpet (~> 3.4) redis (>= 4.0) diff --git a/lib/ddtrace/contrib/action_mailer/events/deliver.rb b/lib/ddtrace/contrib/action_mailer/events/deliver.rb index fcb7a2ef8e3..cea608e8c24 100644 --- a/lib/ddtrace/contrib/action_mailer/events/deliver.rb +++ b/lib/ddtrace/contrib/action_mailer/events/deliver.rb @@ -29,6 +29,7 @@ def span_type def process(span, event, _id, payload) super + span.span_type = span_type span.set_tag(Ext::TAG_MAILER, payload[:mailer]) span.set_tag(Ext::TAG_MSG_ID, payload[:message_id]) end diff --git a/lib/ddtrace/contrib/action_mailer/events/process.rb b/lib/ddtrace/contrib/action_mailer/events/process.rb index 0d78b884b28..ada4ff9ae64 100644 --- a/lib/ddtrace/contrib/action_mailer/events/process.rb +++ b/lib/ddtrace/contrib/action_mailer/events/process.rb @@ -29,6 +29,7 @@ def span_type def process(span, event, _id, payload) super + span.span_type = span_type span.set_tag(Ext::TAG_ACTION, payload[:action]) span.set_tag(Ext::TAG_MAILER, payload[:mailer]) end From 668958c3d18be0672d9dadbf731a793c00cf2fc4 Mon Sep 17 00:00:00 2001 From: ericmustin Date: Wed, 4 Aug 2021 17:19:32 -0400 Subject: [PATCH 12/17] use correct span type constants and linting --- lib/ddtrace/contrib/action_mailer/events/deliver.rb | 2 +- spec/ddtrace/contrib/action_mailer/patcher_spec.rb | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/ddtrace/contrib/action_mailer/events/deliver.rb b/lib/ddtrace/contrib/action_mailer/events/deliver.rb index cea608e8c24..da5723e080d 100644 --- a/lib/ddtrace/contrib/action_mailer/events/deliver.rb +++ b/lib/ddtrace/contrib/action_mailer/events/deliver.rb @@ -23,7 +23,7 @@ def span_name def span_type # deliver.action_mailer sends emails - Datadog::Ext::AppTypes::Worker + Datadog::Ext::AppTypes::WORKER end def process(span, event, _id, payload) diff --git a/spec/ddtrace/contrib/action_mailer/patcher_spec.rb b/spec/ddtrace/contrib/action_mailer/patcher_spec.rb index 3c19625799b..791b50b6cd7 100644 --- a/spec/ddtrace/contrib/action_mailer/patcher_spec.rb +++ b/spec/ddtrace/contrib/action_mailer/patcher_spec.rb @@ -42,11 +42,11 @@ end let(:span) do - spans.select { |s| s.name == Datadog::Contrib::ActionMailer::Ext::SPAN_PROCESS }.first + spans.find { |s| s.name == Datadog::Contrib::ActionMailer::Ext::SPAN_PROCESS } end let(:deliver_span) do - spans.select { |s| s.name == Datadog::Contrib::ActionMailer::Ext::SPAN_DELIVER }.first + spans.find { |s| s.name == Datadog::Contrib::ActionMailer::Ext::SPAN_DELIVER } end before do From b43fa1a9e653f70f544aa2b9b8bf8b3be976b54b Mon Sep 17 00:00:00 2001 From: ericmustin Date: Thu, 5 Aug 2021 11:11:25 -0400 Subject: [PATCH 13/17] sorbet updates --- spec/ddtrace/contrib/action_mailer/helpers.rb | 2 ++ spec/ddtrace/contrib/action_mailer/integration_spec.rb | 3 ++- spec/ddtrace/contrib/action_mailer/patcher_spec.rb | 2 ++ 3 files changed, 6 insertions(+), 1 deletion(-) diff --git a/spec/ddtrace/contrib/action_mailer/helpers.rb b/spec/ddtrace/contrib/action_mailer/helpers.rb index e84da1a785f..6a4f442f826 100644 --- a/spec/ddtrace/contrib/action_mailer/helpers.rb +++ b/spec/ddtrace/contrib/action_mailer/helpers.rb @@ -1,3 +1,5 @@ +# typed: ignore + require 'rails' RSpec.shared_context 'ActionMailer helpers' do diff --git a/spec/ddtrace/contrib/action_mailer/integration_spec.rb b/spec/ddtrace/contrib/action_mailer/integration_spec.rb index 2b234c3e894..6a96b78cb33 100644 --- a/spec/ddtrace/contrib/action_mailer/integration_spec.rb +++ b/spec/ddtrace/contrib/action_mailer/integration_spec.rb @@ -1,5 +1,6 @@ -require 'ddtrace/contrib/support/spec_helper' +# typed: ignore +require 'ddtrace/contrib/support/spec_helper' require 'ddtrace/contrib/action_mailer/integration' RSpec.describe Datadog::Contrib::ActionMailer::Integration do diff --git a/spec/ddtrace/contrib/action_mailer/patcher_spec.rb b/spec/ddtrace/contrib/action_mailer/patcher_spec.rb index 791b50b6cd7..04f8596073d 100644 --- a/spec/ddtrace/contrib/action_mailer/patcher_spec.rb +++ b/spec/ddtrace/contrib/action_mailer/patcher_spec.rb @@ -1,3 +1,5 @@ +# typed: ignore + require 'ddtrace/contrib/support/spec_helper' require 'ddtrace/contrib/analytics_examples' require 'rails' From 6f39604628bf0c15b93c5913d05c8d581e09caaa Mon Sep 17 00:00:00 2001 From: ericmustin Date: Thu, 5 Aug 2021 13:24:22 -0400 Subject: [PATCH 14/17] add note on test helpers --- spec/ddtrace/contrib/action_mailer/helpers.rb | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/spec/ddtrace/contrib/action_mailer/helpers.rb b/spec/ddtrace/contrib/action_mailer/helpers.rb index 6a4f442f826..7c160ea8255 100644 --- a/spec/ddtrace/contrib/action_mailer/helpers.rb +++ b/spec/ddtrace/contrib/action_mailer/helpers.rb @@ -4,6 +4,10 @@ RSpec.shared_context 'ActionMailer helpers' do before do + # internal to tests only as instrumentatioin relies on ASN + # but we patch here to ensure emails dont actually get set. + # older rubies may have this live on `DeliveryJob` instead of `Base` + # https://github.com/rails/rails/blob/e43d0ddb0359858fdb93e86b158987da81698a3d/guides/source/testing.md#the-basic-test-case if ActionMailer::Base.respond_to?(:delivery_method) ActionMailer::Base.delivery_method = :test else From e2cac58a794cd79c526303f3a548e11458788fa3 Mon Sep 17 00:00:00 2001 From: ericmustin Date: Wed, 18 Aug 2021 11:26:44 -0400 Subject: [PATCH 15/17] action_mailer: add email_data config option --- docs/GettingStarted.md | 1 + .../action_mailer/configuration/settings.rb | 1 + .../contrib/action_mailer/events/deliver.rb | 13 ++++++++++++ lib/ddtrace/contrib/action_mailer/ext.rb | 8 +++++++ spec/ddtrace/contrib/action_mailer/helpers.rb | 6 +++++- .../contrib/action_mailer/patcher_spec.rb | 21 +++++++++++++++++++ 6 files changed, 49 insertions(+), 1 deletion(-) diff --git a/docs/GettingStarted.md b/docs/GettingStarted.md index 618bb65e57c..38a1856461c 100644 --- a/docs/GettingStarted.md +++ b/docs/GettingStarted.md @@ -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_date` | 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 diff --git a/lib/ddtrace/contrib/action_mailer/configuration/settings.rb b/lib/ddtrace/contrib/action_mailer/configuration/settings.rb index 2eb29c67143..b7dc02548ef 100644 --- a/lib/ddtrace/contrib/action_mailer/configuration/settings.rb +++ b/lib/ddtrace/contrib/action_mailer/configuration/settings.rb @@ -23,6 +23,7 @@ class Settings < Contrib::Configuration::Settings end option :service_name, default: Ext::SERVICE_NAME + option :email_date, default: false end end end diff --git a/lib/ddtrace/contrib/action_mailer/events/deliver.rb b/lib/ddtrace/contrib/action_mailer/events/deliver.rb index da5723e080d..f6a4d44b7bc 100644 --- a/lib/ddtrace/contrib/action_mailer/events/deliver.rb +++ b/lib/ddtrace/contrib/action_mailer/events/deliver.rb @@ -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 + # https://github.com/rails/rails/blob/18707ab17fa492eb25ad2e8f9818a320dc20b823/actionmailer/lib/action_mailer/base.rb#L742-L754 + if configuration[:email_data] + span.set_tag(Ext::TAG_SUBJECT, payload[:subject].to_s) if payload[:subject] + span.set_tag(Ext::TAG_TO, payload[:to].to_s) if payload[:to] + span.set_tag(Ext::TAG_FROM, payload[:from].to_s) if payload[:from] + span.set_tag(Ext::TAG_BCC, payload[:bcc].to_s) if payload[:bcc] + span.set_tag(Ext::TAG_CC, payload[:cc].to_s) 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 diff --git a/lib/ddtrace/contrib/action_mailer/ext.rb b/lib/ddtrace/contrib/action_mailer/ext.rb index f8c5c2ce5ca..ba396ba6224 100644 --- a/lib/ddtrace/contrib/action_mailer/ext.rb +++ b/lib/ddtrace/contrib/action_mailer/ext.rb @@ -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 = 'action_mailer.perform_deliveries'.freeze end end end diff --git a/spec/ddtrace/contrib/action_mailer/helpers.rb b/spec/ddtrace/contrib/action_mailer/helpers.rb index 7c160ea8255..d27454d93ae 100644 --- a/spec/ddtrace/contrib/action_mailer/helpers.rb +++ b/spec/ddtrace/contrib/action_mailer/helpers.rb @@ -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 ) diff --git a/spec/ddtrace/contrib/action_mailer/patcher_spec.rb b/spec/ddtrace/contrib/action_mailer/patcher_spec.rb index 04f8596073d..e2029bdc8d9 100644 --- a/spec/ddtrace/contrib/action_mailer/patcher_spec.rb +++ b/spec/ddtrace/contrib/action_mailer/patcher_spec.rb @@ -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 From c929fc675a093acfcc5f5c98b75f9a8a4647c628 Mon Sep 17 00:00:00 2001 From: ericmustin Date: Wed, 18 Aug 2021 11:54:45 -0400 Subject: [PATCH 16/17] action_mailer: clean up formatting and fix config naming --- docs/GettingStarted.md | 2 +- .../contrib/action_mailer/configuration/settings.rb | 2 +- lib/ddtrace/contrib/action_mailer/events/deliver.rb | 10 +++++----- spec/ddtrace/contrib/action_mailer/patcher_spec.rb | 2 +- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/docs/GettingStarted.md b/docs/GettingStarted.md index 38a1856461c..6d5d7dce7cb 100644 --- a/docs/GettingStarted.md +++ b/docs/GettingStarted.md @@ -494,7 +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_date` | 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` | +| `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 diff --git a/lib/ddtrace/contrib/action_mailer/configuration/settings.rb b/lib/ddtrace/contrib/action_mailer/configuration/settings.rb index b7dc02548ef..143cd520bda 100644 --- a/lib/ddtrace/contrib/action_mailer/configuration/settings.rb +++ b/lib/ddtrace/contrib/action_mailer/configuration/settings.rb @@ -23,7 +23,7 @@ class Settings < Contrib::Configuration::Settings end option :service_name, default: Ext::SERVICE_NAME - option :email_date, default: false + option :email_data, default: false end end end diff --git a/lib/ddtrace/contrib/action_mailer/events/deliver.rb b/lib/ddtrace/contrib/action_mailer/events/deliver.rb index f6a4d44b7bc..1984f2ae39c 100644 --- a/lib/ddtrace/contrib/action_mailer/events/deliver.rb +++ b/lib/ddtrace/contrib/action_mailer/events/deliver.rb @@ -36,12 +36,12 @@ def process(span, event, _id, payload) # 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 # https://github.com/rails/rails/blob/18707ab17fa492eb25ad2e8f9818a320dc20b823/actionmailer/lib/action_mailer/base.rb#L742-L754 - if configuration[:email_data] + 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].to_s) if payload[:to] - span.set_tag(Ext::TAG_FROM, payload[:from].to_s) if payload[:from] - span.set_tag(Ext::TAG_BCC, payload[:bcc].to_s) if payload[:bcc] - span.set_tag(Ext::TAG_CC, payload[:cc].to_s) if payload[:cc] + 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 diff --git a/spec/ddtrace/contrib/action_mailer/patcher_spec.rb b/spec/ddtrace/contrib/action_mailer/patcher_spec.rb index e2029bdc8d9..b4afdf9047c 100644 --- a/spec/ddtrace/contrib/action_mailer/patcher_spec.rb +++ b/spec/ddtrace/contrib/action_mailer/patcher_spec.rb @@ -103,7 +103,7 @@ 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.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 From c21540f3f7eea81579bb4484de126756f1f0c6b8 Mon Sep 17 00:00:00 2001 From: ericmustin Date: Wed, 18 Aug 2021 12:09:05 -0400 Subject: [PATCH 17/17] action_mailer: fix constants --- lib/ddtrace/contrib/action_mailer/ext.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/ddtrace/contrib/action_mailer/ext.rb b/lib/ddtrace/contrib/action_mailer/ext.rb index ba396ba6224..b79d39ff659 100644 --- a/lib/ddtrace/contrib/action_mailer/ext.rb +++ b/lib/ddtrace/contrib/action_mailer/ext.rb @@ -24,7 +24,7 @@ module Ext TAG_BCC = 'action_mailer.bcc'.freeze TAG_CC = 'action_mailer.cc'.freeze TAG_DATE = 'action_mailer.date'.freeze - TAG_PERFORM = 'action_mailer.perform_deliveries'.freeze + TAG_PERFORM_DELIVERIES = 'action_mailer.perform_deliveries'.freeze end end end