opentelemetry-api 0.16.0 → 1.0.0.rc3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +57 -0
- data/README.md +3 -3
- data/lib/opentelemetry.rb +21 -28
- data/lib/opentelemetry/baggage.rb +95 -2
- data/lib/opentelemetry/baggage/builder.rb +30 -4
- data/lib/opentelemetry/baggage/entry.rb +20 -0
- data/lib/opentelemetry/baggage/propagation.rb +9 -18
- data/lib/opentelemetry/baggage/propagation/text_map_propagator.rb +111 -0
- data/lib/opentelemetry/context.rb +48 -33
- data/lib/opentelemetry/context/propagation.rb +35 -5
- data/lib/opentelemetry/context/propagation/composite_text_map_propagator.rb +105 -0
- data/lib/opentelemetry/context/propagation/noop_text_map_propagator.rb +27 -0
- data/lib/opentelemetry/context/propagation/{propagator.rb → text_map_propagator.rb} +23 -16
- data/lib/opentelemetry/internal.rb +17 -0
- data/lib/opentelemetry/internal/proxy_tracer.rb +38 -0
- data/lib/opentelemetry/internal/proxy_tracer_provider.rb +59 -0
- data/lib/opentelemetry/trace.rb +10 -0
- data/lib/opentelemetry/trace/propagation/trace_context.rb +7 -18
- data/lib/opentelemetry/trace/propagation/trace_context/text_map_propagator.rb +73 -0
- data/lib/opentelemetry/trace/status.rb +34 -5
- data/lib/opentelemetry/trace/tracer.rb +8 -9
- data/lib/opentelemetry/version.rb +1 -1
- metadata +16 -25
- data/lib/opentelemetry/baggage/manager.rb +0 -41
- data/lib/opentelemetry/baggage/propagation/text_map_extractor.rb +0 -57
- data/lib/opentelemetry/baggage/propagation/text_map_injector.rb +0 -52
- data/lib/opentelemetry/context/propagation/composite_propagator.rb +0 -72
- data/lib/opentelemetry/context/propagation/noop_extractor.rb +0 -26
- data/lib/opentelemetry/context/propagation/noop_injector.rb +0 -26
- data/lib/opentelemetry/instrumentation.rb +0 -15
- data/lib/opentelemetry/instrumentation/base.rb +0 -307
- data/lib/opentelemetry/instrumentation/registry.rb +0 -86
- data/lib/opentelemetry/metrics.rb +0 -16
- data/lib/opentelemetry/metrics/handles.rb +0 -44
- data/lib/opentelemetry/metrics/instruments.rb +0 -105
- data/lib/opentelemetry/metrics/meter.rb +0 -72
- data/lib/opentelemetry/metrics/meter_provider.rb +0 -22
- data/lib/opentelemetry/trace/propagation/trace_context/text_map_extractor.rb +0 -52
- data/lib/opentelemetry/trace/propagation/trace_context/text_map_injector.rb +0 -49
- data/lib/opentelemetry/trace/util/http_to_status.rb +0 -28
@@ -0,0 +1,59 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# Copyright The OpenTelemetry Authors
|
4
|
+
#
|
5
|
+
# SPDX-License-Identifier: Apache-2.0
|
6
|
+
|
7
|
+
module OpenTelemetry
|
8
|
+
module Internal
|
9
|
+
# @api private
|
10
|
+
#
|
11
|
+
# {ProxyTracerProvider} is an implementation of {OpenTelemetry::Trace::TracerProvider}.
|
12
|
+
# It is the default global tracer provider returned by OpenTelemetry.tracer_provider.
|
13
|
+
# It delegates to a "real" TracerProvider after the global tracer provider is registered.
|
14
|
+
# It returns {ProxyTracer} instances until the delegate is installed.
|
15
|
+
class ProxyTracerProvider < Trace::TracerProvider
|
16
|
+
Key = Struct.new(:name, :version)
|
17
|
+
private_constant(:Key)
|
18
|
+
|
19
|
+
# Returns a new {ProxyTracerProvider} instance.
|
20
|
+
#
|
21
|
+
# @return [ProxyTracerProvider]
|
22
|
+
def initialize
|
23
|
+
@mutex = Mutex.new
|
24
|
+
@registry = {}
|
25
|
+
@delegate = nil
|
26
|
+
end
|
27
|
+
|
28
|
+
# Set the delegate tracer provider. If this is called more than once, a warning will
|
29
|
+
# be logged and superfluous calls will be ignored.
|
30
|
+
#
|
31
|
+
# @param [TracerProvider] provider The tracer provider to delegate to
|
32
|
+
def delegate=(provider)
|
33
|
+
unless @delegate.nil?
|
34
|
+
OpenTelemetry.logger.warn 'Attempt to reset delegate in ProxyTracerProvider ignored.'
|
35
|
+
return
|
36
|
+
end
|
37
|
+
|
38
|
+
@mutex.synchronize do
|
39
|
+
@delegate = provider
|
40
|
+
@registry.each { |key, tracer| tracer.delegate = provider.tracer(key.name, key.version) }
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
# Returns a {Tracer} instance.
|
45
|
+
#
|
46
|
+
# @param [optional String] name Instrumentation package name
|
47
|
+
# @param [optional String] version Instrumentation package version
|
48
|
+
#
|
49
|
+
# @return [Tracer]
|
50
|
+
def tracer(name = nil, version = nil)
|
51
|
+
@mutex.synchronize do
|
52
|
+
return @delegate.tracer(name, version) unless @delegate.nil?
|
53
|
+
|
54
|
+
@registry[Key.new(name, version)] ||= ProxyTracer.new
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
data/lib/opentelemetry/trace.rb
CHANGED
@@ -81,6 +81,16 @@ module OpenTelemetry
|
|
81
81
|
def with_span(span)
|
82
82
|
Context.with_value(CURRENT_SPAN_KEY, span) { |c, s| yield s, c }
|
83
83
|
end
|
84
|
+
|
85
|
+
# Wraps a SpanContext with an object implementing the Span interface. This is done in order
|
86
|
+
# to expose a SpanContext as a Span in operations such as in-process Span propagation.
|
87
|
+
#
|
88
|
+
# @param [SpanContext] span_context SpanContext to be wrapped
|
89
|
+
#
|
90
|
+
# @return [Span]
|
91
|
+
def non_recording_span(span_context)
|
92
|
+
Span.new(span_context: span_context)
|
93
|
+
end
|
84
94
|
end
|
85
95
|
end
|
86
96
|
|
@@ -5,8 +5,7 @@
|
|
5
5
|
# SPDX-License-Identifier: Apache-2.0
|
6
6
|
|
7
7
|
require 'opentelemetry/trace/propagation/trace_context/trace_parent'
|
8
|
-
require 'opentelemetry/trace/propagation/trace_context/
|
9
|
-
require 'opentelemetry/trace/propagation/trace_context/text_map_injector'
|
8
|
+
require 'opentelemetry/trace/propagation/trace_context/text_map_propagator'
|
10
9
|
|
11
10
|
module OpenTelemetry
|
12
11
|
module Trace
|
@@ -15,24 +14,14 @@ module OpenTelemetry
|
|
15
14
|
# for context propagation in the W3C Trace Context format.
|
16
15
|
module TraceContext
|
17
16
|
extend self
|
18
|
-
|
19
|
-
TRACESTATE_KEY = 'tracestate'
|
20
|
-
TEXT_MAP_EXTRACTOR = TextMapExtractor.new
|
21
|
-
TEXT_MAP_INJECTOR = TextMapInjector.new
|
17
|
+
TEXT_MAP_PROPAGATOR = TextMapPropagator.new
|
22
18
|
|
23
|
-
private_constant :
|
24
|
-
:TEXT_MAP_INJECTOR, :TEXT_MAP_EXTRACTOR
|
19
|
+
private_constant :TEXT_MAP_PROPAGATOR
|
25
20
|
|
26
|
-
# Returns
|
27
|
-
# format
|
28
|
-
def
|
29
|
-
|
30
|
-
end
|
31
|
-
|
32
|
-
# Returns an injector that injects context using the W3C Trace Context
|
33
|
-
# format
|
34
|
-
def text_map_injector
|
35
|
-
TEXT_MAP_INJECTOR
|
21
|
+
# Returns a text map propagator that propagates context using the
|
22
|
+
# W3C Trace Context format.
|
23
|
+
def text_map_propagator
|
24
|
+
TEXT_MAP_PROPAGATOR
|
36
25
|
end
|
37
26
|
end
|
38
27
|
end
|
@@ -0,0 +1,73 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# Copyright The OpenTelemetry Authors
|
4
|
+
#
|
5
|
+
# SPDX-License-Identifier: Apache-2.0
|
6
|
+
|
7
|
+
module OpenTelemetry
|
8
|
+
module Trace
|
9
|
+
module Propagation
|
10
|
+
module TraceContext
|
11
|
+
# Propagates trace context using the W3C Trace Context format
|
12
|
+
class TextMapPropagator
|
13
|
+
TRACEPARENT_KEY = 'traceparent'
|
14
|
+
TRACESTATE_KEY = 'tracestate'
|
15
|
+
FIELDS = [TRACEPARENT_KEY, TRACESTATE_KEY].freeze
|
16
|
+
|
17
|
+
private_constant :TRACEPARENT_KEY, :TRACESTATE_KEY, :FIELDS
|
18
|
+
|
19
|
+
# Inject trace context into the supplied carrier.
|
20
|
+
#
|
21
|
+
# @param [Carrier] carrier The mutable carrier to inject trace context into
|
22
|
+
# @param [Context] context The context to read trace context from
|
23
|
+
# @param [optional Setter] setter If the optional setter is provided, it
|
24
|
+
# will be used to write context into the carrier, otherwise the default
|
25
|
+
# text map setter will be used.
|
26
|
+
def inject(carrier, context: Context.current, setter: Context::Propagation.text_map_setter)
|
27
|
+
span_context = Trace.current_span(context).context
|
28
|
+
return unless span_context.valid?
|
29
|
+
|
30
|
+
setter.set(carrier, TRACEPARENT_KEY, TraceParent.from_span_context(span_context).to_s)
|
31
|
+
setter.set(carrier, TRACESTATE_KEY, span_context.tracestate.to_s) unless span_context.tracestate.empty?
|
32
|
+
nil
|
33
|
+
end
|
34
|
+
|
35
|
+
# Extract trace context from the supplied carrier.
|
36
|
+
# If extraction fails, the original context will be returned
|
37
|
+
#
|
38
|
+
# @param [Carrier] carrier The carrier to get the header from
|
39
|
+
# @param [optional Context] context Context to be updated with the trace context
|
40
|
+
# extracted from the carrier. Defaults to +Context.current+.
|
41
|
+
# @param [optional Getter] getter If the optional getter is provided, it
|
42
|
+
# will be used to read the header from the carrier, otherwise the default
|
43
|
+
# text map getter will be used.
|
44
|
+
#
|
45
|
+
# @return [Context] context updated with extracted baggage, or the original context
|
46
|
+
# if extraction fails
|
47
|
+
def extract(carrier, context: Context.current, getter: Context::Propagation.text_map_getter)
|
48
|
+
tp = TraceParent.from_string(getter.get(carrier, TRACEPARENT_KEY))
|
49
|
+
tracestate = Tracestate.from_string(getter.get(carrier, TRACESTATE_KEY))
|
50
|
+
|
51
|
+
span_context = Trace::SpanContext.new(trace_id: tp.trace_id,
|
52
|
+
span_id: tp.span_id,
|
53
|
+
trace_flags: tp.flags,
|
54
|
+
tracestate: tracestate,
|
55
|
+
remote: true)
|
56
|
+
span = OpenTelemetry::Trace.non_recording_span(span_context)
|
57
|
+
OpenTelemetry::Trace.context_with_span(span)
|
58
|
+
rescue OpenTelemetry::Error
|
59
|
+
context
|
60
|
+
end
|
61
|
+
|
62
|
+
# Returns the predefined propagation fields. If your carrier is reused, you
|
63
|
+
# should delete the fields returned by this method before calling +inject+.
|
64
|
+
#
|
65
|
+
# @return [Array<String>] a list of fields that will be used by this propagator.
|
66
|
+
def fields
|
67
|
+
FIELDS
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
@@ -4,15 +4,41 @@
|
|
4
4
|
#
|
5
5
|
# SPDX-License-Identifier: Apache-2.0
|
6
6
|
|
7
|
-
require 'opentelemetry/trace/util/http_to_status'
|
8
|
-
|
9
7
|
module OpenTelemetry
|
10
8
|
module Trace
|
11
9
|
# Status represents the status of a finished {Span}. It is composed of a
|
12
10
|
# status code in conjunction with an optional descriptive message.
|
13
11
|
class Status
|
14
|
-
|
15
|
-
|
12
|
+
class << self
|
13
|
+
private :new # rubocop:disable Style/AccessModifierDeclarations
|
14
|
+
|
15
|
+
# Returns a newly created {Status} with code == UNSET and an optional
|
16
|
+
# description.
|
17
|
+
#
|
18
|
+
# @param [String] description
|
19
|
+
# @return [Status]
|
20
|
+
def unset(description = '')
|
21
|
+
new(UNSET, description: description)
|
22
|
+
end
|
23
|
+
|
24
|
+
# Returns a newly created {Status} with code == OK and an optional
|
25
|
+
# description.
|
26
|
+
#
|
27
|
+
# @param [String] description
|
28
|
+
# @return [Status]
|
29
|
+
def ok(description = '')
|
30
|
+
new(OK, description: description)
|
31
|
+
end
|
32
|
+
|
33
|
+
# Returns a newly created {Status} with code == ERROR and an optional
|
34
|
+
# description.
|
35
|
+
#
|
36
|
+
# @param [String] description
|
37
|
+
# @return [Status]
|
38
|
+
def error(description = '')
|
39
|
+
new(ERROR, description: description)
|
40
|
+
end
|
41
|
+
end
|
16
42
|
|
17
43
|
# Retrieve the status code of this Status.
|
18
44
|
#
|
@@ -24,7 +50,10 @@ module OpenTelemetry
|
|
24
50
|
# @return [String]
|
25
51
|
attr_reader :description
|
26
52
|
|
27
|
-
#
|
53
|
+
# @api private
|
54
|
+
# The constructor is private and only for use internally by the class.
|
55
|
+
# Users should use the {unset}, {error}, or {ok} factory methods to
|
56
|
+
# obtain a {Status} instance.
|
28
57
|
#
|
29
58
|
# @param [Integer] code One of the status codes below
|
30
59
|
# @param [String] description
|
@@ -23,21 +23,20 @@ module OpenTelemetry
|
|
23
23
|
# span and reraised.
|
24
24
|
# @yield [span, context] yields the newly created span and a context containing the
|
25
25
|
# span to the block.
|
26
|
-
def in_span(name, attributes: nil, links: nil, start_timestamp: nil, kind: nil
|
26
|
+
def in_span(name, attributes: nil, links: nil, start_timestamp: nil, kind: nil)
|
27
27
|
span = nil
|
28
|
-
span = start_span(name, attributes: attributes, links: links, start_timestamp: start_timestamp, kind: kind
|
28
|
+
span = start_span(name, attributes: attributes, links: links, start_timestamp: start_timestamp, kind: kind)
|
29
29
|
Trace.with_span(span) { |s, c| yield s, c }
|
30
30
|
rescue Exception => e # rubocop:disable Lint/RescueException
|
31
31
|
span&.record_exception(e)
|
32
|
-
span&.status = Status.
|
33
|
-
description: "Unhandled exception of type: #{e.class}")
|
32
|
+
span&.status = Status.error("Unhandled exception of type: #{e.class}")
|
34
33
|
raise e
|
35
34
|
ensure
|
36
35
|
span&.finish
|
37
36
|
end
|
38
37
|
|
39
38
|
def start_root_span(name, attributes: nil, links: nil, start_timestamp: nil, kind: nil)
|
40
|
-
Span
|
39
|
+
Span::INVALID
|
41
40
|
end
|
42
41
|
|
43
42
|
# Used when a caller wants to manage the activation/deactivation and lifecycle of
|
@@ -49,12 +48,12 @@ module OpenTelemetry
|
|
49
48
|
#
|
50
49
|
# @return [Span]
|
51
50
|
def start_span(name, with_parent: nil, attributes: nil, links: nil, start_timestamp: nil, kind: nil)
|
52
|
-
|
51
|
+
span = OpenTelemetry::Trace.current_span(with_parent)
|
53
52
|
|
54
|
-
if
|
55
|
-
|
53
|
+
if span.context.valid?
|
54
|
+
span
|
56
55
|
else
|
57
|
-
Span
|
56
|
+
Span::INVALID
|
58
57
|
end
|
59
58
|
end
|
60
59
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: opentelemetry-api
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 1.0.0.rc3
|
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-08-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: benchmark-ipsa
|
@@ -151,36 +151,28 @@ files:
|
|
151
151
|
- lib/opentelemetry.rb
|
152
152
|
- lib/opentelemetry/baggage.rb
|
153
153
|
- lib/opentelemetry/baggage/builder.rb
|
154
|
-
- lib/opentelemetry/baggage/
|
154
|
+
- lib/opentelemetry/baggage/entry.rb
|
155
155
|
- lib/opentelemetry/baggage/propagation.rb
|
156
156
|
- lib/opentelemetry/baggage/propagation/context_keys.rb
|
157
|
-
- lib/opentelemetry/baggage/propagation/
|
158
|
-
- lib/opentelemetry/baggage/propagation/text_map_injector.rb
|
157
|
+
- lib/opentelemetry/baggage/propagation/text_map_propagator.rb
|
159
158
|
- lib/opentelemetry/context.rb
|
160
159
|
- lib/opentelemetry/context/key.rb
|
161
160
|
- lib/opentelemetry/context/propagation.rb
|
162
|
-
- lib/opentelemetry/context/propagation/
|
163
|
-
- lib/opentelemetry/context/propagation/
|
164
|
-
- lib/opentelemetry/context/propagation/noop_injector.rb
|
165
|
-
- lib/opentelemetry/context/propagation/propagator.rb
|
161
|
+
- lib/opentelemetry/context/propagation/composite_text_map_propagator.rb
|
162
|
+
- lib/opentelemetry/context/propagation/noop_text_map_propagator.rb
|
166
163
|
- lib/opentelemetry/context/propagation/rack_env_getter.rb
|
167
164
|
- lib/opentelemetry/context/propagation/text_map_getter.rb
|
165
|
+
- lib/opentelemetry/context/propagation/text_map_propagator.rb
|
168
166
|
- lib/opentelemetry/context/propagation/text_map_setter.rb
|
169
167
|
- lib/opentelemetry/error.rb
|
170
|
-
- lib/opentelemetry/
|
171
|
-
- lib/opentelemetry/
|
172
|
-
- lib/opentelemetry/
|
173
|
-
- lib/opentelemetry/metrics.rb
|
174
|
-
- lib/opentelemetry/metrics/handles.rb
|
175
|
-
- lib/opentelemetry/metrics/instruments.rb
|
176
|
-
- lib/opentelemetry/metrics/meter.rb
|
177
|
-
- lib/opentelemetry/metrics/meter_provider.rb
|
168
|
+
- lib/opentelemetry/internal.rb
|
169
|
+
- lib/opentelemetry/internal/proxy_tracer.rb
|
170
|
+
- lib/opentelemetry/internal/proxy_tracer_provider.rb
|
178
171
|
- lib/opentelemetry/trace.rb
|
179
172
|
- lib/opentelemetry/trace/link.rb
|
180
173
|
- lib/opentelemetry/trace/propagation.rb
|
181
174
|
- lib/opentelemetry/trace/propagation/trace_context.rb
|
182
|
-
- lib/opentelemetry/trace/propagation/trace_context/
|
183
|
-
- lib/opentelemetry/trace/propagation/trace_context/text_map_injector.rb
|
175
|
+
- lib/opentelemetry/trace/propagation/trace_context/text_map_propagator.rb
|
184
176
|
- lib/opentelemetry/trace/propagation/trace_context/trace_parent.rb
|
185
177
|
- lib/opentelemetry/trace/span.rb
|
186
178
|
- lib/opentelemetry/trace/span_context.rb
|
@@ -190,16 +182,15 @@ files:
|
|
190
182
|
- lib/opentelemetry/trace/tracer.rb
|
191
183
|
- lib/opentelemetry/trace/tracer_provider.rb
|
192
184
|
- lib/opentelemetry/trace/tracestate.rb
|
193
|
-
- lib/opentelemetry/trace/util/http_to_status.rb
|
194
185
|
- lib/opentelemetry/version.rb
|
195
186
|
homepage: https://github.com/open-telemetry/opentelemetry-ruby
|
196
187
|
licenses:
|
197
188
|
- Apache-2.0
|
198
189
|
metadata:
|
199
|
-
changelog_uri: https://open-telemetry.github.io/opentelemetry-ruby/opentelemetry-api/
|
190
|
+
changelog_uri: https://open-telemetry.github.io/opentelemetry-ruby/opentelemetry-api/v1.0.0.rc3/file.CHANGELOG.html
|
200
191
|
source_code_uri: https://github.com/open-telemetry/opentelemetry-ruby/tree/main/api
|
201
192
|
bug_tracker_uri: https://github.com/open-telemetry/opentelemetry-ruby/issues
|
202
|
-
documentation_uri: https://open-telemetry.github.io/opentelemetry-ruby/opentelemetry-api/
|
193
|
+
documentation_uri: https://open-telemetry.github.io/opentelemetry-ruby/opentelemetry-api/v1.0.0.rc3
|
203
194
|
post_install_message:
|
204
195
|
rdoc_options: []
|
205
196
|
require_paths:
|
@@ -211,11 +202,11 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
211
202
|
version: 2.5.0
|
212
203
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
213
204
|
requirements:
|
214
|
-
- - "
|
205
|
+
- - ">"
|
215
206
|
- !ruby/object:Gem::Version
|
216
|
-
version:
|
207
|
+
version: 1.3.1
|
217
208
|
requirements: []
|
218
|
-
rubygems_version: 3.1.
|
209
|
+
rubygems_version: 3.1.6
|
219
210
|
signing_key:
|
220
211
|
specification_version: 4
|
221
212
|
summary: A stats collection and distributed tracing framework
|
@@ -1,41 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
# Copyright The OpenTelemetry Authors
|
4
|
-
#
|
5
|
-
# SPDX-License-Identifier: Apache-2.0
|
6
|
-
|
7
|
-
module OpenTelemetry
|
8
|
-
module Baggage
|
9
|
-
# No op implementation of Baggage::Manager
|
10
|
-
class Manager
|
11
|
-
NOOP_BUILDER = Builder.new
|
12
|
-
EMPTY_VALUES = {}.freeze
|
13
|
-
private_constant(:NOOP_BUILDER, :EMPTY_VALUES)
|
14
|
-
|
15
|
-
def build(context: Context.current)
|
16
|
-
yield NOOP_BUILDER
|
17
|
-
context
|
18
|
-
end
|
19
|
-
|
20
|
-
def set_value(key, value, context: Context.current)
|
21
|
-
context
|
22
|
-
end
|
23
|
-
|
24
|
-
def value(key, context: Context.current)
|
25
|
-
nil
|
26
|
-
end
|
27
|
-
|
28
|
-
def values(context: Context.current)
|
29
|
-
EMPTY_VALUES
|
30
|
-
end
|
31
|
-
|
32
|
-
def remove_value(key, context: Context.current)
|
33
|
-
context
|
34
|
-
end
|
35
|
-
|
36
|
-
def clear(context: Context.current)
|
37
|
-
context
|
38
|
-
end
|
39
|
-
end
|
40
|
-
end
|
41
|
-
end
|
@@ -1,57 +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
|
-
module Baggage
|
11
|
-
module Propagation
|
12
|
-
# Extracts baggage from carriers in the W3C Baggage format
|
13
|
-
class TextMapExtractor
|
14
|
-
# Returns a new TextMapExtractor that extracts context using the specified
|
15
|
-
# getter
|
16
|
-
#
|
17
|
-
# @param [optional Getter] default_getter The default getter used to read
|
18
|
-
# headers from a carrier during extract. Defaults to a
|
19
|
-
# {OpenTelemetry::Context::Propagation::TextMapGetter} instance.
|
20
|
-
# @return [TextMapExtractor]
|
21
|
-
def initialize(default_getter = Context::Propagation.text_map_getter)
|
22
|
-
@default_getter = default_getter
|
23
|
-
end
|
24
|
-
|
25
|
-
# Extract remote baggage from the supplied carrier.
|
26
|
-
# If extraction fails, the original context will be returned
|
27
|
-
#
|
28
|
-
# @param [Carrier] carrier The carrier to get the header from
|
29
|
-
# @param [Context] context The context to be updated with extracted baggage
|
30
|
-
# @param [optional Getter] getter If the optional getter is provided, it
|
31
|
-
# will be used to read the header from the carrier, otherwise the default
|
32
|
-
# getter will be used.
|
33
|
-
# @return [Context] context updated with extracted baggage, or the original context
|
34
|
-
# if extraction fails
|
35
|
-
def extract(carrier, context, getter = nil)
|
36
|
-
getter ||= @default_getter
|
37
|
-
header = getter.get(carrier, BAGGAGE_KEY)
|
38
|
-
|
39
|
-
entries = header.gsub(/\s/, '').split(',')
|
40
|
-
|
41
|
-
baggage = entries.each_with_object({}) do |entry, memo|
|
42
|
-
# The ignored variable below holds properties as per the W3C spec.
|
43
|
-
# OTel is not using them currently, but they might be used for
|
44
|
-
# metadata in the future
|
45
|
-
kv, = entry.split(';', 2)
|
46
|
-
k, v = kv.split('=').map!(&CGI.method(:unescape))
|
47
|
-
memo[k] = v
|
48
|
-
end
|
49
|
-
|
50
|
-
context.set_value(ContextKeys.baggage_key, baggage)
|
51
|
-
rescue StandardError
|
52
|
-
context
|
53
|
-
end
|
54
|
-
end
|
55
|
-
end
|
56
|
-
end
|
57
|
-
end
|