gitlab-labkit 0.1.2 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 190e76612be6032be5116ecf271dd78b4f1d8bcdd07e3f47516a161b3c69f1ac
4
- data.tar.gz: 890b5aadb68d2d3da1a80869b288e57180a6b8a30571227811abe20fbdc8a1f8
3
+ metadata.gz: a7e7afa0f2bf64760a144d433f5433532c1a08f1157f2ca46f180f13fead059b
4
+ data.tar.gz: 6647d722dc1ad3835001401ff13be3545649bbbc5847d664678422c3f3bab688
5
5
  SHA512:
6
- metadata.gz: f9b3eabc156afeb32ad87e68e542993a8a6789e3b702c114bf5d5bed9002d11341a6dfafcbb3f2ca5a6460b3e5fb8eb9a589fff9a71f1b62a4dfa9d8e6be54f1
7
- data.tar.gz: 2683b9da50c2878c120b8c4a53cb44f179e301c655cdad125aa23bfe7c034bf6f78a0fdbc5d6dad14dfe2873ee30d0e6adbffe9eaab88292a610c88db41a06c4
6
+ metadata.gz: 1c2a10af3bb8968d523f62a40ef1597af6c26173b7b433c6ed7a1f2f613f76c02008653471dba139a82de7582e564d703da3b28b4bdc10f081c443dd0a41a07d
7
+ data.tar.gz: 5d38c2ef80073df95a0b3898e324ef7ac7b3e962bb72470833f4b1f0c1d28e64580c164fdcfca5d84f2f2e1579f3bd3b6211996205254be35631f5143787e07f
@@ -29,5 +29,5 @@ Gem::Specification.new do |spec|
29
29
  spec.add_development_dependency "rspec-parameterized", "~> 0.4"
30
30
  spec.add_development_dependency "rubocop", "~> 0.65.0"
31
31
  spec.add_development_dependency "rubocop-rspec", "~> 1.22.1"
32
- spec.add_development_dependency "rufo", "~> 0.5"
32
+ spec.add_development_dependency "rufo", "~> 0.6"
33
33
  end
@@ -9,7 +9,6 @@ module Labkit
9
9
  # GRPCInterceptor is a client-side GRPC interceptor
10
10
  # for instrumenting GRPC calls with distributed tracing
11
11
  class GRPCInterceptor < GRPC::ClientInterceptor
12
- include Common
13
12
  include Singleton
14
13
 
15
14
  def request_response(request:, call:, method:, metadata:)
@@ -33,7 +32,7 @@ module Labkit
33
32
  def wrap_with_tracing(method, grpc_type, metadata)
34
33
  tags = { "component" => "grpc", "span.kind" => "client", "grpc.method" => method, "grpc.type" => grpc_type }
35
34
 
36
- in_tracing_span(operation_name: "grpc:#{method}", tags: tags) do |span|
35
+ TracingUtils.with_tracing(operation_name: "grpc:#{method}", tags: tags) do |span|
37
36
  OpenTracing.inject(span.context, OpenTracing::FORMAT_TEXT_MAP, metadata)
38
37
 
39
38
  yield
@@ -10,8 +10,6 @@ module Labkit
10
10
  # instrumenting incoming http requests into a Rails/Rack
11
11
  # server
12
12
  class RackMiddleware
13
- include Common
14
-
15
13
  REQUEST_METHOD = "REQUEST_METHOD"
16
14
 
17
15
  def initialize(app)
@@ -21,10 +19,10 @@ module Labkit
21
19
  def call(env)
22
20
  method = env[REQUEST_METHOD]
23
21
 
24
- context = tracer.extract(OpenTracing::FORMAT_RACK, env)
22
+ context = TracingUtils.tracer.extract(OpenTracing::FORMAT_RACK, env)
25
23
  tags = { "component" => "rack", "span.kind" => "server", "http.method" => method, "http.url" => self.class.build_sanitized_url_from_env(env) }
26
24
 
27
- in_tracing_span(operation_name: "http:#{method}", child_of: context, tags: tags) do |span|
25
+ TracingUtils.with_tracing(operation_name: "http:#{method}", child_of: context, tags: tags) do |span|
28
26
  @app.call(env).tap { |status_code, _headers, _body| span.set_tag("http.status_code", status_code) }
