opentelemetry-sdk 0.5.0 → 0.9.0
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/.yardopts +2 -2
- data/CHANGELOG.md +54 -0
- data/README.md +1 -1
- data/lib/opentelemetry/sdk.rb +2 -1
- data/lib/opentelemetry/sdk/baggage.rb +16 -0
- data/lib/opentelemetry/sdk/{correlation_context → baggage}/builder.rb +5 -5
- data/lib/opentelemetry/sdk/{correlation_context → baggage}/manager.rb +37 -27
- data/lib/opentelemetry/sdk/configurator.rb +41 -20
- data/lib/opentelemetry/sdk/resources/constants.rb +0 -4
- data/lib/opentelemetry/sdk/resources/resource.rb +33 -22
- data/lib/opentelemetry/sdk/trace.rb +1 -0
- data/lib/opentelemetry/sdk/trace/config/trace_config.rb +3 -3
- data/lib/opentelemetry/sdk/trace/event.rb +48 -0
- data/lib/opentelemetry/sdk/trace/export.rb +9 -4
- data/lib/opentelemetry/sdk/trace/export/batch_span_processor.rb +84 -36
- data/lib/opentelemetry/sdk/trace/export/console_span_exporter.rb +5 -8
- data/lib/opentelemetry/sdk/trace/export/in_memory_span_exporter.rb +8 -2
- data/lib/opentelemetry/sdk/trace/export/multi_span_exporter.rb +17 -16
- data/lib/opentelemetry/sdk/trace/export/noop_span_exporter.rb +6 -2
- data/lib/opentelemetry/sdk/trace/export/simple_span_processor.rb +22 -4
- data/lib/opentelemetry/sdk/trace/multi_span_processor.rb +30 -6
- data/lib/opentelemetry/sdk/trace/noop_span_processor.rb +17 -3
- data/lib/opentelemetry/sdk/trace/samplers.rb +51 -43
- data/lib/opentelemetry/sdk/trace/samplers/decision.rb +3 -3
- data/lib/opentelemetry/sdk/trace/samplers/parent_based.rb +54 -0
- data/lib/opentelemetry/sdk/trace/samplers/result.rb +3 -3
- data/lib/opentelemetry/sdk/trace/samplers/trace_id_ratio_based.rb +45 -0
- data/lib/opentelemetry/sdk/trace/span.rb +30 -36
- data/lib/opentelemetry/sdk/trace/span_data.rb +16 -3
- data/lib/opentelemetry/sdk/trace/tracer.rb +13 -11
- data/lib/opentelemetry/sdk/trace/tracer_provider.rb +4 -2
- data/lib/opentelemetry/sdk/version.rb +1 -1
- metadata +30 -11
- data/lib/opentelemetry/sdk/correlation_context.rb +0 -16
- data/lib/opentelemetry/sdk/trace/samplers/parent_or_else.rb +0 -43
- data/lib/opentelemetry/sdk/trace/samplers/probability_sampler.rb +0 -64
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 92bb8c4a7792c37eb367fc10a3093b3fe27339592bc8689cdac308f21ba8ffa7
|
4
|
+
data.tar.gz: 2a0b6df150bbf2cb0987d1d4e5aa29fb37323bb740786ee2171e3ae037ff60ac
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 59acf74f4d8cd4d4b1b7206690b6b0ddff389e98a76d151eb3cc08b97168af5c876a67a537123d81f2a3c7e65e3d52aea07f502bff02b7f8736863c8d299587e
|
7
|
+
data.tar.gz: b99ebe6b214387d35d530d01d154f017cb5ae9ea11f6922773c12d1b2fa2807a1051d5d3f021816ad6970d152794ccb1b2e9af37c46b5fde768d4c8574d8833b
|
data/.yardopts
CHANGED
data/CHANGELOG.md
CHANGED
@@ -1 +1,55 @@
|
|
1
1
|
# Release History: opentelemetry-sdk
|
2
|
+
|
3
|
+
### v0.9.0 / 2020-11-27
|
4
|
+
|
5
|
+
* BREAKING CHANGE: Pass full Context to samplers
|
6
|
+
* BREAKING CHANGE: Add timeout for force_flush and shutdown
|
7
|
+
|
8
|
+
* ADDED: Add OTEL_RUBY_BSP_START_THREAD_ON_BOOT env var
|
9
|
+
* ADDED: Add timeout for force_flush and shutdown
|
10
|
+
* FIXED: Signal at batch_size
|
11
|
+
* FIXED: SDK Span.recording? after finish
|
12
|
+
* FIXED: Pass full Context to samplers
|
13
|
+
* DOCS: Add documentation on usage scenarios for span processors
|
14
|
+
|
15
|
+
### v0.8.0 / 2020-10-27
|
16
|
+
|
17
|
+
* BREAKING CHANGE: Move context/span methods to Trace module
|
18
|
+
* BREAKING CHANGE: Remove 'canonical' from status codes
|
19
|
+
* BREAKING CHANGE: Assorted SpanContext fixes
|
20
|
+
|
21
|
+
* FIXED: Move context/span methods to Trace module
|
22
|
+
* FIXED: Remove 'canonical' from status codes
|
23
|
+
* FIXED: Assorted SpanContext fixes
|
24
|
+
|
25
|
+
### v0.7.0 / 2020-10-07
|
26
|
+
|
27
|
+
* ADDED: Add service_name setter to configurator
|
28
|
+
* ADDED: Add service_version setter to configurator
|
29
|
+
* FIXED: Fork safety for batch processor
|
30
|
+
* FIXED: Don't generate a span ID unnecessarily
|
31
|
+
* DOCS: Fix Configurator#add_span_processor
|
32
|
+
* DOCS: Standardize toplevel docs structure and readme
|
33
|
+
|
34
|
+
### v0.6.0 / 2020-09-10
|
35
|
+
|
36
|
+
* BREAKING CHANGE: Rename Resource labels to attributes
|
37
|
+
* BREAKING CHANGE: Export resource from Span/SpanData instead of library_resource
|
38
|
+
* BREAKING CHANGE: Rename CorrelationContext to Baggage
|
39
|
+
* BREAKING CHANGE: Rename Text* to TextMap* (propagators, injectors, extractors)
|
40
|
+
* BREAKING CHANGE: Rename span.record_error to span.record_exception
|
41
|
+
* BREAKING CHANGE: Update samplers to match spec
|
42
|
+
* BREAKING CHANGE: Remove support for lazy event creation
|
43
|
+
|
44
|
+
* ADDED: Add OTLP exporter
|
45
|
+
* ADDED: Add support for OTEL_LOG_LEVEL env var
|
46
|
+
* FIXED: Rename Resource labels to attributes
|
47
|
+
* ADDED: Environment variable resource detection
|
48
|
+
* ADDED: BatchSpanProcessor environment variable support
|
49
|
+
* FIXED: Remove semver prefix
|
50
|
+
* FIXED: Docs for array valued attributes
|
51
|
+
* ADDED: Add hex_trace_id and hex_span_id helpers to SpanData
|
52
|
+
* FIXED: Fix ProbabilitySampler
|
53
|
+
* ADDED: Implement GetCorrelations
|
54
|
+
* FIXED: Change default Sampler to ParentOrElse(AlwaysOn)
|
55
|
+
* FIXED: Fix probability sampler
|
data/README.md
CHANGED
@@ -41,7 +41,7 @@ tracer.in_span('foo') do |span|
|
|
41
41
|
# set an attribute
|
42
42
|
span.set_attribute('platform', 'osx')
|
43
43
|
# add an event
|
44
|
-
span.add_event(
|
44
|
+
span.add_event('event in bar')
|
45
45
|
# create bar as child of foo
|
46
46
|
tracer.in_span('bar') do |child_span|
|
47
47
|
# inspect the span
|
data/lib/opentelemetry/sdk.rb
CHANGED
@@ -5,6 +5,7 @@
|
|
5
5
|
# SPDX-License-Identifier: Apache-2.0
|
6
6
|
|
7
7
|
require 'opentelemetry'
|
8
|
+
require 'opentelemetry/common'
|
8
9
|
|
9
10
|
# OpenTelemetry is an open source observability framework, providing a
|
10
11
|
# general-purpose API, SDK, and related tools required for the instrumentation
|
@@ -61,7 +62,7 @@ module OpenTelemetry
|
|
61
62
|
end
|
62
63
|
|
63
64
|
require 'opentelemetry/sdk/configurator'
|
64
|
-
require 'opentelemetry/sdk/
|
65
|
+
require 'opentelemetry/sdk/baggage'
|
65
66
|
require 'opentelemetry/sdk/internal'
|
66
67
|
require 'opentelemetry/sdk/instrumentation_library'
|
67
68
|
require 'opentelemetry/sdk/resources'
|
@@ -0,0 +1,16 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# Copyright 2019 OpenTelemetry Authors
|
4
|
+
#
|
5
|
+
# SPDX-License-Identifier: Apache-2.0
|
6
|
+
|
7
|
+
require 'opentelemetry/sdk/baggage/builder'
|
8
|
+
require 'opentelemetry/sdk/baggage/manager'
|
9
|
+
|
10
|
+
module OpenTelemetry
|
11
|
+
module SDK
|
12
|
+
# Contains operational implementations of the Baggage::Manager
|
13
|
+
module Baggage
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -6,8 +6,8 @@
|
|
6
6
|
|
7
7
|
module OpenTelemetry
|
8
8
|
module SDK
|
9
|
-
module
|
10
|
-
# SDK implementation of
|
9
|
+
module Baggage
|
10
|
+
# SDK implementation of Baggage::Builder
|
11
11
|
class Builder
|
12
12
|
attr_reader :entries
|
13
13
|
|
@@ -15,7 +15,7 @@ module OpenTelemetry
|
|
15
15
|
@entries = entries
|
16
16
|
end
|
17
17
|
|
18
|
-
# Set key-value in the to-be-created
|
18
|
+
# Set key-value in the to-be-created baggage
|
19
19
|
#
|
20
20
|
# @param [String] key The key to store this value under
|
21
21
|
# @param [String] value String value to be stored under key
|
@@ -23,14 +23,14 @@ module OpenTelemetry
|
|
23
23
|
@entries[key] = value.to_s
|
24
24
|
end
|
25
25
|
|
26
|
-
# Removes key from the to-be-created
|
26
|
+
# Removes key from the to-be-created baggage
|
27
27
|
#
|
28
28
|
# @param [String] key The key to remove
|
29
29
|
def remove_value(key)
|
30
30
|
@entries.delete(key)
|
31
31
|
end
|
32
32
|
|
33
|
-
# Clears all
|
33
|
+
# Clears all baggage from the to-be-created baggage
|
34
34
|
def clear
|
35
35
|
@entries.clear
|
36
36
|
end
|
@@ -6,38 +6,38 @@
|
|
6
6
|
|
7
7
|
module OpenTelemetry
|
8
8
|
module SDK
|
9
|
-
module
|
10
|
-
# Manages
|
9
|
+
module Baggage
|
10
|
+
# Manages baggage
|
11
11
|
class Manager
|
12
|
-
|
13
|
-
|
14
|
-
private_constant(:
|
12
|
+
BAGGAGE_KEY = OpenTelemetry::Baggage::Propagation::ContextKeys.baggage_key
|
13
|
+
EMPTY_BAGGAGE = {}.freeze
|
14
|
+
private_constant(:BAGGAGE_KEY, :EMPTY_BAGGAGE)
|
15
15
|
|
16
|
-
# Used to chain modifications to
|
17
|
-
# context with an updated
|
18
|
-
# modification is being made to
|
16
|
+
# Used to chain modifications to baggage. The result is a
|
17
|
+
# context with an updated baggage. If only a single
|
18
|
+
# modification is being made to baggage, use the other
|
19
19
|
# methods on +Manager+, if multiple modifications are being made, use
|
20
20
|
# this one.
|
21
21
|
#
|
22
22
|
# @param [optional Context] context The context to update with with new
|
23
|
-
# modified
|
23
|
+
# modified baggage. Defaults to +Context.current+
|
24
24
|
# @return [Context]
|
25
25
|
def build_context(context: Context.current)
|
26
|
-
builder = Builder.new(
|
26
|
+
builder = Builder.new(baggage_for(context).dup)
|
27
27
|
yield builder
|
28
|
-
context.set_value(
|
28
|
+
context.set_value(BAGGAGE_KEY, builder.entries)
|
29
29
|
end
|
30
30
|
|
31
|
-
# Returns a new context with empty
|
31
|
+
# Returns a new context with empty baggage
|
32
32
|
#
|
33
|
-
# @param [optional Context] context Context to clear
|
33
|
+
# @param [optional Context] context Context to clear baggage from. Defaults
|
34
34
|
# to +Context.current+
|
35
35
|
# @return [Context]
|
36
36
|
def clear(context: Context.current)
|
37
|
-
context.set_value(
|
37
|
+
context.set_value(BAGGAGE_KEY, EMPTY_BAGGAGE)
|
38
38
|
end
|
39
39
|
|
40
|
-
# Returns the corresponding
|
40
|
+
# Returns the corresponding baggage value (or nil) for key
|
41
41
|
#
|
42
42
|
# @param [String] key The lookup key
|
43
43
|
# @param [optional Context] context The context from which to retrieve
|
@@ -45,7 +45,17 @@ module OpenTelemetry
|
|
45
45
|
# Defaults to +Context.current+
|
46
46
|
# @return [String]
|
47
47
|
def value(key, context: Context.current)
|
48
|
-
|
48
|
+
baggage_for(context)[key]
|
49
|
+
end
|
50
|
+
|
51
|
+
# Returns the baggage
|
52
|
+
#
|
53
|
+
# @param [optional Context] context The context from which to retrieve
|
54
|
+
# the baggage.
|
55
|
+
# Defaults to +Context.current+
|
56
|
+
# @return [Hash]
|
57
|
+
def values(context: Context.current)
|
58
|
+
baggage_for(context).dup.freeze
|
49
59
|
end
|
50
60
|
|
51
61
|
# Returns a new context with new key-value pair
|
@@ -56,30 +66,30 @@ module OpenTelemetry
|
|
56
66
|
# value. Defaults to +Context.current+
|
57
67
|
# @return [Context]
|
58
68
|
def set_value(key, value, context: Context.current)
|
59
|
-
|
60
|
-
|
61
|
-
context.set_value(
|
69
|
+
new_baggage = baggage_for(context).dup
|
70
|
+
new_baggage[key] = value
|
71
|
+
context.set_value(BAGGAGE_KEY, new_baggage)
|
62
72
|
end
|
63
73
|
|
64
74
|
# Returns a new context with value at key removed
|
65
75
|
#
|
66
76
|
# @param [String] key The key to remove
|
67
|
-
# @param [optional Context] context The context to remove
|
77
|
+
# @param [optional Context] context The context to remove baggage
|
68
78
|
# from. Defaults to +Context.current+
|
69
79
|
# @return [Context]
|
70
80
|
def remove_value(key, context: Context.current)
|
71
|
-
|
72
|
-
return context unless
|
81
|
+
baggage = baggage_for(context)
|
82
|
+
return context unless baggage.key?(key)
|
73
83
|
|
74
|
-
|
75
|
-
|
76
|
-
context.set_value(
|
84
|
+
new_baggage = baggage.dup
|
85
|
+
new_baggage.delete(key)
|
86
|
+
context.set_value(BAGGAGE_KEY, new_baggage)
|
77
87
|
end
|
78
88
|
|
79
89
|
private
|
80
90
|
|
81
|
-
def
|
82
|
-
context.value(
|
91
|
+
def baggage_for(context)
|
92
|
+
context.value(BAGGAGE_KEY) || EMPTY_BAGGAGE
|
83
93
|
end
|
84
94
|
end
|
85
95
|
end
|
@@ -15,32 +15,53 @@ module OpenTelemetry
|
|
15
15
|
|
16
16
|
private_constant :USE_MODE_UNSPECIFIED, :USE_MODE_ONE, :USE_MODE_ALL
|
17
17
|
|
18
|
-
attr_writer :logger, :http_extractors, :http_injectors, :
|
19
|
-
:
|
18
|
+
attr_writer :logger, :http_extractors, :http_injectors, :text_map_extractors,
|
19
|
+
:text_map_injectors
|
20
20
|
|
21
21
|
def initialize
|
22
22
|
@instrumentation_names = []
|
23
23
|
@instrumentation_config_map = {}
|
24
24
|
@http_extractors = nil
|
25
25
|
@http_injectors = nil
|
26
|
-
@
|
27
|
-
@
|
26
|
+
@text_map_extractors = nil
|
27
|
+
@text_map_injectors = nil
|
28
28
|
@span_processors = []
|
29
29
|
@use_mode = USE_MODE_UNSPECIFIED
|
30
30
|
@resource = Resources::Resource.telemetry_sdk
|
31
31
|
end
|
32
32
|
|
33
33
|
def logger
|
34
|
-
@logger ||=
|
34
|
+
@logger ||= OpenTelemetry.logger
|
35
35
|
end
|
36
36
|
|
37
37
|
# Accepts a resource object that is merged with the default telemetry sdk
|
38
38
|
# resource. The use of this method is optional, and is provided as means
|
39
|
-
# to
|
39
|
+
# to include additional resource information.
|
40
|
+
# If a resource key collision occurs the passed in resource takes priority.
|
40
41
|
#
|
41
42
|
# @param [Resource] new_resource The resource to be merged
|
42
43
|
def resource=(new_resource)
|
43
|
-
@resource =
|
44
|
+
@resource = new_resource.merge(@resource)
|
45
|
+
end
|
46
|
+
|
47
|
+
# Accepts a string that is merged in as the service.name resource attribute.
|
48
|
+
# The most recent assigned value will be used in the event of repeated
|
49
|
+
# calls to this setter.
|
50
|
+
# @param [String] service_name The value to be used as the service name
|
51
|
+
def service_name=(service_name)
|
52
|
+
@resource = OpenTelemetry::SDK::Resources::Resource.create(
|
53
|
+
OpenTelemetry::SDK::Resources::Constants::SERVICE_RESOURCE[:name] => service_name
|
54
|
+
).merge(@resource)
|
55
|
+
end
|
56
|
+
|
57
|
+
# Accepts a string that is merged in as the service.version resource attribute.
|
58
|
+
# The most recent assigned value will be used in the event of repeated
|
59
|
+
# calls to this setter.
|
60
|
+
# @param [String] service_version The value to be used as the service version
|
61
|
+
def service_version=(service_version)
|
62
|
+
@resource = OpenTelemetry::SDK::Resources::Resource.create(
|
63
|
+
OpenTelemetry::SDK::Resources::Constants::SERVICE_RESOURCE[:version] => service_version
|
64
|
+
).merge(@resource)
|
44
65
|
end
|
45
66
|
|
46
67
|
# Install an instrumentation with specificied optional +config+.
|
@@ -72,8 +93,8 @@ module OpenTelemetry
|
|
72
93
|
|
73
94
|
# Add a span processor to the export pipeline
|
74
95
|
#
|
75
|
-
# @param [#on_start, #on_finish, #shutdown] span_processor A span_processor
|
76
|
-
# that satisfies the duck type #on_start, #on_finish, #shutdown. See
|
96
|
+
# @param [#on_start, #on_finish, #shutdown, #force_flush] span_processor A span_processor
|
97
|
+
# that satisfies the duck type #on_start, #on_finish, #shutdown, #force_flush. See
|
77
98
|
# {SimpleSpanProcessor} for an example.
|
78
99
|
def add_span_processor(span_processor)
|
79
100
|
@span_processors << span_processor
|
@@ -89,7 +110,7 @@ module OpenTelemetry
|
|
89
110
|
# - install instrumentation
|
90
111
|
def configure
|
91
112
|
OpenTelemetry.logger = logger
|
92
|
-
OpenTelemetry.
|
113
|
+
OpenTelemetry.baggage = Baggage::Manager.new
|
93
114
|
configure_propagation
|
94
115
|
configure_span_processors
|
95
116
|
OpenTelemetry.tracer_provider = tracer_provider
|
@@ -130,8 +151,8 @@ module OpenTelemetry
|
|
130
151
|
def configure_propagation
|
131
152
|
OpenTelemetry.propagation.http = create_propagator(@http_injectors || default_http_injectors,
|
132
153
|
@http_extractors || default_http_extractors)
|
133
|
-
OpenTelemetry.propagation.text = create_propagator(@
|
134
|
-
@
|
154
|
+
OpenTelemetry.propagation.text = create_propagator(@text_map_injectors || default_text_map_injectors,
|
155
|
+
@text_map_extractors || default_text_map_extractors)
|
135
156
|
end
|
136
157
|
|
137
158
|
def create_propagator(injectors, extractors)
|
@@ -143,27 +164,27 @@ module OpenTelemetry
|
|
143
164
|
end
|
144
165
|
|
145
166
|
def default_http_injectors
|
146
|
-
|
167
|
+
default_text_map_injectors
|
147
168
|
end
|
148
169
|
|
149
170
|
def default_http_extractors
|
150
171
|
[
|
151
172
|
OpenTelemetry::Trace::Propagation::TraceContext.rack_extractor,
|
152
|
-
OpenTelemetry::
|
173
|
+
OpenTelemetry::Baggage::Propagation.rack_extractor
|
153
174
|
]
|
154
175
|
end
|
155
176
|
|
156
|
-
def
|
177
|
+
def default_text_map_injectors
|
157
178
|
[
|
158
|
-
OpenTelemetry::Trace::Propagation::TraceContext.
|
159
|
-
OpenTelemetry::
|
179
|
+
OpenTelemetry::Trace::Propagation::TraceContext.text_map_injector,
|
180
|
+
OpenTelemetry::Baggage::Propagation.text_map_injector
|
160
181
|
]
|
161
182
|
end
|
162
183
|
|
163
|
-
def
|
184
|
+
def default_text_map_extractors
|
164
185
|
[
|
165
|
-
OpenTelemetry::Trace::Propagation::TraceContext.
|
166
|
-
OpenTelemetry::
|
186
|
+
OpenTelemetry::Trace::Propagation::TraceContext.text_map_extractor,
|
187
|
+
OpenTelemetry::Baggage::Propagation.text_map_extractor
|
167
188
|
]
|
168
189
|
end
|
169
190
|
end
|
@@ -79,10 +79,6 @@ module OpenTelemetry
|
|
79
79
|
|
80
80
|
# Attributes defining a computing instance (e.g. host).
|
81
81
|
HOST_RESOURCE = {
|
82
|
-
# Hostname of the host. It contains what the hostname command returns on the
|
83
|
-
# host machine.
|
84
|
-
hostname: 'host.hostname',
|
85
|
-
|
86
82
|
# Unique host id. For Cloud this must be the instance_id assigned by the
|
87
83
|
# cloud provider
|
88
84
|
id: 'host.id',
|
@@ -13,29 +13,40 @@ module OpenTelemetry
|
|
13
13
|
class << self
|
14
14
|
private :new # rubocop:disable Style/AccessModifierDeclarations
|
15
15
|
|
16
|
-
# Returns a newly created {Resource} with the specified
|
16
|
+
# Returns a newly created {Resource} with the specified attributes
|
17
17
|
#
|
18
|
-
# @param [Hash{String => String, Numeric, Boolean}
|
19
|
-
# as
|
20
|
-
# @raise [ArgumentError] If
|
18
|
+
# @param [Hash{String => String, Numeric, Boolean} attributes Hash of key-value pairs to be used
|
19
|
+
# as attributes for this resource
|
20
|
+
# @raise [ArgumentError] If attribute keys and values are not strings
|
21
21
|
# @return [Resource]
|
22
|
-
def create(
|
23
|
-
|
24
|
-
raise ArgumentError, '
|
25
|
-
raise ArgumentError, '
|
22
|
+
def create(attributes = {})
|
23
|
+
frozen_attributes = attributes.each_with_object({}) do |(k, v), memo|
|
24
|
+
raise ArgumentError, 'attribute keys must be strings' unless k.is_a?(String)
|
25
|
+
raise ArgumentError, 'attribute values must be strings, integers, floats, or booleans' unless Internal.valid_value?(v)
|
26
26
|
|
27
27
|
memo[-k] = v.freeze
|
28
28
|
end.freeze
|
29
29
|
|
30
|
-
new(
|
30
|
+
new(frozen_attributes)
|
31
31
|
end
|
32
32
|
|
33
33
|
def telemetry_sdk
|
34
|
-
|
34
|
+
resource_attributes = {
|
35
35
|
Constants::TELEMETRY_SDK_RESOURCE[:name] => 'opentelemetry',
|
36
36
|
Constants::TELEMETRY_SDK_RESOURCE[:language] => 'ruby',
|
37
|
-
Constants::TELEMETRY_SDK_RESOURCE[:version] =>
|
38
|
-
|
37
|
+
Constants::TELEMETRY_SDK_RESOURCE[:version] => OpenTelemetry::SDK::VERSION
|
38
|
+
}
|
39
|
+
|
40
|
+
resource_pairs = ENV['OTEL_RESOURCE_ATTRIBUTES']
|
41
|
+
return create(resource_attributes) unless resource_pairs.is_a?(String)
|
42
|
+
|
43
|
+
resource_pairs.split(',').each do |pair|
|
44
|
+
key, value = pair.split('=')
|
45
|
+
resource_attributes[key] = value
|
46
|
+
end
|
47
|
+
|
48
|
+
resource_attributes.delete_if { |_key, value| value.nil? || value.empty? }
|
49
|
+
create(resource_attributes)
|
39
50
|
end
|
40
51
|
end
|
41
52
|
|
@@ -44,18 +55,18 @@ module OpenTelemetry
|
|
44
55
|
# Users should use the {create} factory method to obtain a {Resource}
|
45
56
|
# instance.
|
46
57
|
#
|
47
|
-
# @param [Hash<String, String>]
|
48
|
-
# key-value pairs to be used as
|
58
|
+
# @param [Hash<String, String>] frozen_attributes Frozen-hash of frozen-string
|
59
|
+
# key-value pairs to be used as attributes for this resource
|
49
60
|
# @return [Resource]
|
50
|
-
def initialize(
|
51
|
-
@
|
61
|
+
def initialize(frozen_attributes)
|
62
|
+
@attributes = frozen_attributes
|
52
63
|
end
|
53
64
|
|
54
|
-
# Returns an enumerator for
|
65
|
+
# Returns an enumerator for attributes of this {Resource}
|
55
66
|
#
|
56
67
|
# @return [Enumerator]
|
57
|
-
def
|
58
|
-
@
|
68
|
+
def attribute_enumerator
|
69
|
+
@attribute_enumerator ||= attributes.to_enum
|
59
70
|
end
|
60
71
|
|
61
72
|
# Returns a new, merged {Resource} by merging the current {Resource} with
|
@@ -68,16 +79,16 @@ module OpenTelemetry
|
|
68
79
|
def merge(other)
|
69
80
|
return self unless other.is_a?(Resource)
|
70
81
|
|
71
|
-
|
82
|
+
merged_attributes = attributes.merge(other.attributes) do |_, old_v, new_v|
|
72
83
|
old_v.empty? ? new_v : old_v
|
73
84
|
end
|
74
85
|
|
75
|
-
self.class.send(:new,
|
86
|
+
self.class.send(:new, merged_attributes.freeze)
|
76
87
|
end
|
77
88
|
|
78
89
|
protected
|
79
90
|
|
80
|
-
attr_reader :
|
91
|
+
attr_reader :attributes
|
81
92
|
end
|
82
93
|
end
|
83
94
|
end
|