gitlab-labkit 0.10.1 → 0.11.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: 2476531528be243ed0069feffe3bbfbc7d557556455616e7d4216aa686422409
4
- data.tar.gz: 43223820267f18725601573595ba607178788178b1922835becaf7c72d593b2f
3
+ metadata.gz: '079f4d5036a9fec36b5b6407aae14904afe2cf8e14805bd66e2bc4e7232fbf6a'
4
+ data.tar.gz: ba3f76216a9e26fd2208911ae51f147e94ffa3bb786922eec529f4188c35b91b
5
5
  SHA512:
6
- metadata.gz: 712fd95e6a754409e83a8b5ee690c1843b233794a33a7461dea2fdc84c49eb8e873c7298ee15087302c32b60faeca83fd3592a80e471640a3c80710fa094e54e
7
- data.tar.gz: e6d4d048caa06702bd47326574d105f32d9d5e7c27d3c619ac529e4cb35f671a7cfca92e1d9b6460a1b6080c90bc05306f2df17381ca6e104ad30a5171a22bb8
6
+ metadata.gz: 512596bceb4a8549af748a72e49286e3c1224ab1ae61d30f127685b70653fe30579c37d1091190cab19e244e016f5e2947b5892f51ba55b31651ccbc9e028706
7
+ data.tar.gz: de29c45094bafd62607471a8b0142ae3dffced97032d2a6b25c748a2a47347a5c815e5735d60985a98f6c43f3107ba901094ba814d1ff903d38c4f8ac6452b9b
@@ -28,6 +28,10 @@ module Labkit
28
28
  ENV["GITLAB_TRACING_URL"]
29
29
  end
30
30
 
31
+ def self.stacktrace_operations
32
+ @stacktrace_operations ||= Set.new(ENV["GITLAB_TRACING_INCLUDE_STACKTRACE"].to_s.split(",").map(&:strip))
33
+ end
34
+
31
35
  def self.tracing_url_enabled?
32
36
  enabled? && tracing_url_template.present?
33
37
  end
@@ -17,6 +17,8 @@ module Labkit
17
17
  scope = scope_stack.pop
18
18
  span = scope.span
19
19
 
20
+ Labkit::Tracing::TracingUtils.log_common_fields_on_span(span, span_name(payload))
21
+
20
22
  exception = payload[:exception]
21
23
  Labkit::Tracing::TracingUtils.log_exception_on_span(span, exception) if exception
22
24
 
@@ -12,9 +12,7 @@ module Labkit
12
12
  scope = tracer.start_active_span(operation_name, child_of: child_of, tags: tags)
13
13
  span = scope.span
14
14
 
15
- # Add correlation details to the span if we have them
16
- correlation_id = Labkit::Correlation::CorrelationId.current_id
17
- span.set_tag("correlation_id", correlation_id) if correlation_id
15
+ log_common_fields_on_span(span, operation_name)
18
16
 
19
17
  begin
20
18
  yield span
@@ -35,11 +33,19 @@ module Labkit
35
33
  def self.postnotify_span(operation_name, start_time, end_time, tags: nil, child_of: nil, exception: nil)
36
34
  span = OpenTracing.start_span(operation_name, start_time: start_time, tags: tags, child_of: child_of)
37
35
 
36
+ log_common_fields_on_span(span, operation_name)
38
37
  log_exception_on_span(span, exception) if exception
39
38
 
40
39
  span.finish(end_time: end_time)
41
40
  end
42
41
 
42
+ # Add common fields to a span
43
+ def self.log_common_fields_on_span(span, operation_name)
44
+ correlation_id = Labkit::Correlation::CorrelationId.current_id
45
+ span.set_tag("correlation_id", correlation_id) if correlation_id
46
+ span.log_kv(stack: caller.join('\n')) if include_stacktrace?(operation_name)
47
+ end
48
+
43
49
  # Add exception logging to a span
44
50
  def self.log_exception_on_span(span, exception)
45
51
  span.set_tag("error", true)
@@ -60,6 +66,14 @@ module Labkit
60
66
  { :"event" => "error", :"error.kind" => exception.class.to_s, :"error.object" => Labkit::Logging::Sanitizer.sanitize_field(exception.to_s) }
61
67
  end
62
68
  end
69
+
70
+ def self.include_stacktrace?(operation_name)
71
+ @include_stacktrace ||= Hash.new do |result, name|
72
+ result[name] = Tracing.stacktrace_operations.any? { |stacktrace_operation| name.starts_with?(stacktrace_operation) }
73
+ end
74
+
75
+ @include_stacktrace[operation_name]
76
+ end
63
77
  end
64
78
  end
65
79
  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.10.1
4
+ version: 0.11.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: 2020-03-05 00:00:00.000000000 Z
11
+ date: 2020-03-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: actionpack