29
27
  end
30
28
  end
@@ -9,7 +9,6 @@ module Labkit
9
9
  # functionality for the rails instrumentation classes
10
10
  module RailsCommon
11
11
  extend ActiveSupport::Concern
12
- include Labkit::Tracing::Common
13
12
 
14
13
  class_methods do
15
14
  def create_unsubscriber(subscriptions)
@@ -20,7 +19,7 @@ module Labkit
20
19
  def generate_span_for_notification(operation_name, start, finish, payload, tags)
21
20
  exception = payload[:exception]
22
21
 
23
- postnotify_span(operation_name, start, finish, tags: tags, exception: exception)
22
+ TracingUtils.postnotify_span(operation_name, start, finish, tags: tags, exception: exception)
24
23
  end
25
24
  end
26
25
  end
@@ -14,10 +14,9 @@ module Labkit
14
14
  SPAN_KIND = "client"
15
15
 
16
16
  def call(_worker_class, job, _queue, _redis_pool)
17
- in_tracing_span(operation_name: "sidekiq:#{job["class"]}", tags: tags_from_job(job, SPAN_KIND)) do |span|
17
+ TracingUtils.with_tracing(operation_name: "sidekiq:#{job["class"]}", tags: tags_from_job(job, SPAN_KIND)) do |span|
18
18
  # Inject the details directly into the job
19
- tracer
20
- .inject(span.context, OpenTracing::FORMAT_TEXT_MAP, job)
19
+ TracingUtils.tracer.inject(span.context, OpenTracing::FORMAT_TEXT_MAP, job)
21
20
 
22
21
  yield
23
22
  end
@@ -14,9 +14,9 @@ module Labkit
14
14
  SPAN_KIND = "server"
15
15
 
16
16
  def call(_worker, job, _queue)
17
- context = tracer.extract(OpenTracing::FORMAT_TEXT_MAP, job)
17
+ context = TracingUtils.tracer.extract(OpenTracing::FORMAT_TEXT_MAP, job)
18
18
 
19
- in_tracing_span(operation_name: "sidekiq:#{job["class"]}", child_of: context, tags: tags_from_job(job, SPAN_KIND)) { |_span| yield }
19
+ TracingUtils.with_tracing(operation_name: "sidekiq:#{job["class"]}", child_of: context, tags: tags_from_job(job, SPAN_KIND)) { |_span| yield }
20
20
  end
21
21
  end
22
22
  end
@@ -5,8 +5,6 @@ module Labkit
5
5
  module Sidekiq
6
6
  # SidekiqCommon is a mixin for the sidekiq middleware components
7
7
  module SidekiqCommon
8
- include Labkit::Tracing::Common
9
-
10
8
  def tags_from_job(job, kind)
