test-tracer 1.1.0 → 1.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ee64ccc49b552feba85f706f6bac12e3e533ce01
4
- data.tar.gz: 8209e0cfc6486a354fee51bc126e5740fc12d7ad
3
+ metadata.gz: 4739863b3eb7ab8856bb7aa3a3e0e9bc7c7852b8
4
+ data.tar.gz: 0c9a7a17bf4adb350b2dc575db89095052b1985d
5
5
  SHA512:
6
- metadata.gz: 703cb08e6050c4f3e43391bc6cf8ca3a45dfbd69a71117d2ee6338b3441d29d1cf858965f3757c12889850aac80c6a6b56d2e5c28988109334794346efb7bad4
7
- data.tar.gz: 54d59ab71bb8a9619ba627e12ded651cb8d795fe315ed8cff7de52dad127b55812e29989da2c7191070c6da0c1689eb5860748c71f8be9f96f6f27dabd284270
6
+ metadata.gz: ce894897631dd6c8087aedaabceae8abc43a0fdb7795f41dcbfadffc14b3e274a84523289700877c9ef882acfb3d8360775cc385d93667031ab01af527a7b613
7
+ data.tar.gz: feb5e4eb5f9fda6b9cf2d99fd182f411f3a6e0ed55ba0f3483dbd385ac991782664f8488378a024671ebd07e4539957a1f23d802bc02d45d1dd9c4a073becf43
data/README.md CHANGED
@@ -28,12 +28,52 @@ In addition to OT compatible methods `Test::Tracer` provides the following metho
28
28
  1. `spans` returns all spans, including those in progress.
29
29
  2. `finished_spans` returns only finished spans.
30
30
 
31
+ ### Usage
32
+
33
+ ```ruby
34
+ require "test/tracer"
35
+
36
+ describe "Test::Tracer examples" do
37
+ let(:tracer) { Test::Tracer.new }
38
+
39
+ context "when we expect no traces" do
40
+ it "does not have any traces started" do
41
+ expect(tracer.spans).to be_empty
42
+ end
43
+
44
+ it "does not have any traces recorded" do
45
+ expect(tracer.finished_spans).to be_empty
46
+ end
47
+ end
48
+
49
+ context "when we expect traces to be present" do
50
+ it "does have some traces started" do
51
+ expect(tracer.spans).not_to be_empty
52
+ end
53
+
54
+ it "does have some traces recorded" do
55
+ expect(tracer.finished_spans).not_to be_empty
56
+ end
57
+ end
58
+
59
+ context "when we expect exactly N traces" do
60
+ it "has N traces started" do
61
+ expect(tracer.spans.size).to eq(N)
62
+ end
63
+
64
+ it "has N traces recorded" do
65
+ expect(tracer.finished_spans.size).to eq(N)
66
+ end
67
+ end
68
+ end
69
+ ```
70
+
31
71
  ## Test::Span
32
72
 
33
73
  In addition to OT compatible methods `Test::Span` provides the following methods:
34
74
 
35
75
  1. `tracer` returns the tracer the span was created by.
36
- 1. `in_progress?` informs whether the span is in progress, or it's finished.
76
+ 1. `in_progress?`, `started?`, `finished?` informs whether the span is in progress, or it's finished.
37
77
  2. `start_time` returns when the span was started.
38
78
  2. `end_time` returns when the span was finished, or nil if still in progress.
39
79
  2. `tags` returns the span's tags.
@@ -41,6 +81,66 @@ In addition to OT compatible methods `Test::Span` provides the following methods
41
81
 
42
82
  The modification operations e.g. `operation_name=`, `set_tag`, `set_baggage_item` on a span are not allowed after it's finished. It throws `Test::Span::SpanAlreadyFinished` exception. The same with `finish`. The span can be finished only once.
43
83
 
