lib/instana/tracing/span.rb in instana-1.7.8 vs lib/instana/tracing/span.rb in instana-1.7.9
- old
+ new
@@ -96,11 +96,11 @@
end
if HTTP_SPANS.include?(@data[:n])
set_tags(:http => { :error => "#{e.class}: #{e.message}" })
else
- set_tags(:log => { :message => e.message, :parameters => e.class.to_s })
+ log(:error, Time.now, { :message => e.message, :parameters => e.class.to_s })
end
e.instance_variable_set(:@instana_logged, true)
end
self
end
@@ -113,10 +113,11 @@
# @param kvs [Hash] list of key values to be reported in the span
#
def configure_custom(name)
@data[:n] = :sdk
@data[:data] = { :sdk => { :name => name.to_sym } }
+ @data[:data][:sdk][:custom] = { :tags => {}, :logs => {} }
self
end
# Closes out the span. This difference between this and
# the finish method tells us how the tracing is being
@@ -241,10 +242,14 @@
# Indicates whether this span is a custom or registered Span
def custom?
@data[:n] == :sdk
end
+ def inspect
+ @data.inspect
+ end
+
#############################################################
# OpenTracing Compatibility Methods
#############################################################
# Set the name of the operation
@@ -264,11 +269,12 @@
# a String, Numeric, or Boolean it will be encoded with to_s
#
def set_tag(key, value)
if custom?
@data[:data][:sdk][:custom] ||= {}
- @data[:data][:sdk][:custom][key] = value
+ @data[:data][:sdk][:custom][:tags] ||= {}
+ @data[:data][:sdk][:custom][:tags][key] = value
if key.to_sym == :'span.kind'
case value.to_sym
when :server || :consumer
@data[:data][:sdk][:type] = :entry
@@ -331,11 +337,11 @@
# Retrieve the hash of tags for this span
#
def tags(key = nil)
if custom?
- tags = @data[:data][:sdk][:custom]
+ tags = @data[:data][:sdk][:custom][:tags]
else
tags = @data[:data][key]
end
key ? tags[key] : tags
end
@@ -345,11 +351,19 @@
#
# @param event [String] event name for the log
# @param timestamp [Time] time of the log
# @param fields [Hash] Additional information to log
#
- def log(event = nil, _timestamp = Time.now, **fields)
- set_tags(:log => { :message => event, :parameters => fields })
+ def log(event = nil, timestamp = Time.now, **fields)
+ ts = ::Instana::Util.time_to_ms(timestamp).to_s
+ if custom?
+ @data[:data][:sdk][:custom][:logs][ts] = fields
+ @data[:data][:sdk][:custom][:logs][ts][:event] = event
+ else
+ set_tags(:log => fields)
+ end
+ rescue StandardError => e
+ Instana.logger.debug "#{__method__}:#{File.basename(__FILE__)}:#{__LINE__}: #{e.message}"
end
# Finish the {Span}
# Spec: OpenTracing API
#