11
9
  {
12
10
  "component" => "sidekiq",
@@ -4,14 +4,11 @@ require "opentracing"
4
4
 
5
5
  module Labkit
6
6
  module Tracing
7
- # Common is a mixin for various distributed tracing instrumentation
8
- module Common
9
- def tracer
10
- OpenTracing.global_tracer
11
- end
12
-
7
+ # Internal methods for tracing. This is not part of the LabKit public API.
8
+ # For internal usage only
9
+ class TracingUtils
13
10
  # Convience method for running a block with a span
14
- def in_tracing_span(operation_name:, tags:, child_of: nil)
11
+ def self.with_tracing(operation_name:, tags:, child_of: nil)
15
12
  scope = tracer.start_active_span(operation_name, child_of: child_of, tags: tags)
16
13
  span = scope.span
17
14
 
@@ -29,7 +26,13 @@ module Labkit
29
26
  end
30
27
  end
31
28
 
32
- def postnotify_span(operation_name, start_time, end_time, tags: nil, child_of: nil, exception: nil)
29
+ # Obtain a tracer instance
30
+ def self.tracer
31
+ OpenTracing.global_tracer
32
+ end
33
+
34
+ # Generate a span retrospectively
35
+ def self.postnotify_span(operation_name, start_time, end_time, tags: nil, child_of: nil, exception: nil)
33
36
  span = OpenTracing.start_span(operation_name, start_time: start_time, tags: tags, child_of: child_of)
34
37
 
35
38
  log_exception_on_span(span, exception) if exception
@@ -37,12 +40,14 @@ module Labkit
37
40
  span.finish(end_time: end_time)
38
41
  end
39
42
 
40
- def log_exception_on_span(span, exception)
43
+ # Add exception logging to a span
44
+ def self.log_exception_on_span(span, exception)
41
45
  span.set_tag("error", true)
42
46
  span.log_kv(kv_tags_for_exception(exception))
43
47
  end
44
48
 
45
- def kv_tags_for_exception(exception)
49
+ # Generate key-value tags for an exception
50
+ def self.kv_tags_for_exception(exception)
46
51
  case exception
47
52
  when Exception
48
53
  {
@@ -5,13 +5,13 @@ require "active_support/all"
5
5
  module Labkit
6
6
  # Tracing provides distributed tracing functionality
7
7
  module Tracing
8
- autoload :Common, "labkit/tracing/common"
9
8
  autoload :Factory, "labkit/tracing/factory"
10
9
  autoload :GRPCInterceptor, "labkit/tracing/grpc_interceptor"
11
10
  autoload :JaegerFactory, "labkit/tracing/jaeger_factory"
12
11
  autoload :RackMiddleware, "labkit/tracing/rack_middleware"
13
12
  autoload :Rails, "labkit/tracing/rails"
14
13
  autoload :Sidekiq, "labkit/tracing/sidekiq"
14
+ autoload :TracingUtils, "labkit/tracing/tracing_utils"
15
15
 
16
16
  # Tracing is only enabled when the `GITLAB_TRACING` env var is configured.
17
17
  def self.enabled?
@@ -43,5 +43,15 @@ module Labkit
43
43
  .gsub("{{ correlation_id }}", correlation_id)
44
44
  .gsub("{{ service }}", service_name)
45
45
  end
46
+
47
+ # This will run a block with a span
48
+ # @param operation_name [String] The operation name for the span
49
+ # @param tags [Hash] Tags to assign to the span
50
+ # @param child_of [SpanContext, Span] SpanContext that acts as a parent to
51
+ # the newly-started span. If a span instance is provided, its
52
+ # context is automatically substituted.
53
+ def self.with_tracing(**kwargs, &block)
54
+ TracingUtils.with_tracing(**kwargs, &block)
55
+ end
46
56
  end
47
57
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gitlab-labkit
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andrew Newdigate
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-03-04 00:00:00.000000000 Z
11
+ date: 2019-04-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: actionpack
@@ -170,14 +170,14 @@ dependencies:
170
170
  requirements:
171
171
  - - "~>"
172
172
  - !ruby/object:Gem::Version
173
- version: '0.5'
173
+ version: '0.6'
174
174
  type: :development
175
175
  prerelease: false
176
176
  version_requirements: !ruby/object:Gem::Requirement
177
177
  requirements:
178
178
  - - "~>"
179
179
  - !ruby/object:Gem::Version
180
- version: '0.5'
180
+ version: '0.6'
181
181
  description:
182
182
  email:
183
183
  - andrew@gitlab.com
@@ -202,7 +202,6 @@ files:
202
202
  - lib/labkit/logging.rb
203
203
  - lib/labkit/logging/sanitizer.rb
204
204
  - lib/labkit/tracing.rb
205
- - lib/labkit/tracing/common.rb
206
205
  - lib/labkit/tracing/factory.rb
207
206
  - lib/labkit/tracing/grpc_interceptor.rb
208
207
  - lib/labkit/tracing/jaeger_factory.rb
@@ -215,6 +214,7 @@ files:
215
214
  - lib/labkit/tracing/sidekiq/client_middleware.rb
216
215
  - lib/labkit/tracing/sidekiq/server_middleware.rb
217
216
  - lib/labkit/tracing/sidekiq/sidekiq_common.rb
217
+ - lib/labkit/tracing/tracing_utils.rb
218
218
  homepage: http://about.gitlab.com
219
219
  licenses:
220
220
  - MIT
@@ -234,7 +234,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
234
234
  - !ruby/object:Gem::Version
235
235
  version: '0'
236
236
  requirements: []
237
- rubygems_version: 3.0.1
237
+ rubygems_version: 3.0.3
238
238
  signing_key:
239
239
  specification_version: 4
240
240
  summary: Instrumentation for GitLab