From f06d83f798408d7cae6f1d7fa4d1b0d0f27a7287 Mon Sep 17 00:00:00 2001 From: Jonathan Batten Date: Thu, 23 Apr 2015 19:57:26 +1000 Subject: [PATCH] Ensure that the tags hierarchy is respected where event > context > configuration for tags using the same key. --- lib/raven/event.rb | 4 ++++ spec/raven/event_spec.rb | 44 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 48 insertions(+) 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|