opentelemetry-propagator-jaeger 0.16.0 → 0.19.1

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: e309829185d53b310beb404e6db7bf7c50bf1b52638e0c2abe4316d569bcf79d
4
- data.tar.gz: 1c70d8fc82e5833d8c93554662536b5b7f017d5e38367c19dd2ea9fdb07aa42e
3
+ metadata.gz: 7a654d390032141e29a85ed30947ca5fe8d849107716376205ea3c268c49f2f6
4
+ data.tar.gz: 158c5925352505f218cd4b5464b238eac2691dd268c9c59e255cabe43638485b
5
5
  SHA512:
6
- metadata.gz: dab712ae65175d5b4024e0879ba8bcc1ff0403af73209f7596cf05994d5b8f4e868617ac22384cb75cfc11d2469f01bad51e3f4dd340dd307c1010ff03c3ca3e
7
- data.tar.gz: e607b7cd32db1fa516452084faaa9acf920a858c2d13c879ea883e86b8157b72af4ac8e901a07fbc863d26ddeb1ee58201ac6e8880ecc29dd44fef179f680c79
6
+ metadata.gz: 17e1a8f17565ba610f848e63209af14a5c8d3a3e9c17559c90709a0f790a84b588118492bf0a44336ce57bb795af8a0345de8987e20d782e2a1f9d596df13a6c
7
+ data.tar.gz: 369d618f1efeb8d6855f14c3c66d67f11a0472667c67e2ea5036808651fb99761771f3499ed71fb08eba8a6f6d083bb5c78ec5af7539f2f142dbfa127eec9a63
data/CHANGELOG.md CHANGED
@@ -1,5 +1,28 @@
1
1
  # Release History: opentelemetry-propagator-jaeger
2
2
 
