diff --git a/CHANGELOG.md b/CHANGELOG.md index 41dddc4c3..78f397647 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -43,6 +43,10 @@ ``` - Prevent SDK crash when SDK logging fails ([#2817](https://github.com/getsentry/sentry-ruby/pull/2817)) +### Internal + +- Unify Logs and Metrics implementations ([#2826](https://github.com/getsentry/sentry-ruby/pull/2826)) + ## 6.2.0 ### Features diff --git a/sentry-ruby/lib/sentry/client.rb b/sentry-ruby/lib/sentry/client.rb index 80279361f..57c2f74e9 100644 --- a/sentry-ruby/lib/sentry/client.rb +++ b/sentry-ruby/lib/sentry/client.rb @@ -107,7 +107,7 @@ def capture_event(event, scope, hint = {}) # @return [LogEvent] def buffer_log_event(event, scope) return unless event.is_a?(LogEvent) - @log_event_buffer.add_event(scope.apply_to_event(event)) + @log_event_buffer.add_event(scope.apply_to_telemetry(event)) event end diff --git a/sentry-ruby/lib/sentry/log_event.rb b/sentry-ruby/lib/sentry/log_event.rb index 7cea5f0ff..44904a2c3 100644 --- a/sentry-ruby/lib/sentry/log_event.rb +++ b/sentry-ruby/lib/sentry/log_event.rb @@ -1,129 +1,52 @@ # frozen_string_literal: true -require "json" +require "sentry/utils/telemetry_attributes" module Sentry # Event type that represents a log entry with its attributes # # @see https://develop.sentry.dev/sdk/telemetry/logs/#log-envelope-item-payload class LogEvent + include Sentry::Utils::TelemetryAttributes + TYPE = "log" DEFAULT_PARAMETERS = [].freeze - DEFAULT_ATTRIBUTES = {}.freeze - - SERIALIZEABLE_ATTRIBUTES = %i[ - level - body - timestamp - environment - release - server_name - trace_id - attributes - contexts - ] - - SENTRY_ATTRIBUTES = { - "sentry.trace.parent_span_id" => :parent_span_id, - "sentry.environment" => :environment, - "sentry.release" => :release, - "sentry.address" => :server_name, - "sentry.sdk.name" => :sdk_name, - "sentry.sdk.version" => :sdk_version, - "sentry.message.template" => :template, - "sentry.origin" => :origin - } PARAMETER_PREFIX = "sentry.message.parameter" - USER_ATTRIBUTES = { - "user.id" => :user_id, - "user.name" => :user_username, - "user.email" => :user_email - } - LEVELS = %i[trace debug info warn error fatal].freeze - attr_accessor :level, :body, :template, :attributes, :user, :origin - - attr_reader :configuration, *(SERIALIZEABLE_ATTRIBUTES - %i[level body attributes]) - - SERIALIZERS = %i[ - attributes - body - level - parent_span_id - sdk_name - sdk_version - template - timestamp - trace_id - user_id - user_username - user_email - ].map { |name| [name, :"serialize_#{name}"] }.to_h + attr_accessor :level, :body, :template, :attributes, :origin, :trace_id, :span_id + attr_reader :timestamp TOKEN_REGEXP = /%\{(\w+)\}/ - def initialize(configuration: Sentry.configuration, **options) - @configuration = configuration + def initialize(**options) @type = TYPE - @server_name = configuration.server_name - @environment = configuration.environment - @release = configuration.release @timestamp = Sentry.utc_now @level = options.fetch(:level) @body = options[:body] @template = @body if is_template? - @attributes = options[:attributes] || DEFAULT_ATTRIBUTES - @user = options[:user] || {} + @attributes = options[:attributes] || {} @origin = options[:origin] - @contexts = {} + @trace_id = nil + @span_id = nil end def to_h - SERIALIZEABLE_ATTRIBUTES.each_with_object({}) do |name, memo| - memo[name] = serialize(name) - end + { + level: level.to_s, + timestamp: timestamp.to_f, + trace_id: @trace_id, + span_id: @span_id, + body: serialize_body, + attributes: serialize_attributes + }.compact end private - def serialize(name) - serializer = SERIALIZERS[name] - - if serializer - __send__(serializer) - else - public_send(name) - end - end - - def serialize_level - level.to_s - end - - def serialize_sdk_name - Sentry.sdk_meta["name"] - end - - def serialize_sdk_version - Sentry.sdk_meta["version"] - end - - def serialize_timestamp - timestamp.to_f - end - - def serialize_trace_id - contexts.dig(:trace, :trace_id) - end - - def serialize_parent_span_id - contexts.dig(:trace, :parent_span_id) - end - def serialize_body if parameters.empty? body @@ -134,61 +57,14 @@ def serialize_body end end - def serialize_user_id - user[:id] - end - - def serialize_user_username - user[:username] - end - - def serialize_user_email - user[:email] - end - - def serialize_template - template if has_parameters? - end - def serialize_attributes - hash = {} - - attributes.each do |key, value| - hash[key] = attribute_hash(value) - end - - SENTRY_ATTRIBUTES.each do |key, name| - if (value = serialize(name)) - hash[key] = attribute_hash(value) - end - end - - USER_ATTRIBUTES.each do |key, name| - if (value = serialize(name)) - hash[key] = value - end - end - - hash + populate_sentry_attributes! + @attributes.transform_values! { |v| attribute_hash(v) } end - def attribute_hash(value) - case value - when String - { value: value, type: "string" } - when TrueClass, FalseClass - { value: value, type: "boolean" } - when Integer - { value: value, type: "integer" } - when Float - { value: value, type: "double" } - else - begin - { value: JSON.generate(value), type: "string" } - rescue - { value: value, type: "string" } - end - end + def populate_sentry_attributes! + @attributes["sentry.origin"] ||= @origin if @origin + @attributes["sentry.message.template"] ||= template if has_parameters? end def parameters diff --git a/sentry-ruby/lib/sentry/metric_event.rb b/sentry-ruby/lib/sentry/metric_event.rb index 24e962703..94e9ee346 100644 --- a/sentry-ruby/lib/sentry/metric_event.rb +++ b/sentry-ruby/lib/sentry/metric_event.rb @@ -1,9 +1,13 @@ # frozen_string_literal: true +require "sentry/utils/telemetry_attributes" + module Sentry class MetricEvent - attr_reader :name, :type, :value, :unit, :timestamp, :trace_id, :span_id, :attributes, :user - attr_writer :trace_id, :span_id, :attributes, :user + include Sentry::Utils::TelemetryAttributes + + attr_reader :name, :type, :value, :unit, :timestamp, :trace_id, :span_id, :attributes + attr_writer :trace_id, :span_id, :attributes def initialize( name:, @@ -21,13 +25,9 @@ def initialize( @timestamp = Sentry.utc_now @trace_id = nil @span_id = nil - @user = {} end def to_h - populate_default_attributes! - populate_user_attributes! - { name: @name, type: @type, @@ -42,44 +42,8 @@ def to_h private - def populate_default_attributes! - configuration = Sentry.configuration - return unless configuration - - default_attributes = { - "sentry.environment" => configuration.environment, - "sentry.release" => configuration.release, - "sentry.sdk.name" => Sentry.sdk_meta["name"], - "sentry.sdk.version" => Sentry.sdk_meta["version"], - "server.address" => configuration.server_name - }.compact - - @attributes = default_attributes.merge(@attributes) - end - - def populate_user_attributes! - return unless @user - return unless Sentry.initialized? && Sentry.configuration.send_default_pii - - user_attributes = { - "user.id" => @user[:id], - "user.name" => @user[:username], - "user.email" => @user[:email] - }.compact - - @attributes = user_attributes.merge(@attributes) - end - def serialize_attributes - @attributes.transform_values do |v| - case v - when Integer then { type: "integer", value: v } - when Float then { type: "double", value: v } - when TrueClass, FalseClass then { type: "boolean", value: v } - when String then { type: "string", value: v } - else { type: "string", value: v.to_s } - end - end + @attributes.transform_values! { |v| attribute_hash(v) } end end end diff --git a/sentry-ruby/lib/sentry/scope.rb b/sentry-ruby/lib/sentry/scope.rb index ab7681ea1..6d0ec2d36 100644 --- a/sentry-ruby/lib/sentry/scope.rb +++ b/sentry-ruby/lib/sentry/scope.rb @@ -46,7 +46,7 @@ def clear # @param hint [Hash] the hint data that'll be passed to event processors. # @return [Event] def apply_to_event(event, hint = nil) - unless event.is_a?(CheckInEvent) || event.is_a?(LogEvent) + unless event.is_a?(CheckInEvent) event.tags = tags.merge(event.tags) event.user = user.merge(event.user) event.extra = extra.merge(event.extra) @@ -60,10 +60,6 @@ def apply_to_event(event, hint = nil) event.attachments = attachments end - if event.is_a?(LogEvent) - event.user = user.merge(event.user) - end - if span event.contexts[:trace] ||= span.get_trace_context @@ -92,18 +88,31 @@ def apply_to_event(event, hint = nil) # A leaner version of apply_to_event that applies to # lightweight payloads like Logs and Metrics. # - # Only adds trace_id, span_id and user from the scope. + # Adds trace_id, span_id, user from the scope and default attributes from configuration. # - # @param telemetry [MetricEvent] - # @return [MetricEvent] + # @param telemetry [MetricEvent, LogEvent] the telemetry event to apply scope context to + # @return [MetricEvent, LogEvent] the telemetry event with scope context applied def apply_to_telemetry(telemetry) # TODO-neel when new scope set_attribute api is added: add them here - telemetry.user = user.merge(telemetry.user) - trace_context = span ? span.get_trace_context : propagation_context.get_trace_context telemetry.trace_id = trace_context[:trace_id] telemetry.span_id = trace_context[:span_id] + configuration = Sentry.configuration + return telemetry unless configuration + + telemetry.attributes["sentry.sdk.name"] ||= Sentry.sdk_meta["name"] + telemetry.attributes["sentry.sdk.version"] ||= Sentry.sdk_meta["version"] + telemetry.attributes["sentry.environment"] ||= configuration.environment if configuration.environment + telemetry.attributes["sentry.release"] ||= configuration.release if configuration.release + telemetry.attributes["server.address"] ||= configuration.server_name if configuration.server_name + + if configuration.send_default_pii && !user.empty? + telemetry.attributes["user.id"] ||= user[:id] if user[:id] + telemetry.attributes["user.name"] ||= user[:username] if user[:username] + telemetry.attributes["user.email"] ||= user[:email] if user[:email] + end + telemetry end diff --git a/sentry-ruby/lib/sentry/utils/telemetry_attributes.rb b/sentry-ruby/lib/sentry/utils/telemetry_attributes.rb new file mode 100644 index 000000000..0f49dc3d7 --- /dev/null +++ b/sentry-ruby/lib/sentry/utils/telemetry_attributes.rb @@ -0,0 +1,30 @@ +# frozen_string_literal: true + +require "json" + +module Sentry + module Utils + module TelemetryAttributes + private + + def attribute_hash(value) + case value + when String + { value: value, type: "string" } + when TrueClass, FalseClass + { value: value, type: "boolean" } + when Integer + { value: value, type: "integer" } + when Float + { value: value, type: "double" } + else + begin + { value: JSON.generate(value), type: "string" } + rescue + { value: value, type: "string" } + end + end + end + end + end +end diff --git a/sentry-ruby/spec/sentry/log_event_buffer_spec.rb b/sentry-ruby/spec/sentry/log_event_buffer_spec.rb index e97a6941a..053d0d3b8 100644 --- a/sentry-ruby/spec/sentry/log_event_buffer_spec.rb +++ b/sentry-ruby/spec/sentry/log_event_buffer_spec.rb @@ -8,7 +8,6 @@ let(:client) { double(Sentry::Client) } let(:log_event) do Sentry::LogEvent.new( - configuration: Sentry.configuration, level: :info, body: "Test message" ) diff --git a/sentry-ruby/spec/sentry/log_event_spec.rb b/sentry-ruby/spec/sentry/log_event_spec.rb index 0591c1dd7..1b44664f9 100644 --- a/sentry-ruby/spec/sentry/log_event_spec.rb +++ b/sentry-ruby/spec/sentry/log_event_spec.rb @@ -1,16 +1,26 @@ # frozen_string_literal: true RSpec.describe Sentry::LogEvent do - let(:configuration) do - Sentry::Configuration.new.tap do |config| - config.dsn = Sentry::TestHelper::DUMMY_DSN + before do + perform_basic_setup do |config| + config.environment = "test" + config.release = "1.2.3" + config.server_name = "server-123" end end + let(:event_with_applied_scope_with_user) do + scope = Sentry::Scope.new + scope.set_user({ id: 123, username: "john_doe", email: "john@example.com" }) + + event = described_class.new(level: :info, body: "User John has logged in!") + scope.apply_to_telemetry(event) + event + end + describe "#initialize" do it "initializes with required attributes" do event = described_class.new( - configuration: configuration, level: :info, body: "User John has logged in!" ) @@ -22,7 +32,6 @@ it "accepts origin parameter" do event = described_class.new( - configuration: configuration, level: :info, body: "Database query executed", origin: "auto.db.rails" @@ -38,7 +47,6 @@ } event = described_class.new( - configuration: configuration, level: :info, body: "User John has logged in!", attributes: attributes @@ -49,17 +57,10 @@ end describe "#to_h" do - before do - configuration.release = "1.2.3" - configuration.environment = "test" - configuration.server_name = "server-123" - end - it "formats message with hash-based parameters" do attributes = { name: "John", day: "Monday" } event = described_class.new( - configuration: configuration, level: :info, body: "Hello %{name}, today is %{day}", attributes: attributes @@ -76,13 +77,7 @@ end it "includes all required fields" do - event = described_class.new( - configuration: configuration, - level: :info, - body: "User John has logged in!" - ) - - hash = event.to_h + hash = event_with_applied_scope_with_user.to_h expect(hash[:level]).to eq("info") expect(hash[:body]).to eq("User John has logged in!") @@ -97,7 +92,6 @@ it "doesn't set message.template when the body is not a template" do event = described_class.new( - configuration: configuration, level: :info, body: "User John has logged in!" ) @@ -109,7 +103,6 @@ it "doesn't set message.template when template has no parameters" do event = described_class.new( - configuration: configuration, level: :info, body: "Hello %{name}, today is %{day}" ) @@ -127,7 +120,6 @@ } event = described_class.new( - configuration: configuration, level: :info, body: "User %s has logged in!", attributes: attributes @@ -149,7 +141,6 @@ } event = described_class.new( - configuration: configuration, level: :info, body: "Test message", attributes: attributes @@ -164,29 +155,18 @@ end it "serializes user attributes correctly" do - user = { - id: 123, - username: "john_doe", - email: "john@example.com" - } - - event = described_class.new( - configuration: configuration, - level: :info, - body: "User action performed", - user: user - ) - - hash = event.to_h - - expect(hash[:attributes]["user.id"]).to eq(123) - expect(hash[:attributes]["user.name"]).to eq("john_doe") - expect(hash[:attributes]["user.email"]).to eq("john@example.com") + # Enable send_default_pii so user attributes are added + Sentry.configuration.send_default_pii = true + hash = event_with_applied_scope_with_user.to_h + + # User attributes are now wrapped with type information (consistent with MetricEvent) + expect(hash[:attributes]["user.id"]).to eq({ value: 123, type: "integer" }) + expect(hash[:attributes]["user.name"]).to eq({ value: "john_doe", type: "string" }) + expect(hash[:attributes]["user.email"]).to eq({ value: "john@example.com", type: "string" }) end it "includes sentry.origin attribute when origin is set" do event = described_class.new( - configuration: configuration, level: :info, body: "Database query executed", origin: "auto.db.rails" @@ -199,7 +179,6 @@ it "does not include sentry.origin attribute when origin is nil" do event = described_class.new( - configuration: configuration, level: :info, body: "Manual log message" ) diff --git a/sentry-ruby/spec/sentry/metric_event_spec.rb b/sentry-ruby/spec/sentry/metric_event_spec.rb index dfde488b8..999b651e3 100644 --- a/sentry-ruby/spec/sentry/metric_event_spec.rb +++ b/sentry-ruby/spec/sentry/metric_event_spec.rb @@ -12,6 +12,13 @@ ) end + let(:metric_event_scope_applied) do + scope = Sentry::Scope.new + scope.set_user({ id: "123", username: "jane", email: "jane.doe@email.com" }) + scope.apply_to_telemetry(metric_event) + metric_event + end + before do perform_basic_setup do |config| config.environment = "test" @@ -31,7 +38,6 @@ expect(metric_event.timestamp).to be_a(Time) expect(metric_event.trace_id).to be_nil expect(metric_event.span_id).to be_nil - expect(metric_event.user).to eq({}) end it "accepts custom attributes" do @@ -73,7 +79,7 @@ end it "includes default attributes from configuration" do - hash = metric_event.to_h + hash = metric_event_scope_applied.to_h attributes = hash[:attributes] expect(attributes["sentry.environment"]).to eq({ type: "string", value: "test" }) @@ -118,6 +124,8 @@ value: 1.0, attributes: { "custom" => "value" } ) + scope = Sentry::Scope.new + scope.apply_to_telemetry(event) hash = event.to_h attributes = hash[:attributes] @@ -126,17 +134,13 @@ end context "with user data" do - before do - metric_event.user = { id: "123", username: "jane", email: "jane.doe@email.com" } - end - context "when send_default_pii is true" do before do Sentry.configuration.send_default_pii = true end it "includes user.id attribute" do - hash = metric_event.to_h + hash = metric_event_scope_applied.to_h expect(hash[:attributes]["user.id"]).to eq({ type: "string", value: "123" }) expect(hash[:attributes]["user.name"]).to eq({ type: "string", value: "jane" }) @@ -150,7 +154,7 @@ end it "does not include user attributes" do - hash = metric_event.to_h + hash = metric_event_scope_applied.to_h expect(hash[:attributes].key?("user.id")).to eq(false) expect(hash[:attributes].key?("user.name")).to eq(false) diff --git a/sentry-ruby/spec/sentry/scope_spec.rb b/sentry-ruby/spec/sentry/scope_spec.rb index 70d7896f2..0f4cbfae7 100644 --- a/sentry-ruby/spec/sentry/scope_spec.rb +++ b/sentry-ruby/spec/sentry/scope_spec.rb @@ -207,7 +207,6 @@ let(:event) { client.event_from_message("test message") } let(:check_in_event) { client.event_from_check_in("test_slug", :ok) } - let(:log_event) { client.event_from_log("test log message", level: :info) } it "applies the contextual data to event" do subject.apply_to_event(event) @@ -239,32 +238,6 @@ expect(check_in_event.contexts).to include(:trace) end - context "with LogEvent" do - it "adds user attributes to log event" do - scope = described_class.new - scope.set_user({ id: 123, username: "john_doe", email: "john@example.com" }) - - scope.apply_to_event(log_event) - - log_hash = log_event.to_h - - expect(log_hash[:attributes]["user.id"]).to eq(123) - expect(log_hash[:attributes]["user.name"]).to eq("john_doe") - expect(log_hash[:attributes]["user.email"]).to eq("john@example.com") - end - - it "does not add user attributes when user is empty" do - scope = described_class.new - scope.apply_to_event(log_event) - - log_hash = log_event.to_h - - expect(log_hash[:attributes]).not_to have_key("user.id") - expect(log_hash[:attributes]).not_to have_key("user.name") - expect(log_hash[:attributes]).not_to have_key("user.email") - end - end - it "doesn't override event's pre-existing data" do event.tags = { foo: "baz" } event.user = { id: 2 } @@ -415,49 +388,107 @@ end describe "#apply_to_telemetry" do - before { perform_basic_setup } - - let(:metric_event) do - Sentry::MetricEvent.new(name: "test.metric", type: :counter, value: 1) + before do + perform_basic_setup do |config| + config.environment = "test" + config.release = "1.2.3" + config.server_name = "my-server" + end end - context "with user data" do - before { subject.set_user({ id: 1, username: "test_user" }) } + shared_examples "telemetry event user data" do + context "with user data" do + before { subject.set_user({ id: 123, username: "john_doe", email: "john@example.com" }) } - it "merges user data from scope to telemetry" do - subject.apply_to_telemetry(metric_event) - expect(metric_event.user).to eq({ id: 1, username: "test_user" }) + it "adds user attributes when send_default_pii is enabled" do + Sentry.configuration.send_default_pii = true + subject.apply_to_telemetry(telemetry_event) + + hash = telemetry_event.to_h + expect(hash[:attributes]["user.id"]).to eq({ value: 123, type: "integer" }) + expect(hash[:attributes]["user.name"]).to eq({ value: "john_doe", type: "string" }) + expect(hash[:attributes]["user.email"]).to eq({ value: "john@example.com", type: "string" }) + end + + it "doesn't add user attributes when send_default_pii is disabled" do + Sentry.configuration.send_default_pii = false + subject.apply_to_telemetry(telemetry_event) + + hash = telemetry_event.to_h + expect(hash[:attributes].key?("user.id")).to eq(false) + expect(hash[:attributes].key?("user.name")).to eq(false) + expect(hash[:attributes].key?("user.email")).to eq(false) + end end - it "doesn't override telemetry's pre-existing user data" do - metric_event.user = { id: 2, email: "test@example.com" } - subject.apply_to_telemetry(metric_event) - expect(metric_event.user).to eq({ id: 2, username: "test_user", email: "test@example.com" }) + context "without user data" do + it "does not add user attributes when user is empty" do + Sentry.configuration.send_default_pii = true + subject.apply_to_telemetry(telemetry_event) + + hash = telemetry_event.to_h + expect(hash[:attributes]).not_to have_key("user.id") + expect(hash[:attributes]).not_to have_key("user.name") + expect(hash[:attributes]).not_to have_key("user.email") + end end end - it "sets trace_id and span_id from propagation context when no span is set" do - subject.apply_to_telemetry(metric_event) + shared_examples "telemetry event trace data" do + it "sets trace_id and span_id from propagation context when no span is set" do + subject.apply_to_telemetry(telemetry_event) + hash = telemetry_event.to_h + + trace_context = subject.propagation_context.get_trace_context + expect(hash[:trace_id]).to eq(trace_context[:trace_id]) + expect(hash[:span_id]).to eq(trace_context[:span_id]) + end + + it "sets trace_id and span_id from span when span is set" do + transaction = Sentry::Transaction.new(op: "test_op") + subject.set_span(transaction) + + subject.apply_to_telemetry(telemetry_event) + hash = telemetry_event.to_h - trace_context = subject.propagation_context.get_trace_context - expect(metric_event.trace_id).to eq(trace_context[:trace_id]) - expect(metric_event.span_id).to eq(trace_context[:span_id]) + trace_context = transaction.get_trace_context + expect(hash[:trace_id]).to eq(trace_context[:trace_id]) + expect(hash[:span_id]).to eq(trace_context[:span_id]) + end end - it "sets trace_id and span_id from span when span is set" do - transaction = Sentry::Transaction.new(op: "test_op") - subject.set_span(transaction) + shared_examples "telemetry event default attributes" do + it "includes default attributes from configuration" do + subject.apply_to_telemetry(telemetry_event) + hash = telemetry_event.to_h + attributes = hash[:attributes] - subject.apply_to_telemetry(metric_event) + expect(attributes["sentry.environment"]).to eq({ type: "string", value: "test" }) + expect(attributes["sentry.release"]).to eq({ type: "string", value: "1.2.3" }) + expect(attributes["sentry.sdk.name"]).to eq({ type: "string", value: Sentry.sdk_meta["name"] }) + expect(attributes["sentry.sdk.version"]).to eq({ type: "string", value: Sentry.sdk_meta["version"] }) + expect(attributes["server.address"]).to eq({ type: "string", value: "my-server" }) + end + end - trace_context = transaction.get_trace_context - expect(metric_event.trace_id).to eq(trace_context[:trace_id]) - expect(metric_event.span_id).to eq(trace_context[:span_id]) + context "with MetricEvent" do + let(:telemetry_event) do + Sentry::MetricEvent.new(name: "test.metric", type: :counter, value: 1) + end + + include_examples "telemetry event user data" + include_examples "telemetry event trace data" + include_examples "telemetry event default attributes" end - it "returns the telemetry object" do - result = subject.apply_to_telemetry(metric_event) - expect(result).to eq(metric_event) + context "with LogEvent" do + let(:telemetry_event) do + Sentry.get_current_client.event_from_log("test log message", level: :info) + end + + include_examples "telemetry event user data" + include_examples "telemetry event trace data" + include_examples "telemetry event default attributes" end end end diff --git a/sentry-ruby/spec/sentry/transport_spec.rb b/sentry-ruby/spec/sentry/transport_spec.rb index 2909ea389..56a941bcf 100644 --- a/sentry-ruby/spec/sentry/transport_spec.rb +++ b/sentry-ruby/spec/sentry/transport_spec.rb @@ -212,7 +212,6 @@ let(:log_events) do 5.times.map do |i| Sentry::LogEvent.new( - configuration: configuration, level: :info, body: "User %s has logged in!", trace_id: "5b8efff798038103d269b633813fc60c", @@ -266,7 +265,6 @@ expect(log_event["attributes"]).to include( "sentry.message.template" => { "value" => "User %s has logged in!", "type" => "string" }, "sentry.message.parameter.0" => { "value" => "John", "type" => "string" }, - "sentry.environment" => { "value" => "development", "type" => "string" } ) end end @@ -529,7 +527,6 @@ let(:log_events) do 5.times.map do |i| Sentry::LogEvent.new( - configuration: configuration, level: :info, body: "User John has logged in!", trace_id: "5b8efff798038103d269b633813fc60c", diff --git a/sentry-ruby/spec/sentry_spec.rb b/sentry-ruby/spec/sentry_spec.rb index 581058db9..38ba360bf 100644 --- a/sentry-ruby/spec/sentry_spec.rb +++ b/sentry-ruby/spec/sentry_spec.rb @@ -385,10 +385,10 @@ expect(log_event[:level]).to eq("info") expect(log_event[:trace_id]).to_not be(nil) - expect(log_event[:attributes]).to_not have_key("sentry.trace.parent_span_id") + expect(log_event[:span_id]).to_not be(nil) end - it "sends a log event with parent_span_id" do + it "sends a log event with span_id" do transaction = Sentry.start_transaction(name: "test_transaction", op: "test.op") span = transaction.start_child(op: "child span") @@ -406,8 +406,8 @@ log_event = sentry_logs.first expect(log_event[:level]).to eq("info") - expect(log_event[:trace_id]).to_not be(nil) - expect(log_event[:attributes]).to have_key("sentry.trace.parent_span_id") + expect(log_event[:trace_id]).to eq(span.trace_id) + expect(log_event[:span_id]).to eq(span.span_id) end it "includes sentry.origin attribute when origin is provided" do