opentracing-instrumentation 0.1.16 → 0.1.17
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/GEM_VERSION +1 -1
- data/Gemfile.lock +1 -1
- data/lib/opentracing/instrumentation/common.rb +2 -0
- data/lib/opentracing/instrumentation/common/operation_name_builder.rb +23 -0
- data/lib/opentracing/instrumentation/sidekiq/client_middleware.rb +35 -10
- data/lib/opentracing/instrumentation/sidekiq/job_tagger.rb +5 -5
- data/lib/opentracing/instrumentation/sidekiq/server_middleware.rb +33 -7
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9ca5229070a9ceefdba01deafe855a8c506018111a073bc627f52b77e67ec07b
|
4
|
+
data.tar.gz: 7afb446993601e8fa9df04c0fca0537495b7125724449c6eab721a45c5e7e5cc
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2ff9411175de0c6b489c05da90e068cc85c4ba177f17bea72658b51ec6258935fdc0b264e4577d64a0ecfc04cb670085ea438c0ff04485f4e97bd3de9008d902
|
7
|
+
data.tar.gz: 1058ed6b1b347a9a596a8e76e14a3822b51cf6b0911fe05f03933dee533db10cd3fd138f3d659523ee907c5cf8b394ef1251bb1332a6705ad306c3e50e3fb297
|
data/GEM_VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.1.
|
1
|
+
0.1.17
|
data/Gemfile.lock
CHANGED
@@ -0,0 +1,23 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module OpenTracing
|
4
|
+
module Instrumentation
|
5
|
+
module Common
|
6
|
+
# Build operation name by template and tags
|
7
|
+
class OperationNameBuilder
|
8
|
+
def initialize(operation_name_template:)
|
9
|
+
@operation_name_template = operation_name_template
|
10
|
+
end
|
11
|
+
|
12
|
+
# build operation name with tags
|
13
|
+
def build(tags)
|
14
|
+
format(operation_name_template, **tags)
|
15
|
+
end
|
16
|
+
|
17
|
+
private
|
18
|
+
|
19
|
+
attr_reader :operation_name_template
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -7,41 +7,68 @@ module OpenTracing
|
|
7
7
|
class ClientMiddleware
|
8
8
|
extend Forwardable
|
9
9
|
|
10
|
-
DEFAULT_SPAN_NAME = 'sidekiq_enqueue'
|
11
10
|
DEFAULT_SPAN_KIND = 'producer'
|
12
11
|
|
12
|
+
DEFAULT_OPERATION_NAME_TEMPLATE = \
|
13
|
+
'sidekiq_enqueue(%<sidekiq.class>s)'
|
14
|
+
DEFAULT_OPERATION_NAME_BUILDER = \
|
15
|
+
Common::OperationNameBuilder.new(
|
16
|
+
operation_name_template: DEFAULT_OPERATION_NAME_TEMPLATE,
|
17
|
+
)
|
18
|
+
|
13
19
|
attr_reader :tracer
|
14
20
|
attr_reader :tagger
|
15
21
|
attr_reader :error_writter
|
22
|
+
attr_reader :logger
|
16
23
|
attr_reader :span_kind
|
17
|
-
attr_reader :
|
24
|
+
attr_reader :operation_name_builder
|
18
25
|
|
26
|
+
# rubocop:disable Metrics/ParameterLists
|
19
27
|
def initialize(
|
20
28
|
tracer: OpenTracing.global_tracer,
|
21
29
|
tagger: JobTagger.new,
|
22
30
|
error_writter: Common::ErrorWriter.new,
|
31
|
+
logger: nil,
|
23
32
|
span_kind: DEFAULT_SPAN_KIND,
|
24
|
-
|
33
|
+
operation_name_builder: DEFAULT_OPERATION_NAME_BUILDER
|
25
34
|
)
|
26
35
|
@tracer = tracer
|
27
36
|
@tagger = tagger
|
28
37
|
@error_writter = error_writter
|
38
|
+
@logger = logger
|
29
39
|
@span_kind = span_kind
|
30
|
-
@
|
40
|
+
@operation_name_builder = operation_name_builder
|
31
41
|
end
|
42
|
+
# rubocop:enable Metrics/ParameterLists
|
32
43
|
|
33
44
|
def call(_worker_class, job, _queue, _redis_pool)
|
34
|
-
scope =
|
45
|
+
scope = safe_start_scope(job)
|
35
46
|
inject(scope.span.context, job)
|
36
47
|
log(scope.span, job) do
|
37
48
|
yield
|
38
49
|
end
|
39
50
|
ensure
|
40
|
-
scope
|
51
|
+
safe_close_scope(scope)
|
41
52
|
end
|
42
53
|
|
43
54
|
private
|
44
55
|
|
56
|
+
def safe_start_scope(job)
|
57
|
+
tags = build_tags(job)
|
58
|
+
operation_name = operation_name_builder.build(tags)
|
59
|
+
tracer.start_active_span(operation_name, tags: tags)
|
60
|
+
rescue StandardError => e
|
61
|
+
logger&.error(e)
|
62
|
+
end
|
63
|
+
|
64
|
+
def safe_close_scope(scope)
|
65
|
+
return unless scope
|
66
|
+
|
67
|
+
scope.close
|
68
|
+
rescue StandardError => e
|
69
|
+
logger&.error(e)
|
70
|
+
end
|
71
|
+
|
45
72
|
def log(span, job)
|
46
73
|
tagger.write_args_log(span, job['jid'], job['args'])
|
47
74
|
|
@@ -51,10 +78,8 @@ module OpenTracing
|
|
51
78
|
raise
|
52
79
|
end
|
53
80
|
|
54
|
-
def
|
55
|
-
|
56
|
-
tags: tagger.build_tags(job, span_kind),
|
57
|
-
}
|
81
|
+
def build_tags(job)
|
82
|
+
tagger.build_tags(job, span_kind)
|
58
83
|
end
|
59
84
|
|
60
85
|
def inject(span_context, carrier)
|
@@ -30,11 +30,11 @@ module OpenTracing
|
|
30
30
|
# build tags from job data and static attributes
|
31
31
|
def build_tags(job, span_kind)
|
32
32
|
{
|
33
|
-
|
34
|
-
'span.kind'
|
35
|
-
'sidekiq.queue'
|
36
|
-
'sidekiq.class'
|
37
|
-
'sidekiq.retry'
|
33
|
+
component: component,
|
34
|
+
'span.kind': span_kind,
|
35
|
+
'sidekiq.queue': job['queue'],
|
36
|
+
'sidekiq.class': job['class'],
|
37
|
+
'sidekiq.retry': job['retry'],
|
38
38
|
}
|
39
39
|
end
|
40
40
|
|
@@ -9,41 +9,68 @@ module OpenTracing
|
|
9
9
|
class ServerMiddleware
|
10
10
|
extend Forwardable
|
11
11
|
|
12
|
-
DEFAULT_SPAN_NAME = 'sidekiq_perform'
|
13
12
|
DEFAULT_SPAN_KIND = 'consumer'
|
14
13
|
|
14
|
+
DEFAULT_OPERATION_NAME_TEMPLATE = \
|
15
|
+
'sidekiq_perform(%<sidekiq.class>s)'
|
16
|
+
DEFAULT_OPERATION_NAME_BUILDER = \
|
17
|
+
Common::OperationNameBuilder.new(
|
18
|
+
operation_name_template: DEFAULT_OPERATION_NAME_TEMPLATE,
|
19
|
+
)
|
20
|
+
|
15
21
|
attr_reader :tracer
|
16
22
|
attr_reader :tagger
|
17
23
|
attr_reader :error_writter
|
24
|
+
attr_reader :logger
|
18
25
|
attr_reader :span_kind
|
19
|
-
attr_reader :
|
26
|
+
attr_reader :operation_name_builder
|
20
27
|
|
28
|
+
# rubocop:disable Metrics/ParameterLists
|
21
29
|
def initialize(
|
22
30
|
tracer: OpenTracing.global_tracer,
|
23
31
|
tagger: JobTagger.new,
|
24
32
|
error_writter: Common::ErrorWriter.new,
|
33
|
+
logger: nil,
|
25
34
|
span_kind: DEFAULT_SPAN_KIND,
|
26
|
-
|
35
|
+
operation_name_builder: DEFAULT_OPERATION_NAME_BUILDER
|
27
36
|
)
|
28
37
|
@tracer = tracer
|
29
38
|
@tagger = tagger
|
30
39
|
@error_writter = error_writter
|
40
|
+
@logger = logger
|
31
41
|
@span_kind = span_kind
|
32
|
-
@
|
42
|
+
@operation_name_builder = operation_name_builder
|
33
43
|
end
|
44
|
+
# rubocop:enable Metrics/ParameterLists
|
34
45
|
|
35
46
|
def call(_worker, job, _queue)
|
36
|
-
scope =
|
47
|
+
scope = safe_start_scope(job)
|
37
48
|
|
38
49
|
log(scope.span, job) do
|
39
50
|
yield
|
40
51
|
end
|
41
52
|
ensure
|
42
|
-
scope
|
53
|
+
scope&.close
|
43
54
|
end
|
44
55
|
|
45
56
|
private
|
46
57
|
|
58
|
+
def safe_start_scope(job)
|
59
|
+
tags = tagger.build_tags(job, span_kind)
|
60
|
+
operation_name = operation_name_builder.build(tags)
|
61
|
+
tracer.start_active_span(operation_name, tags: tags, **build_span_args(job))
|
62
|
+
rescue StandardError => e
|
63
|
+
logger&.error(e)
|
64
|
+
end
|
65
|
+
|
66
|
+
def safe_close_scope(scope)
|
67
|
+
return unless socpe
|
68
|
+
|
69
|
+
scope.close
|
70
|
+
rescue StandardError => e
|
71
|
+
logger&.error(e)
|
72
|
+
end
|
73
|
+
|
47
74
|
def log(span, job)
|
48
75
|
tagger.write_args_log(span, job['jid'], job['args'])
|
49
76
|
|
@@ -56,7 +83,6 @@ module OpenTracing
|
|
56
83
|
def build_span_args(job)
|
57
84
|
{
|
58
85
|
references: extract_references(job),
|
59
|
-
tags: tagger.build_tags(job, span_kind),
|
60
86
|
}
|
61
87
|
end
|
62
88
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: opentracing-instrumentation
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.17
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Fedorenko Dmitrij
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-04-
|
11
|
+
date: 2020-04-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: json
|
@@ -284,6 +284,7 @@ files:
|
|
284
284
|
- lib/opentracing/instrumentation/bunny/regexp_routing_key_sanitazer.rb
|
285
285
|
- lib/opentracing/instrumentation/common.rb
|
286
286
|
- lib/opentracing/instrumentation/common/error_writer.rb
|
287
|
+
- lib/opentracing/instrumentation/common/operation_name_builder.rb
|
287
288
|
- lib/opentracing/instrumentation/faraday.rb
|
288
289
|
- lib/opentracing/instrumentation/faraday/response_logger.rb
|
289
290
|
- lib/opentracing/instrumentation/faraday/trace_middleware.rb
|