opentelemetry-propagator-jaeger 0.16.0 → 0.17.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +8 -0
- data/README.md +4 -4
- data/lib/opentelemetry/propagator/jaeger.rb +7 -22
- data/lib/opentelemetry/propagator/jaeger/{text_map_extractor.rb → text_map_propagator.rb} +66 -25
- data/lib/opentelemetry/propagator/jaeger/version.rb +1 -1
- metadata +8 -9
- data/lib/opentelemetry/propagator/jaeger/text_map_injector.rb +0 -68
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7dece159e0c94c5fa48147b8ef28b92306061f4d6a2495f881ed485ab2e688eb
|
4
|
+
data.tar.gz: 73ba94fa32820c294d8831a06e9996f8b9b4e0ccf3f7c0faf6ed8bc9577a2834
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 581dadd5c5b73c38c98ecd59f5be345eb956d44ddb83cdd95e6eb848e92e533e0a10b90e2f3e16d8d4fedf0809b22ec86a39cee9920cab155c59862b857664cf
|
7
|
+
data.tar.gz: f52229bd430039b17c031029a583fe0911e0afe69a7c1e9ae9c396e7c54c6ecf9066e5e86dd963c1bf528e9acdba92e94f4ac056313b676bc7935b08686e9311
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,13 @@
|
|
1
1
|
# Release History: opentelemetry-propagator-jaeger
|
2
2
|
|
3
|
+
### v0.17.0 / 2021-04-22
|
4
|
+
|
5
|
+
* BREAKING CHANGE: Replace TextMapInjector/TextMapExtractor pairs with a TextMapPropagator.
|
6
|
+
|
7
|
+
[Check the propagator documentation](https://open-telemetry.github.io/opentelemetry-ruby/) for the new usage.
|
8
|
+
|
9
|
+
* FIXED: Refactor propagators to add #fields
|
10
|
+
|
3
11
|
### v0.16.0 / 2021-03-17
|
4
12
|
|
5
13
|
* Initial release.
|
data/README.md
CHANGED
@@ -1,9 +1,9 @@
|
|
1
1
|
# opentelemetry-propagator-jaeger
|
2
2
|
|
3
|
-
The `opentelemetry-propagator-jaeger` gem contains
|
4
|
-
[Jaeger native propagation format][jaeger-spec]
|
5
|
-
|
6
|
-
|
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/
|
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
|
-
|
27
|
-
TEXT_MAP_INJECTOR = TextMapInjector.new
|
25
|
+
TEXT_MAP_PROPAGATOR = TextMapPropagator.new
|
28
26
|
|
29
|
-
private_constant :
|
27
|
+
private_constant :TEXT_MAP_PROPAGATOR
|
30
28
|
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
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
|
@@ -17,36 +17,33 @@ module OpenTelemetry
|
|
17
17
|
module Propagator
|
18
18
|
# Namespace for OpenTelemetry Jaeger propagation
|
19
19
|
module Jaeger
|
20
|
-
#
|
21
|
-
class
|
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
|
22
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
|
23
28
|
ZERO_ID_REGEX = /^0+$/.freeze
|
24
29
|
|
25
|
-
|
26
|
-
|
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
|
30
|
+
private_constant \
|
31
|
+
:IDENTITY_KEY, :DEFAULT_FLAG_BIT, :SAMPLED_FLAG_BIT, :DEBUG_FLAG_BIT,
|
32
|
+
:FIELDS, :TRACE_SPAN_IDENTITY_REGEX, :ZERO_ID_REGEX
|
35
33
|
|
36
|
-
# Extract
|
37
|
-
#
|
38
|
-
# Jaeger cannot be extracted from the carrier.
|
34
|
+
# Extract trace context from the supplied carrier.
|
35
|
+
# If extraction fails, the original context will be returned
|
39
36
|
#
|
40
|
-
# @param [Carrier] carrier The carrier to get the header from
|
41
|
-
# @param [Context] context
|
42
|
-
#
|
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+.
|
43
40
|
# @param [optional Getter] getter If the optional getter is provided, it
|
44
41
|
# will be used to read the header from the carrier, otherwise the default
|
45
|
-
# getter will be used.
|
46
|
-
#
|
47
|
-
#
|
48
|
-
|
49
|
-
|
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)
|
50
47
|
header = getter.get(carrier, IDENTITY_KEY)
|
51
48
|
return context unless (match = header.match(TRACE_SPAN_IDENTITY_REGEX))
|
52
49
|
return context if match['trace_id'] =~ ZERO_ID_REGEX
|
@@ -55,10 +52,42 @@ module OpenTelemetry
|
|
55
52
|
sampling_flags = match['sampling_flags'].to_i
|
56
53
|
span = build_span(match, sampling_flags)
|
57
54
|
context = Jaeger.context_with_debug(context) if sampling_flags & DEBUG_FLAG_BIT != 0
|
58
|
-
context =
|
55
|
+
context = context_with_extracted_baggage(carrier, context, getter)
|
59
56
|
Trace.context_with_span(span, parent_context: context)
|
60
57
|
end
|
61
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
|
+
|
62
91
|
private
|
63
92
|
|
64
93
|
def build_span(match, sampling_flags)
|
@@ -72,7 +101,7 @@ module OpenTelemetry
|
|
72
101
|
Trace::Span.new(span_context: span_context)
|
73
102
|
end
|
74
103
|
|
75
|
-
def
|
104
|
+
def context_with_extracted_baggage(carrier, context, getter)
|
76
105
|
baggage_key_prefix = 'uberctx-'
|
77
106
|
OpenTelemetry.baggage.build(context: context) do |b|
|
78
107
|
getter.keys(carrier).each do |carrier_key|
|
@@ -86,6 +115,18 @@ module OpenTelemetry
|
|
86
115
|
end
|
87
116
|
end
|
88
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
|
+
|
89
130
|
def to_trace_flags(sampling_flags)
|
90
131
|
if (sampling_flags & SAMPLED_FLAG_BIT) != 0
|
91
132
|
Trace::TraceFlags::SAMPLED
|
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.
|
4
|
+
version: 0.17.0
|
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-
|
11
|
+
date: 2021-04-23 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.
|
19
|
+
version: 0.17.0
|
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.
|
26
|
+
version: 0.17.0
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: bundler
|
29
29
|
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/
|
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.
|
158
|
+
changelog_uri: https://open-telemetry.github.io/opentelemetry-ruby/opentelemetry-propagator-jaeger/v0.17.0/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.
|
161
|
+
documentation_uri: https://open-telemetry.github.io/opentelemetry-ruby/opentelemetry-propagator-jaeger/v0.17.0
|
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.
|
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,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
|