gitlab-labkit 0.31.0 → 0.32.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/gitlab-labkit.gemspec +1 -1
- data/lib/labkit/context.rb +0 -11
- data/lib/labkit/logging/json_logger.rb +15 -1
- data/lib/labkit/middleware/rack.rb +17 -2
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: dd0d698d4683c94ad8c37047253ab83f4504b17a7a3162a822660b1e42512d3e
|
4
|
+
data.tar.gz: dedef03b41c33466eeec83483b82bb20e9e30987493b104cda3c14a6b2b55003
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e7f5b41fc2d7b844d0b553a206136824de6f9a470e30e96281191590cc4a879eb7243e3fa6deb70452b79959a0536c77a4d2d6fbd7e7af225b076f2c72e6effc
|
7
|
+
data.tar.gz: 6bc549eb4aecdcb9ed93b6309fd7cbec8add69b816a19a25eb06be7f1ee7670d2a6f82e9555758b6fa567ce4b4860a7fd374386ea8a679d3bc14785ceaef4426
|
data/gitlab-labkit.gemspec
CHANGED
@@ -29,7 +29,7 @@ Gem::Specification.new do |spec|
|
|
29
29
|
|
30
30
|
# Please maintain alphabetical order for dev dependencies
|
31
31
|
spec.add_development_dependency "excon", "~> 0.78.1"
|
32
|
-
spec.add_development_dependency "faraday", "~> 1.
|
32
|
+
spec.add_development_dependency "faraday", "~> 1.0"
|
33
33
|
spec.add_development_dependency "gitlab-dangerfiles", "~> 2.11.0"
|
34
34
|
spec.add_development_dependency "gitlab-styles", "~> 6.2.0"
|
35
35
|
spec.add_development_dependency "grpc-tools", ">= 1.37"
|
data/lib/labkit/context.rb
CHANGED
@@ -26,7 +26,6 @@ module Labkit
|
|
26
26
|
LOG_KEY = "meta"
|
27
27
|
CORRELATION_ID_KEY = "correlation_id"
|
28
28
|
RAW_KEYS = [CORRELATION_ID_KEY].freeze
|
29
|
-
HEADER_PREFIX = "X-Gitlab-"
|
30
29
|
|
31
30
|
class << self
|
32
31
|
def with_context(attributes = {})
|
@@ -71,10 +70,6 @@ module Labkit
|
|
71
70
|
@known_log_keys ||= (KNOWN_KEYS.map(&method(:log_key)) + RAW_KEYS).freeze
|
72
71
|
end
|
73
72
|
|
74
|
-
def header_name(name)
|
75
|
-
HEADER_PREFIX + log_key(name).titlecase(keep_id_suffix: true).gsub(/\W/, "-")
|
76
|
-
end
|
77
|
-
|
78
73
|
private
|
79
74
|
|
80
75
|
def contexts
|
@@ -103,12 +98,6 @@ module Labkit
|
|
103
98
|
data[CORRELATION_ID_KEY]
|
104
99
|
end
|
105
100
|
|
106
|
-
def to_headers
|
107
|
-
to_h.except(CORRELATION_ID_KEY).transform_keys do |key|
|
108
|
-
self.class.header_name(key)
|
109
|
-
end
|
110
|
-
end
|
111
|
-
|
112
101
|
def get_attribute(attribute)
|
113
102
|
raw = call_or_value(data[log_key(attribute)])
|
114
103
|
|
@@ -23,6 +23,15 @@ module Labkit
|
|
23
23
|
ENV.fetch("GITLAB_LOG_LEVEL", fallback)
|
24
24
|
end
|
25
25
|
|
26
|
+
def self.exclude_context!
|
27
|
+
@exclude_context = true
|
28
|
+
self
|
29
|
+
end
|
30
|
+
|
31
|
+
def self.exclude_context?
|
32
|
+
!!@exclude_context
|
33
|
+
end
|
34
|
+
|
26
35
|
def initialize(path, level: JsonLogger.log_level)
|
27
36
|
super
|
28
37
|
end
|
@@ -31,7 +40,12 @@ module Labkit
|
|
31
40
|
data = default_attributes
|
32
41
|
data[:severity] = severity
|
33
42
|
data[:time] = timestamp.utc.iso8601(3)
|
34
|
-
|
43
|
+
|
44
|
+
if self.class.exclude_context?
|
45
|
+
data[Labkit::Correlation::CorrelationId::LOG_KEY] = Labkit::Correlation::CorrelationId.current_id
|
46
|
+
else
|
47
|
+
data.merge!(Labkit::Context.current.to_h)
|
48
|
+
end
|
35
49
|
|
36
50
|
case message
|
37
51
|
when String
|
@@ -1,9 +1,12 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require "action_dispatch"
|
4
|
+
require "json"
|
4
5
|
|
5
6
|
module Labkit
|
6
7
|
module Middleware
|
8
|
+
HEADER = "X-Gitlab-Meta"
|
9
|
+
|
7
10
|
# This is a rack middleware to be inserted in GitLab-rails
|
8
11
|
# It makes sure that there's always a root context containing the correlation
|
9
12
|
# id.
|
@@ -15,8 +18,12 @@ module Labkit
|
|
15
18
|
end
|
16
19
|
|
17
20
|
def call(env)
|
18
|
-
Labkit::Context.with_context(Labkit::Context::CORRELATION_ID_KEY => correlation_id(env)) do
|
19
|
-
@app.call(env)
|
21
|
+
Labkit::Context.with_context(Labkit::Context::CORRELATION_ID_KEY => correlation_id(env)) do |context|
|
22
|
+
status, headers, response = @app.call(env)
|
23
|
+
|
24
|
+
headers[HEADER] = context_to_json(context)
|
25
|
+
|
26
|
+
[status, headers, response]
|
20
27
|
end
|
21
28
|
end
|
22
29
|
|
@@ -29,6 +36,14 @@ module Labkit
|
|
29
36
|
def request(env)
|
30
37
|
ActionDispatch::Request.new(env)
|
31
38
|
end
|
39
|
+
|
40
|
+
def context_to_json(context)
|
41
|
+
context
|
42
|
+
.to_h
|
43
|
+
.transform_keys { |k| k.delete_prefix("meta.") }
|
44
|
+
.merge("version" => "1")
|
45
|
+
.to_json
|
46
|
+
end
|
32
47
|
end
|
33
48
|
end
|
34
49
|
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.32.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: 2023-
|
11
|
+
date: 2023-04-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: actionpack
|
@@ -146,14 +146,14 @@ dependencies:
|
|
146
146
|
requirements:
|
147
147
|
- - "~>"
|
148
148
|
- !ruby/object:Gem::Version
|
149
|
-
version: 1.
|
149
|
+
version: '1.0'
|
150
150
|
type: :development
|
151
151
|
prerelease: false
|
152
152
|
version_requirements: !ruby/object:Gem::Requirement
|
153
153
|
requirements:
|
154
154
|
- - "~>"
|
155
155
|
- !ruby/object:Gem::Version
|
156
|
-
version: 1.
|
156
|
+
version: '1.0'
|
157
157
|
- !ruby/object:Gem::Dependency
|
158
158
|
name: gitlab-dangerfiles
|
159
159
|
requirement: !ruby/object:Gem::Requirement
|