gitlab-labkit 0.1.2 → 0.2.0
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 +4 -4
- data/gitlab-labkit.gemspec +1 -1
- data/lib/labkit/tracing/grpc_interceptor.rb +1 -2
- data/lib/labkit/tracing/rack_middleware.rb +2 -4
- data/lib/labkit/tracing/rails/rails_common.rb +1 -2
- data/lib/labkit/tracing/sidekiq/client_middleware.rb +2 -3
- data/lib/labkit/tracing/sidekiq/server_middleware.rb +2 -2
- data/lib/labkit/tracing/sidekiq/sidekiq_common.rb +0 -2
- data/lib/labkit/tracing/{common.rb → tracing_utils.rb} +15 -10
- data/lib/labkit/tracing.rb +11 -1
- metadata +6 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a7e7afa0f2bf64760a144d433f5433532c1a08f1157f2ca46f180f13fead059b
|
4
|
+
data.tar.gz: 6647d722dc1ad3835001401ff13be3545649bbbc5847d664678422c3f3bab688
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1c2a10af3bb8968d523f62a40ef1597af6c26173b7b433c6ed7a1f2f613f76c02008653471dba139a82de7582e564d703da3b28b4bdc10f081c443dd0a41a07d
|
7
|
+
data.tar.gz: 5d38c2ef80073df95a0b3898e324ef7ac7b3e962bb72470833f4b1f0c1d28e64580c164fdcfca5d84f2f2e1579f3bd3b6211996205254be35631f5143787e07f
|
data/gitlab-labkit.gemspec
CHANGED
@@ -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.
|
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
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
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
|
@@ -4,14 +4,11 @@ require "opentracing"
|
|
4
4
|
|
5
5
|
module Labkit
|
6
6
|
module Tracing
|
7
|
-
#
|
8
|
-
|
9
|
-
|
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
|
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
|
-
|
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
|
-
|
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
|
-
|
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
|
{
|
data/lib/labkit/tracing.rb
CHANGED
@@ -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.
|
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-
|
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.
|
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.
|
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.
|
237
|
+
rubygems_version: 3.0.3
|
238
238
|
signing_key:
|
239
239
|
specification_version: 4
|
240
240
|
summary: Instrumentation for GitLab
|