3
+ ### v0.19.1 / 2021-08-12
4
+
5
+ * (No significant changes)
6
+
7
+ ### v0.19.0 / 2021-06-23
8
+
9
+ * BREAKING CHANGE: Refactor Baggage to remove Noop*
10
+
11
+ * ADDED: Add Tracer.non_recording_span to API
12
+ * FIXED: Refactor Baggage to remove Noop*
13
+
14
+ ### v0.18.0 / 2021-05-21
15
+
16
+ * ADDED: Updated API depedency for 1.0.0.rc1
17
+
18
+ ### v0.17.0 / 2021-04-22
19
+
20
+ * BREAKING CHANGE: Replace TextMapInjector/TextMapExtractor pairs with a TextMapPropagator.
21
+
22
+ [Check the propagator documentation](https://open-telemetry.github.io/opentelemetry-ruby/) for the new usage.
23
+
24
+ * FIXED: Refactor propagators to add #fields
25
+
3
26
  ### v0.16.0 / 2021-03-17
4
27
 
5
28
  * Initial release.
data/README.md CHANGED
@@ -1,9 +1,9 @@
1
1
  # opentelemetry-propagator-jaeger
2
2
 
3
- The `opentelemetry-propagator-jaeger` gem contains injectors and extractors for the
4
- [Jaeger native propagation format][jaeger-spec] They can be used in
5
- conjunction with each other as well as with injectors and extractors for
6
- other formats to support a variety of context propagation scenarios.
3
+ The `opentelemetry-propagator-jaeger` gem contains a propagator for the
4
+ [Jaeger native propagation format][jaeger-spec] This can be used on its
5
+ own as well as with propagators for other formats to support a variety
6
+ of context propagation scenarios.
7
7
 
8
8
  ## What is OpenTelemetry?
9
9
 
@@ -4,8 +4,7 @@
4
4
  #
5
5
  # SPDX-License-Identifier: Apache-2.0
6
6
 
7
- require_relative './jaeger/text_map_extractor'
8
- require_relative './jaeger/text_map_injector'
7
+ require_relative './jaeger/text_map_propagator'
9
8
 
10
9
  # OpenTelemetry is an open source observability framework, providing a
11
10
  # general-purpose API, SDK, and related tools required for the instrumentation
@@ -23,28 +22,14 @@ module OpenTelemetry
23
22
  DEBUG_CONTEXT_KEY = Context.create_key('jaeger-debug-key')
24
23
  private_constant :DEBUG_CONTEXT_KEY
25
24
 
26
- TEXT_MAP_EXTRACTOR = TextMapExtractor.new
27
- TEXT_MAP_INJECTOR = TextMapInjector.new
25
+ TEXT_MAP_PROPAGATOR = TextMapPropagator.new
28
26
 
29
- private_constant :TEXT_MAP_INJECTOR, :TEXT_MAP_EXTRACTOR
27
+ private_constant :TEXT_MAP_PROPAGATOR
30
28
 
31
- IDENTITY_KEY = 'uber-trace-id'
32
- DEFAULT_FLAG_BIT = 0x0
33
- SAMPLED_FLAG_BIT = 0x01
34
- DEBUG_FLAG_BIT = 0x02
35
-
36
- private_constant :IDENTITY_KEY, :DEFAULT_FLAG_BIT, :SAMPLED_FLAG_BIT, :DEBUG_FLAG_BIT
37
-
38
- # Returns an extractor that extracts context in the Jaeger single header
39
- # format
40
- def text_map_injector
41
- TEXT_MAP_INJECTOR
42
- end
43
-
44
- # Returns an injector that injects context in the Jaeger single header
45
- # format
46
- def text_map_extractor
47
- TEXT_MAP_EXTRACTOR
29
+ # Returns a text map propagator that propagates context in the Jaeger
30
+ # format.
31
+ def text_map_propagator
32
+ TEXT_MAP_PROPAGATOR
48
33
  end
49
34
 
50
35
  # @api private
@@ -0,0 +1,148 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Copyright The OpenTelemetry Authors
4
+ #
5
+ # SPDX-License-Identifier: Apache-2.0
6
+
7
+ require 'cgi'
8
+
9
+ # OpenTelemetry is an open source observability framework, providing a
10
+ # general-purpose API, SDK, and related tools required for the instrumentation
11
+ # of cloud-native software, frameworks, and libraries.
12
+ #
13
+ # The OpenTelemetry module provides global accessors for telemetry objects.
14
+ # See the documentation for the `opentelemetry-api` gem for details.
15
+ module OpenTelemetry
16
+ # Namespace for OpenTelemetry propagator extension libraries
17
+ module Propagator
18
+ # Namespace for OpenTelemetry Jaeger propagation
19
+ module Jaeger
20
+ # Propagates trace context using the Jaeger format
21
+ class TextMapPropagator
22
+ IDENTITY_KEY = 'uber-trace-id'
23
+ DEFAULT_FLAG_BIT = 0x0
24
+ SAMPLED_FLAG_BIT = 0x01
25
+ DEBUG_FLAG_BIT = 0x02
26
+ FIELDS = [IDENTITY_KEY].freeze
27
+ TRACE_SPAN_IDENTITY_REGEX = /\A(?<trace_id>(?:[0-9a-f]){1,32}):(?<span_id>([0-9a-f]){1,16}):[0-9a-f]{1,16}:(?<sampling_flags>[0-9a-f]{1,2})\z/.freeze
28
+ ZERO_ID_REGEX = /^0+$/.freeze
29
+
30
+ private_constant \
31
+ :IDENTITY_KEY, :DEFAULT_FLAG_BIT, :SAMPLED_FLAG_BIT, :DEBUG_FLAG_BIT,
32
+ :FIELDS, :TRACE_SPAN_IDENTITY_REGEX, :ZERO_ID_REGEX
33
+
34
+ # Extract trace context from the supplied carrier.
35
+ # If extraction fails, the original context will be returned
36
+ #
37
+ # @param [Carrier] carrier The carrier to get the header from
38
+ # @param [optional Context] context Context to be updated with the trace context
39
+ # extracted from the carrier. Defaults to +Context.current+.
40
+ # @param [optional Getter] getter If the optional getter is provided, it
41
+ # will be used to read the header from the carrier, otherwise the default
42
+ # text map getter will be used.
43
+ #
44
+ # @return [Context] context updated with extracted baggage, or the original context
45
+ # if extraction fails
46
+ def extract(carrier, context: Context.current, getter: Context::Propagation.text_map_getter)
47
+ header = getter.get(carrier, IDENTITY_KEY)
48
+ return context unless (match = header.match(TRACE_SPAN_IDENTITY_REGEX))
49
+ return context if match['trace_id'] =~ ZERO_ID_REGEX
50
+ return context if match['span_id'] =~ ZERO_ID_REGEX
51
+
52
+ sampling_flags = match['sampling_flags'].to_i
53
+ span = build_span(match, sampling_flags)
54
+ context = Jaeger.context_with_debug(context) if sampling_flags & DEBUG_FLAG_BIT != 0
55
+ context = context_with_extracted_baggage(carrier, context, getter)
56
+ Trace.context_with_span(span, parent_context: context)
57
+ end
58
+
59
+ # Inject trace context into the supplied carrier.
60
+ #
61
+ # @param [Carrier] carrier The mutable carrier to inject trace context into
62
+ # @param [Context] context The context to read trace context from
63
+ # @param [optional Setter] setter If the optional setter is provided, it
64
+ # will be used to write context into the carrier, otherwise the default
65
+ # text map setter will be used.
66
+ def inject(carrier, context: Context.current, setter: Context::Propagation.text_map_setter)
67
+ span_context = Trace.current_span(context).context
68
+ return unless span_context.valid?
69
+
70
+ flags = to_jaeger_flags(context, span_context)
71
+ trace_span_identity_value = [
72
+ span_context.hex_trace_id, span_context.hex_span_id, '0', flags
73
+ ].join(':')
74
+ setter.set(carrier, IDENTITY_KEY, trace_span_identity_value)
75
+ OpenTelemetry::Baggage.values(context: context).each do |key, value|
76
+ baggage_key = 'uberctx-' + key
77
+ encoded_value = CGI.escape(value)
78
+ setter.set(carrier, baggage_key, encoded_value)
79
+ end
80
+ carrier
81
+ end
82
+
83
+ # Returns the predefined propagation fields. If your carrier is reused, you
84
+ # should delete the fields returned by this method before calling +inject+.
85
+ #
86
+ # @return [Array<String>] a list of fields that will be used by this propagator.
87
+ def fields
88
+ FIELDS
89
+ end
90
+
91
+ private
92
+
93
+ def build_span(match, sampling_flags)
94
+ trace_id = to_trace_id(match['trace_id'])
95
+ span_context = Trace::SpanContext.new(
96
+ trace_id: trace_id,
97
+ span_id: to_span_id(match['span_id']),
98
+ trace_flags: to_trace_flags(sampling_flags),
99
+ remote: true
100
+ )
101
+ OpenTelemetry::Trace.non_recording_span(span_context)
102
+ end
103
+
104
+ def context_with_extracted_baggage(carrier, context, getter)
105
+ baggage_key_prefix = 'uberctx-'
106
+ OpenTelemetry::Baggage.build(context: context) do |b|
107
+ getter.keys(carrier).each do |carrier_key|
108
+ baggage_key = carrier_key.start_with?(baggage_key_prefix) && carrier_key[baggage_key_prefix.length..-1]
109
+ next unless baggage_key
110
+
111
+ raw_value = getter.get(carrier, carrier_key)
112
+ value = CGI.unescape(raw_value)
113
+ b.set_value(baggage_key, value)
114
+ end
115
+ end
116
+ end
117
+
118
+ def to_jaeger_flags(context, span_context)
119
+ if span_context.trace_flags == Trace::TraceFlags::SAMPLED
120
+ if Jaeger.debug?(context)
121
+ SAMPLED_FLAG_BIT | DEBUG_FLAG_BIT
122
+ else
123
+ SAMPLED_FLAG_BIT
124
+ end
125
+ else
126
+ DEFAULT_FLAG_BIT
127
+ end
128
+ end
129
+
130
+ def to_trace_flags(sampling_flags)
131
+ if (sampling_flags & SAMPLED_FLAG_BIT) != 0
132
+ Trace::TraceFlags::SAMPLED
133
+ else
134
+ Trace::TraceFlags::DEFAULT
135
+ end
136
+ end
137
+
138
+ def to_span_id(span_id_str)
139
+ [span_id_str.rjust(16, '0')].pack('H*')
140
+ end
141
+
142
+ def to_trace_id(trace_id_str)
143
+ [trace_id_str.rjust(32, '0')].pack('H*')
144
+ end
145
+ end
146
+ end
147
+ end
148
+ end
@@ -7,7 +7,7 @@
7
7
  module OpenTelemetry
8
8
  module Propagator
9
9
  module Jaeger
10
- VERSION = '0.16.0'
10
+ VERSION = '0.19.1'
11
11
  end
12
12
  end
13
13
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: opentelemetry-propagator-jaeger
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.16.0
4
+ version: 0.19.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - OpenTelemetry Authors
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-03-22 00:00:00.000000000 Z
11
+ date: 2021-08-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: opentelemetry-api
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: 0.16.0
19
+ version: 1.0.0.rc3
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: 0.16.0
26
+ version: 1.0.0.rc3
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: bundler
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -56,16 +56,16 @@ dependencies:
56
56
  name: opentelemetry-sdk
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
- - - "~>"
59
+ - - ">="
60
60
  - !ruby/object:Gem::Version
61
- version: 0.14.0
61
+ version: '0'
62
62
  type: :development
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
- - - "~>"
66
+ - - ">="
67
67
  - !ruby/object:Gem::Version
68
- version: 0.14.0
68
+ version: '0'
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: rake
71
71
  requirement: !ruby/object:Gem::Requirement
@@ -149,17 +149,16 @@ files:
149
149
  - README.md
150
150
  - lib/opentelemetry-propagator-jaeger.rb
151
151
  - lib/opentelemetry/propagator/jaeger.rb
152
- - lib/opentelemetry/propagator/jaeger/text_map_extractor.rb
153
- - lib/opentelemetry/propagator/jaeger/text_map_injector.rb
152
+ - lib/opentelemetry/propagator/jaeger/text_map_propagator.rb
154
153
  - lib/opentelemetry/propagator/jaeger/version.rb
155
154
  homepage: https://github.com/open-telemetry/opentelemetry-ruby
156
155
  licenses:
157
156
  - Apache-2.0
158
157
  metadata:
159
- changelog_uri: https://open-telemetry.github.io/opentelemetry-ruby/opentelemetry-propagator-jaeger/v0.16.0/file.CHANGELOG.html
158
+ changelog_uri: https://open-telemetry.github.io/opentelemetry-ruby/opentelemetry-propagator-jaeger/v0.19.1/file.CHANGELOG.html
160
159
  source_code_uri: https://github.com/open-telemetry/opentelemetry-ruby/tree/master/propagator/jaeger
161
160
  bug_tracker_uri: https://github.com/open-telemetry/opentelemetry-ruby/issues
162
- documentation_uri: https://open-telemetry.github.io/opentelemetry-ruby/opentelemetry-propagator-jaeger/v0.16.0
161
+ documentation_uri: https://open-telemetry.github.io/opentelemetry-ruby/opentelemetry-propagator-jaeger/v0.19.1
163
162
  post_install_message:
164
163
  rdoc_options: []
165
164
  require_paths:
@@ -175,7 +174,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
175
174
  - !ruby/object:Gem::Version
176
175
  version: '0'
177
176
  requirements: []
178
- rubygems_version: 3.1.4
177
+ rubygems_version: 3.1.6
179
178
  signing_key:
180
179
  specification_version: 4
181
180
  summary: Jaeger Context Propagation Extension for the OpenTelemetry framework
@@ -1,107 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- # Copyright The OpenTelemetry Authors
4
- #
5
- # SPDX-License-Identifier: Apache-2.0
6
-
7
- require 'cgi'
8
-
9
- # OpenTelemetry is an open source observability framework, providing a
10
- # general-purpose API, SDK, and related tools required for the instrumentation
11
- # of cloud-native software, frameworks, and libraries.
12
- #
13
- # The OpenTelemetry module provides global accessors for telemetry objects.
14
- # See the documentation for the `opentelemetry-api` gem for details.
15
- module OpenTelemetry
16
- # Namespace for OpenTelemetry propagator extension libraries
17
- module Propagator
18
- # Namespace for OpenTelemetry Jaeger propagation
19
- module Jaeger
20
- # Extracts context from carriers
21
- class TextMapExtractor
22
- TRACE_SPAN_IDENTITY_REGEX = /\A(?<trace_id>(?:[0-9a-f]){1,32}):(?<span_id>([0-9a-f]){1,16}):[0-9a-f]{1,16}:(?<sampling_flags>[0-9a-f]{1,2})\z/.freeze
23
- ZERO_ID_REGEX = /^0+$/.freeze
24
-
25
- # Returns a new TextMapExtractor that extracts Jaeger context using the
26
- # specified header keys
27
- #
28
- # @param [optional Getter] default_getter The default getter used to read
29
- # headers from a carrier during extract. Defaults to a
30
- # {OpenTelemetry::Context:Propagation::TextMapGetter} instance.
31
- # @return [TextMapExtractor]
32
- def initialize(default_getter = Context::Propagation.text_map_getter)
33
- @default_getter = default_getter
34
- end
35
-
36
- # Extract Jaeger context from the supplied carrier and set the active
37
- # span in the given context. The original context will be return if
38
- # Jaeger cannot be extracted from the carrier.
39
- #
40
- # @param [Carrier] carrier The carrier to get the header from.
41
- # @param [Context] context The context to be updated with extracted
42
- # context
43
- # @param [optional Getter] getter If the optional getter is provided, it
44
- # will be used to read the header from the carrier, otherwise the default
45
- # getter will be used.
46
- # @return [Context] Updated context with active span derived from the
47
- # header, or the original context if parsing fails.
48
- def extract(carrier, context, getter = nil)
49
- getter ||= @default_getter
50
- header = getter.get(carrier, IDENTITY_KEY)
51
- return context unless (match = header.match(TRACE_SPAN_IDENTITY_REGEX))
52
- return context if match['trace_id'] =~ ZERO_ID_REGEX
53
- return context if match['span_id'] =~ ZERO_ID_REGEX
54
-
55
- sampling_flags = match['sampling_flags'].to_i
56
- span = build_span(match, sampling_flags)
57
- context = Jaeger.context_with_debug(context) if sampling_flags & DEBUG_FLAG_BIT != 0
58
- context = set_baggage(carrier, context, getter)
59
- Trace.context_with_span(span, parent_context: context)
60
- end
61
-
62
- private
63
-
64
- def build_span(match, sampling_flags)
65
- trace_id = to_trace_id(match['trace_id'])
66
- span_context = Trace::SpanContext.new(
67
- trace_id: trace_id,
68
- span_id: to_span_id(match['span_id']),
69
- trace_flags: to_trace_flags(sampling_flags),
70
- remote: true
71
- )
72
- Trace::Span.new(span_context: span_context)
73
- end
74
-
75
- def set_baggage(carrier, context, getter)
76
- baggage_key_prefix = 'uberctx-'
77
- OpenTelemetry.baggage.build(context: context) do |b|
78
- getter.keys(carrier).each do |carrier_key|
79
- baggage_key = carrier_key.start_with?(baggage_key_prefix) && carrier_key[baggage_key_prefix.length..-1]
80
- next unless baggage_key
81
-
82
- raw_value = getter.get(carrier, carrier_key)
83
- value = CGI.unescape(raw_value)
84
- b.set_value(baggage_key, value)
85
- end
86
- end
87
- end
88
-
89
- def to_trace_flags(sampling_flags)
90
- if (sampling_flags & SAMPLED_FLAG_BIT) != 0
91
- Trace::TraceFlags::SAMPLED
92
- else
93
- Trace::TraceFlags::DEFAULT
94
- end
95
- end
96
-
97
- def to_span_id(span_id_str)
98
- [span_id_str.rjust(16, '0')].pack('H*')
99
- end
100
-
101
- def to_trace_id(trace_id_str)
102
- [trace_id_str.rjust(32, '0')].pack('H*')
103
- end
104
- end
105
- end
106
- end
107
- end
@@ -1,68 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- # Copyright The OpenTelemetry Authors
4
- #
5
- # SPDX-License-Identifier: Apache-2.0
6
-
7
- require 'cgi'
8
-
9
- module OpenTelemetry
10
- # Namespace for OpenTelemetry propagator extension libraries
11
- module Propagator
12
- # Namespace for OpenTelemetry Jaeger propagation
13
- module Jaeger
14
- # Injects context into carriers
15
- class TextMapInjector
16
- # Returns a new TextMapInjector that extracts Jaeger context using the
17
- # specified header keys
18
- #
19
- # @param [optional Setter] default_setter The default setter used to
20
- # write context into a carrier during inject. Defaults to a
21
- # {OpenTelemetry::Context:Propagation::TextMapSetter} instance.
22
- # @return [TextMapInjector]
23
- def initialize(default_setter = Context::Propagation.text_map_setter)
24
- @default_setter = default_setter
25
- end
26
-
27
- # Set the span context on the supplied carrier.
28
- #
29
- # @param [Context] context The active Context.
30
- # @param [optional Setter] setter If the optional setter is provided, it
31
- # will be used to write context into the carrier, otherwise the default
32
- # setter will be used.
33
- # @return [Object] the carrier with context injected
34
- def inject(carrier, context, setter = nil)
35
- span_context = Trace.current_span(context).context
36
- return unless span_context.valid?
37
-
38
- flags = to_flags(context, span_context)
39
- trace_span_identity_value = [
40
- span_context.hex_trace_id, span_context.hex_span_id, '0', flags
41
- ].join(':')
42
- setter ||= @default_setter
43
- setter.set(carrier, IDENTITY_KEY, trace_span_identity_value)
44
- OpenTelemetry.baggage.values(context: context).each do |key, value|
45
- baggage_key = 'uberctx-' + key
46
- encoded_value = CGI.escape(value)
47
- setter.set(carrier, baggage_key, encoded_value)
48
- end
49
- carrier
50
- end
51
-
52
- private
53
-
54
- def to_flags(context, span_context)
55
- if span_context.trace_flags == Trace::TraceFlags::SAMPLED
56
- if Jaeger.debug?(context)
57
- SAMPLED_FLAG_BIT | DEBUG_FLAG_BIT
58
- else
59
- SAMPLED_FLAG_BIT
60
- end
61
- else
62
- DEFAULT_FLAG_BIT
63
- end
64
- end
65
- end
66
- end
67
- end
68
- end