diff --git a/lib/raven/event.rb b/lib/raven/event.rb index 9e33da08a..4034859d9 100644 --- a/lib/raven/event.rb +++ b/lib/raven/event.rb @@ -56,8 +56,12 @@ def initialize(init = {}) @user.merge!(@context.user) @extra.merge!(@context.extra) + + tags = @tags.dup + @tags = {} @tags.merge!(@configuration.tags) @tags.merge!(@context.tags) + @tags.merge!(tags) # Some type coercion @timestamp = @timestamp.strftime('%Y-%m-%dT%H:%M:%S') if @timestamp.is_a?(Time) diff --git a/spec/raven/event_spec.rb b/spec/raven/event_spec.rb index 05b2841f1..e7eb9f01b 100644 --- a/spec/raven/event_spec.rb +++ b/spec/raven/event_spec.rb @@ -230,6 +230,50 @@ end end + context 'tags hierarchy respected' do + let(:hash) do + config = Raven::Configuration.new + config.tags = { + 'configuration_context_event_key' => 'configuration_value', + 'configuration_context_key' => 'configuration_value', + 'configuration_event_key' => 'configuration_value', + 'configuration_key' => 'configuration_value', + } + + Raven.tags_context({ + 'configuration_context_event_key' => 'context_value', + 'configuration_context_key' => 'context_value', + 'context_event_key' => 'context_value', + 'context_key' => 'context_value', + }) + + Raven::Event.new( + :level => 'warning', + :logger => 'foo', + :tags => { + 'configuration_context_event_key' => 'event_value', + 'configuration_event_key' => 'event_value', + 'context_event_key' => 'event_value', + 'event_key' => 'event_value', + }, + :server_name => 'foo.local', + :configuration => config + ).to_hash + end + + it 'merges tags data' do + expect(hash[:tags]).to eq({ + 'configuration_context_event_key' => 'event_value', + 'configuration_context_key' => 'context_value', + 'configuration_event_key' => 'event_value', + 'context_event_key' => 'event_value', + 'configuration_key' => 'configuration_value', + 'context_key' => 'context_value', + 'event_key' => 'event_value', + }) + end + end + describe '.initialize' do it 'should not touch the env object for an ignored environment' do Raven.configure do |config|