-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #11 from salemove/logging
Add logging support
- Loading branch information
Showing
8 changed files
with
102 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
module Zipkin | ||
class Collector | ||
module LogAnnotations | ||
def self.build(span, endpoint) | ||
span.logs.map do |log| | ||
{ | ||
timestamp: Timestamp.create(log.fetch(:timestamp)), | ||
value: format_log_value(log), | ||
endpoint: endpoint | ||
} | ||
end | ||
end | ||
|
||
def self.format_log_value(log) | ||
if log.keys == %i[event timestamp] | ||
log.fetch(:event) | ||
else | ||
log | ||
.reject { |key, _value| key == :timestamp } | ||
.map { |key, value| "#{key}=#{value}" } | ||
.join(' ') | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
module Zipkin | ||
class Collector | ||
module Timestamp | ||
def self.create(time) | ||
(time.to_f * 1_000_000).to_i | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
require 'spec_helper' | ||
|
||
RSpec.describe Zipkin::Collector::LogAnnotations do | ||
let(:span) { Zipkin::Span.new(nil, 'operation_name', nil) } | ||
let(:endpoint) { 'local-endpoint' } | ||
|
||
context 'when log includes only event and timestamp' do | ||
it 'uses event as the annotation value' do | ||
message = 'some message' | ||
span.log_kv(event: message) | ||
expect(described_class.build(span, endpoint)).to include( | ||
timestamp: instance_of(Integer), | ||
value: message, | ||
endpoint: endpoint | ||
) | ||
end | ||
end | ||
|
||
context 'when log includes multiple fields' do | ||
it 'converts fields into string form' do | ||
span.log_kv(foo: 'bar', baz: 'buz') | ||
expect(described_class.build(span, endpoint)).to include( | ||
timestamp: instance_of(Integer), | ||
value: 'foo=bar baz=buz', | ||
endpoint: endpoint | ||
) | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters