gitlab-labkit 0.13.0 → 0.13.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/.gitlab-ci.yml +13 -4
- data/.ruby-version +1 -1
- data/gitlab-labkit.gemspec +2 -1
- data/lib/labkit/context.rb +12 -1
- data/lib/labkit/logging/grpc/server_interceptor.rb +1 -0
- data/lib/labkit/logging/sanitizer.rb +8 -0
- data/lib/labkit/tracing.rb +6 -0
- data/lib/labkit/tracing/jaeger_factory.rb +4 -1
- data/lib/labkit/tracing/rails/active_record/sql_instrumenter.rb +2 -1
- data/lib/labkit/tracing/tracing_utils.rb +1 -1
- metadata +18 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 386875226d2cd983130f209da6204b633bc564dc7cdf749e4fd51aeb27ea44b7
|
4
|
+
data.tar.gz: b07771c72a4dc8385bba052ac9524dde00cce55023ad9c327db040535faeed31
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 73dcbe4d30d4706da4299dce292b7cd7271be8c10ab555fa4bbd46c53f3cdbb2d47e1c92743f4f914a95b78d3035d43e38003344f7afc399b5507dab84690bb1
|
7
|
+
data.tar.gz: 571c2df46e971b9696c5e23b5bdba9ab6df56d8253e998fa9a8797b2ebfb4d0e1b2371ac1626fd8e02d11641b17fb5270e23a7c927e28fddf03b17f4b3b21e7a
|
data/.gitignore
CHANGED
data/.gitlab-ci.yml
CHANGED
@@ -1,3 +1,12 @@
|
|
1
|
+
workflow:
|
2
|
+
rules:
|
3
|
+
# For merge requests, create a pipeline.
|
4
|
+
- if: '$CI_MERGE_REQUEST_IID'
|
5
|
+
# For `master` branch, create a pipeline (this includes on schedules, pushes, merges, etc.).
|
6
|
+
- if: '$CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH'
|
7
|
+
# For tags, create a pipeline.
|
8
|
+
- if: '$CI_COMMIT_TAG'
|
9
|
+
|
1
10
|
.test_template: &test_definition
|
2
11
|
stage: test
|
3
12
|
script:
|
@@ -5,6 +14,10 @@
|
|
5
14
|
- bundle install
|
6
15
|
- bundle exec rake verify build install
|
7
16
|
|
17
|
+
test:2.7:
|
18
|
+
image: ruby:2.7
|
19
|
+
<<: *test_definition
|
20
|
+
|
8
21
|
test:2.6:
|
9
22
|
image: ruby:2.6
|
10
23
|
<<: *test_definition
|
@@ -13,10 +26,6 @@ test:2.5:
|
|
13
26
|
image: ruby:2.5
|
14
27
|
<<: *test_definition
|
15
28
|
|
16
|
-
test:2.4:
|
17
|
-
image: ruby:2.4
|
18
|
-
<<: *test_definition
|
19
|
-
|
20
29
|
deploy:
|
21
30
|
stage: deploy
|
22
31
|
script:
|
data/.ruby-version
CHANGED
@@ -1 +1 @@
|
|
1
|
-
2.
|
1
|
+
2.7.2
|
data/gitlab-labkit.gemspec
CHANGED
@@ -22,9 +22,10 @@ Gem::Specification.new do |spec|
|
|
22
22
|
spec.add_runtime_dependency "actionpack", ">= 5.0.0", "< 6.1.0"
|
23
23
|
spec.add_runtime_dependency "activesupport", ">= 5.0.0", "< 6.1.0"
|
24
24
|
spec.add_runtime_dependency "grpc", "~> 1.19" # Be sure to update the "grpc-tools" dev_depenency too
|
25
|
-
spec.add_runtime_dependency "jaeger-client", "~>
|
25
|
+
spec.add_runtime_dependency "jaeger-client", "~> 1.1"
|
26
26
|
spec.add_runtime_dependency "opentracing", "~> 0.4"
|
27
27
|
spec.add_runtime_dependency "redis", ">3.0.0", "<5.0.0"
|
28
|
+
spec.add_runtime_dependency "gitlab-pg_query", "~> 1.3"
|
28
29
|
|
29
30
|
# Please maintain alphabetical order for dev dependencies
|
30
31
|
spec.add_development_dependency "grpc-tools", "~> 1.19"
|
data/lib/labkit/context.rb
CHANGED
@@ -21,8 +21,9 @@ module Labkit
|
|
21
21
|
LOG_KEY = "meta"
|
22
22
|
CORRELATION_ID_KEY = "correlation_id"
|
23
23
|
RAW_KEYS = [CORRELATION_ID_KEY].freeze
|
24
|
+
HEADER_PREFIX = "X-Gitlab-"
|
24
25
|
KNOWN_KEYS = %w[user project root_namespace subscription_plan caller_id
|
25
|
-
related_class feature_category].freeze
|
26
|
+
remote_ip related_class feature_category].freeze
|
26
27
|
|
27
28
|
class << self
|
28
29
|
def with_context(attributes = {})
|
@@ -67,6 +68,10 @@ module Labkit
|
|
67
68
|
@known_log_keys ||= (KNOWN_KEYS.map(&method(:log_key)) + RAW_KEYS).freeze
|
68
69
|
end
|
69
70
|
|
71
|
+
def header_name(name)
|
72
|
+
HEADER_PREFIX + log_key(name).titlecase(keep_id_suffix: true).gsub(/\W/, "-")
|
73
|
+
end
|
74
|
+
|
70
75
|
private
|
71
76
|
|
72
77
|
def contexts
|
@@ -95,6 +100,12 @@ module Labkit
|
|
95
100
|
data[CORRELATION_ID_KEY]
|
96
101
|
end
|
97
102
|
|
103
|
+
def to_headers
|
104
|
+
to_h.except(CORRELATION_ID_KEY).transform_keys do |key|
|
105
|
+
self.class.header_name(key)
|
106
|
+
end
|
107
|
+
end
|
108
|
+
|
98
109
|
protected
|
99
110
|
|
100
111
|
def assign_attributes(attributes)
|
@@ -67,6 +67,7 @@ module Labkit
|
|
67
67
|
ensure
|
68
68
|
service_name, method_name = rpc_split(method)
|
69
69
|
message = @default_tags.merge(
|
70
|
+
'grpc.start_time': start.utc.rfc3339,
|
70
71
|
'grpc.time_ms': ((Time.now - start) * 1000.0).truncate(3),
|
71
72
|
'grpc.code': CODE_STRINGS.fetch(code, code.to_s),
|
72
73
|
'grpc.method': method_name,
|
@@ -1,5 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
require "pg_query"
|
4
|
+
|
3
5
|
module Labkit
|
4
6
|
module Logging
|
5
7
|
# Sanitizer provides log message sanitization, removing
|
@@ -22,6 +24,12 @@ module Labkit
|
|
22
24
|
content
|
23
25
|
end
|
24
26
|
|
27
|
+
def self.sanitize_sql(sql)
|
28
|
+
PgQuery.normalize(sql)
|
29
|
+
rescue PgQuery::ParseError
|
30
|
+
""
|
31
|
+
end
|
32
|
+
|
25
33
|
# Ensures that URLS are sanitized to hide credentials
|
26
34
|
def self.mask_url(url)
|
27
35
|
url = url.to_s.strip
|
data/lib/labkit/tracing.rb
CHANGED
@@ -28,6 +28,12 @@ module Labkit
|
|
28
28
|
ENV["GITLAB_TRACING_URL"]
|
29
29
|
end
|
30
30
|
|
31
|
+
# Check if the current request is being traced.
|
32
|
+
def self.sampled?
|
33
|
+
context = OpenTracing.active_span&.context
|
34
|
+
context && context.respond_to?(:sampled?) && context.sampled?
|
35
|
+
end
|
36
|
+
|
31
37
|
def self.stacktrace_operations
|
32
38
|
@stacktrace_operations ||= Set.new(ENV["GITLAB_TRACING_INCLUDE_STACKTRACE"].to_s.split(",").map(&:strip))
|
33
39
|
end
|
@@ -19,6 +19,9 @@ module Labkit
|
|
19
19
|
FLUSH_INTERVAL = 5
|
20
20
|
|
21
21
|
def self.create_tracer(service_name, options)
|
22
|
+
# The service_name parameter from GITLAB_TRACING takes precedence over the application one
|
23
|
+
service_name = options[:service_name] if options[:service_name]
|
24
|
+
|
22
25
|
kwargs = {
|
23
26
|
service_name: service_name,
|
24
27
|
sampler: get_sampler(options[:sampler], options[:sampler_param]),
|
@@ -34,7 +37,7 @@ module Labkit
|
|
34
37
|
warn message
|
35
38
|
end
|
36
39
|
|
37
|
-
Jaeger::Client.build(kwargs)
|
40
|
+
Jaeger::Client.build(**kwargs)
|
38
41
|
end
|
39
42
|
|
40
43
|
def self.get_sampler(sampler_type, sampler_param)
|
@@ -14,13 +14,14 @@ module Labkit
|
|
14
14
|
end
|
15
15
|
|
16
16
|
def tags(payload)
|
17
|
+
sql = Labkit::Logging::Sanitizer.sanitize_sql(payload[:sql]) if Labkit::Tracing.sampled? && payload[:sql]
|
17
18
|
{
|
18
19
|
"component" => COMPONENT_TAG,
|
19
20
|
"span.kind" => "client",
|
20
21
|
"db.type" => "sql",
|
21
22
|
"db.connection_id" => payload[:connection_id],
|
22
23
|
"db.cached" => payload[:cached] || false,
|
23
|
-
"db.statement" =>
|
24
|
+
"db.statement" => sql,
|
24
25
|
}
|
25
26
|
end
|
26
27
|
end
|
@@ -49,7 +49,7 @@ module Labkit
|
|
49
49
|
# Add exception logging to a span
|
50
50
|
def self.log_exception_on_span(span, exception)
|
51
51
|
span.set_tag("error", true)
|
52
|
-
span.log_kv(kv_tags_for_exception(exception))
|
52
|
+
span.log_kv(**kv_tags_for_exception(exception))
|
53
53
|
end
|
54
54
|
|
55
55
|
# Generate key-value tags for an exception
|
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.13.
|
4
|
+
version: 0.13.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Andrew Newdigate
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-
|
11
|
+
date: 2020-12-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: actionpack
|
@@ -70,14 +70,14 @@ dependencies:
|
|
70
70
|
requirements:
|
71
71
|
- - "~>"
|
72
72
|
- !ruby/object:Gem::Version
|
73
|
-
version: '
|
73
|
+
version: '1.1'
|
74
74
|
type: :runtime
|
75
75
|
prerelease: false
|
76
76
|
version_requirements: !ruby/object:Gem::Requirement
|
77
77
|
requirements:
|
78
78
|
- - "~>"
|
79
79
|
- !ruby/object:Gem::Version
|
80
|
-
version: '
|
80
|
+
version: '1.1'
|
81
81
|
- !ruby/object:Gem::Dependency
|
82
82
|
name: opentracing
|
83
83
|
requirement: !ruby/object:Gem::Requirement
|
@@ -112,6 +112,20 @@ dependencies:
|
|
112
112
|
- - "<"
|
113
113
|
- !ruby/object:Gem::Version
|
114
114
|
version: 5.0.0
|
115
|
+
- !ruby/object:Gem::Dependency
|
116
|
+
name: gitlab-pg_query
|
117
|
+
requirement: !ruby/object:Gem::Requirement
|
118
|
+
requirements:
|
119
|
+
- - "~>"
|
120
|
+
- !ruby/object:Gem::Version
|
121
|
+
version: '1.3'
|
122
|
+
type: :runtime
|
123
|
+
prerelease: false
|
124
|
+
version_requirements: !ruby/object:Gem::Requirement
|
125
|
+
requirements:
|
126
|
+
- - "~>"
|
127
|
+
- !ruby/object:Gem::Version
|
128
|
+
version: '1.3'
|
115
129
|
- !ruby/object:Gem::Dependency
|
116
130
|
name: grpc-tools
|
117
131
|
requirement: !ruby/object:Gem::Requirement
|