84
+ ### Usage
85
+
86
+ ```ruby
87
+ require "test/tracer"
88
+
89
+ describe "Test::Span examples" do
90
+ let(:tracer) { Test::Tracer.new }
91
+
92
+ context "when a new span was started" do
93
+ let(:span) { tracer.start_span("operation name", tags: {'component' => 'ActiveRecord'}) }
94
+
95
+ it "is in progress" do
96
+ expect(span.in_progress?).to eq(true)
97
+ end
98
+
99
+ it "does have the proper name" do
100
+ expect(span.operation_name).to eq("operation name")
101
+ end
102
+
103
+ it "does include standard OT tags" do
104
+ expect(span.tags).to include('component' => 'ActiveRecord')
105
+ end
106
+
107
+ it "does not have any log entries" do
108
+ expect(span.logs).to be_empty
109
+ end
110
+ end
111
+
112
+ context "when an event was logged" do
113
+ let(:span) do
114
+ current_span = tracer.start_span("operation name")
115
+ current_span.log(event: "exceptional message", severity: Logger::ERROR, pid: $1)
116
+ current_span
117
+ end
118
+
119
+ it "does have some log entries recorded" do
120
+ expect(span.logs).not_to be_empty
121
+ end
122
+
123
+ it "includes all the event attributes" do
124
+ log = span.logs.first
125
+ expect(log.event).to eq("exceptional message")
126
+ expect(log.fields).to include(severity: Logger::ERROR)
127
+ end
128
+ end
129
+
130
+ context "when a span was finished" do
131
+ let(:span) { tracer.start_span("operation name").finish }
132
+
133
+ it "is not in progress" do
134
+ expect(span.in_progress?).to eq(false)
135
+ end
136
+
137
+ it "can't be finished twice" do
138
+ expect { span.finish }.to raise_error(Test::Span::SpanAlreadyFinished)
139
+ end
140
+ end
141
+ end
142
+ ```
143
+
44
144
  ## Test::SpanContext
45
145
 
46
146
  Context propagation is fully implemented by the tracer, and is inspired by [Jaeger](http://jaeger.readthedocs.io/en/latest/) and [TraceContext](https://github.com/TraceContext/tracecontext-spec/pull/1/files). In addition to OT compatible methods `Test::SpanContext` provides the following methods:
@@ -49,22 +149,28 @@ Context propagation is fully implemented by the tracer, and is inspired by [Jaeg
49
149
  1. `span_id` returns the ID of the current span.
50
150
  2. `parent_span_id` returns the ID of the parent span.
51
151
 
52
- ## Usage
152
+
153
+ ### Usage
53
154
 
54
155
  ```ruby
55
- gem 'test-tracer'
156
+ require "test/tracer"
157
+
158
+ describe "Test::SpanContext examples" do
159
+ let(:tracer) { Test::Tracer.new }
56
160
 
57
- tracer = Test::Tracer.new
161
+ context "when a new span was started as child of root" do
162
+ let(:root_context) { tracer.start_span("root span").context }
163
+ let(:child_context) { tracer.start_span("child span", child_of: root_context).context }
58
164
 
59
- root_span = tracer.start_span("root")
60
- tracer.spans # => will include root_span
61
- child_span = tracer.start_span("child", child_of: root_span)
62
- tracer.spans # => will include both root_span, child_span
165
+ it "all have the same trace_id" do
166
+ expect(child_context.trace_id).to eq(root_context.trace_id)
167
+ end
63
168
 
64
- child_span.finish
65
- tracer.finished_spans # => will include child_span
66
- root_span.finish
67
- tracer.finished_spans # => will include child_span, root_span
169
+ it "propagates parent child relationship" do
170
+ expect(child_context.parent_span_id).to eq(root_context.span_id)
171
+ end
172
+ end
173
+ end
68
174
  ```
69
175
 
70
176
  ## Development
@@ -29,6 +29,12 @@ module Test
29
29
  @in_progress
30
30
  end
31
31
 
32
+ alias_method :started?, :in_progress?
33
+
34
+ def finished?
35
+ !in_progress?
36
+ end
37
+
32
38
  def context
33
39
  @context
34
40
  end
@@ -4,7 +4,7 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
4
 
5
5
  Gem::Specification.new do |spec|
6
6
  spec.name = "test-tracer"
7
- spec.version = "1.1.0"
7
+ spec.version = "1.1.1"
8
8
  spec.authors = ["iaintshine"]
9
9
  spec.email = ["bodziomista@gmail.com"]
10
10
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: test-tracer
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0
4
+ version: 1.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - iaintshine
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-08-15 00:00:00.000000000 Z
11
+ date: 2017-08-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: opentracing