opentelemetry-sdk 1.0.0.rc1 → 1.0.1

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.
@@ -1,205 +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 SDK
9
- module Resources
10
- module Constants
11
- # Attributes describing a service instance.
12
- SERVICE_RESOURCE = {
13
- # Logical name of the service.
14
- name: 'service.name',
15
-
16
- # A namespace for `service.name`.
17
- namespace: 'service.namespace',
18
-
19
- # The string ID of the service instance.
20
- instance_id: 'service.instance.id',
21
-
22
- # The version string of the service API or implementation.
23
- version: 'service.version'
24
- }.freeze
25
-
26
- # Attributes describing the telemetry library.
27
- TELEMETRY_SDK_RESOURCE = {
28
- # The name of the telemetry library.
29
- name: 'telemetry.sdk.name',
30
-
31
- # The language of the telemetry library and of the code instrumented with it.
32
- language: 'telemetry.sdk.language',
33
-
34
- # The version string of the telemetry library
35
- version: 'telemetry.sdk.version'
36
- }.freeze
37
-
38
- # Attributes defining a compute unit (e.g. Container, Process, Lambda
39
- # Function).
40
- CONTAINER_RESOURCE = {
41
- # The container name.
42
- name: 'container.name',
43
-
44
- # The name of the image the container was built on.
45
- image_name: 'container.image.name',
46
-
47
- # The container image tag.
48
- image_tag: 'container.image.tag'
49
- }.freeze
50
-
51
- FAAS_RESOURCE = {
52
- # The name of the function being executed.
53
- name: 'faas.name',
54
-
55
- # The unique name of the function being executed.
56
- id: 'faas.id',
57
-
58
- # The version string of the function being executed.
59
- version: 'faas.version',
60
-
61
- # The execution environment ID as a string.
62
- instance: 'faas.instance'
63
- }.freeze
64
-
65
- # Attributes defining a deployment service (e.g. Kubernetes).
66
- K8S_RESOURCE = {
67
- # The name of the cluster that the pod is running in.
68
- cluster_name: 'k8s.cluster.name',
69
-
70
- # The name of the Node.
71
- node_name: 'k8s.node.name',
72
-
73
- # The UID of the Node.
74
- node_uid: 'k8s.node.uid',
75
-
76
- # The name of the namespace that the pod is running in.
77
- namespace_name: 'k8s.namespace.name',
78
-
79
- # The name of the pod.
80
- pod_name: 'k8s.pod.name',
81
-
82
- # The UID of the Pod.
83
- pod_uid: 'k8s.pod.uid',
84
-
85
- # The name of the Container in a Pod template.
86
- container_name: 'k8s.container.name',
87
-
88
- # The UID of the ReplicaSet.
89
- replicaset_uid: 'k8s.replicaset.uid',
90
-
91
- # The name of the ReplicaSet.
92
- replicaset_name: 'k8s.replicaset.name',
93
-
94
- # The UID of the Deployment.
95
- deployment_uid: 'k8s.deployment.uid',
96
-
97
- # The name of the deployment.
98
- deployment_name: 'k8s.deployment.name',
99
-
100
- # The UID of the StatefulSet.
101
- statefulset_uid: 'k8s.statefulset.uid',
102
-
103
- # The name of the StatefulSet.
104
- statefulset_name: 'k8s.statefulset.name',
105
-
106
- # The UID of the DaemonSet.
107
- daemonset_uid: 'k8s.daemonset.uid',
108
-
109
- # The name of the DaemonSet.
110
- daemonset_name: 'k8s.daemonset.name',
111
-
112
- # The UID of the Job.
113
- job_uid: 'k8s.job.uid',
114
-
115
- # The name of the Job.
116
- job_name: 'k8s.job.name',
117
-
118
- # The UID of the CronJob.
119
- cronjob_uid: 'k8s.cronjob.uid',
120
-
121
- # The name of the CronJob.
122
- cronjob_name: 'k8s.cronjob.name'
123
- }.freeze
124
-
125
- # Attributes defining an operating system process.
126
- PROCESS_RESOURCE = {
127
- # Process identifier (PID).
128
- pid: 'process.pid',
129
-
130
- # The name of the process executable.
131
- executable_name: 'process.executable.name',
132
-
133
- # The full path to the process executable.
134
- executable_path: 'process.executable.path',
135
-
136
- # The command used to launch the process (i.e. the command name).
137
- command: 'process.command',
138
-
139
- # The full command used to launch the process as a single string
140
- # representing the full command.
141
- command_line: 'process.command_line',
142
-
143
- # All the command arguments (including the command/executable itself)
144
- # as received by the process.
145
- command_args: 'process.command_args',
146
-
147
- # The username of the user that owns the process.
148
- owner: 'process.owner'
149
- }.freeze
150
-
151
- # Attributes defining the single (language) runtime instance which is monitored.
152
- PROCESS_RUNTIME_RESOURCE = {
153
- # The name of the runtime of this process.
154
- name: 'process.runtime.name',
155
-
156
- # The version of the runtime of this process, as returned by the runtime
157
- # without modification.
158
- version: 'process.runtime.version',
159
-
160
- # An additional description about the runtime of the process, for example
161
- # a specific vendor customization of the runtime environment.
162
- description: 'process.runtime.description'
163
- }.freeze
164
-
165
- # Attributes defining a computing instance (e.g. host).
166
- HOST_RESOURCE = {
167
- # Unique host id. For Cloud this must be the instance_id assigned by the
168
- # cloud provider
169
- id: 'host.id',
170
-
171
- # Name of the host. It may contain what hostname returns on Unix systems,
172
- # the fully qualified, or a name specified by the user.
173
- name: 'host.name',
174
-
175
- # Type of host. For Cloud this must be the machine type.
176
- type: 'host.type',
177
-
178
- # Name of the VM image or OS install the host was instantiated from.
179
- image_name: 'host.image.name',
180
-
181
- # VM image id. For Cloud, this value is from the provider.
182
- image_id: 'host.image.id',
183
-
184
- # The version string of the VM image.
185
- image_version: 'host.image.version'
186
- }.freeze
187
-
188
- # Attributes defining a running environment (e.g. Cloud, Data Center).
189
- CLOUD_RESOURCE = {
190
- # Name of the cloud provider. Example values are aws, azure, gcp.
191
- provider: 'cloud.provider',
192
-
193
- # The cloud account id used to identify different entities.
194
- account_id: 'cloud.account.id',
195
-
196
- # A specific geographical location where different entities can run.
197
- region: 'cloud.region',
198
-
199
- # Availability zones are a sub set of the region connected through low-latency links.
200
- availability_zone: 'cloud.availability_zone'
201
- }.freeze
202
- end
203
- end
204
- end
205
- end
@@ -1,85 +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 SDK
9
- module Trace
10
- module Config
11
- # Class that holds global trace parameters.
12
- class TraceConfig
13
- # The global default sampler (see {Samplers}).
14
- attr_reader :sampler
15
-
16
- # The global default max number of attributes per {Span}.
17
- attr_reader :max_attributes_count
18
-
19
- # The global default max length of attribute value per {Span}.
20
- attr_reader :max_attributes_length
21
-
22
- # The global default max number of {OpenTelemetry::SDK::Trace::Event}s per {Span}.
23
- attr_reader :max_events_count
24
-
25
- # The global default max number of {OpenTelemetry::Trace::Link} entries per {Span}.
26
- attr_reader :max_links_count
27
-
28
- # The global default max number of attributes per {OpenTelemetry::SDK::Trace::Event}.
29
- attr_reader :max_attributes_per_event
30
-
31
- # The global default max number of attributes per {OpenTelemetry::Trace::Link}.
32
- attr_reader :max_attributes_per_link
33
-
34
- # Returns a {TraceConfig} with the desired values.
35
- #
36
- # @return [TraceConfig] with the desired values.
37
- # @raise [ArgumentError] if any of the max numbers are not positive.
38
- def initialize(sampler: sampler_from_environment(Samplers.parent_based(root: Samplers::ALWAYS_ON)), # rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
39
- max_attributes_count: Integer(ENV.fetch('OTEL_SPAN_ATTRIBUTE_COUNT_LIMIT', 128)),
40
- max_attributes_length: ENV['OTEL_RUBY_SPAN_ATTRIBUTE_VALUE_LENGTH_LIMIT'],
41
- max_events_count: Integer(ENV.fetch('OTEL_SPAN_EVENT_COUNT_LIMIT', 128)),
42
- max_links_count: Integer(ENV.fetch('OTEL_SPAN_LINK_COUNT_LIMIT', 128)),
43
- max_attributes_per_event: max_attributes_count,
44
- max_attributes_per_link: max_attributes_count)
45
- raise ArgumentError, 'max_attributes_count must be positive' unless max_attributes_count.positive?
46
- raise ArgumentError, 'max_attributes_length must not be less than 32' unless max_attributes_length.nil? || Integer(max_attributes_length) >= 32
47
- raise ArgumentError, 'max_events_count must be positive' unless max_events_count.positive?
48
- raise ArgumentError, 'max_links_count must be positive' unless max_links_count.positive?
49
- raise ArgumentError, 'max_attributes_per_event must be positive' unless max_attributes_per_event.positive?
50
- raise ArgumentError, 'max_attributes_per_link must be positive' unless max_attributes_per_link.positive?
51
-
52
- @sampler = sampler
53
- @max_attributes_count = max_attributes_count
54
- @max_attributes_length = max_attributes_length.nil? ? nil : Integer(max_attributes_length)
55
- @max_events_count = max_events_count
56
- @max_links_count = max_links_count
57
- @max_attributes_per_event = max_attributes_per_event
58
- @max_attributes_per_link = max_attributes_per_link
59
- end
60
-
61
- # TODO: from_proto
62
- private
63
-
64
- def sampler_from_environment(default_sampler) # rubocop:disable Metrics/CyclomaticComplexity
65
- case ENV['OTEL_TRACES_SAMPLER']
66
- when 'always_on' then Samplers::ALWAYS_ON
67
- when 'always_off' then Samplers::ALWAYS_OFF
68
- when 'traceidratio' then Samplers.trace_id_ratio_based(Float(ENV.fetch('OTEL_TRACES_SAMPLER_ARG', 1.0)))
69
- when 'parentbased_always_on' then Samplers.parent_based(root: Samplers::ALWAYS_ON)
70
- when 'parentbased_always_off' then Samplers.parent_based(root: Samplers::ALWAYS_OFF)
71
- when 'parentbased_traceidratio' then Samplers.parent_based(root: Samplers.trace_id_ratio_based(Float(ENV.fetch('OTEL_TRACES_SAMPLER_ARG', 1.0))))
72
- else default_sampler
73
- end
74
- rescue StandardError => e
75
- OpenTelemetry.handle_error(exception: e, message: "installing default sampler #{default_sampler.description}")
76
- default_sampler
77
- end
78
-
79
- # The default {TraceConfig}.
80
- DEFAULT = new
81
- end
82
- end
83
- end
84
- end
85
- end
@@ -1,18 +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 SDK
9
- module Trace
10
- # The Config module contains the configuration logic for the
11
- # OpenTelemetry SDK.
12
- module Config
13
- end
14
- end
15
- end
16
- end
17
-
18
- require 'opentelemetry/sdk/trace/config/trace_config'
@@ -1,76 +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 SDK
9
- module Trace
10
- module Export
11
- # Implementation of the SpanExporter duck type that simply forwards all
12
- # received spans to a collection of SpanExporters.
13
- #
14
- # Can be used to export to multiple backends using the same
15
- # SpanProcessor like a {SimpleSpanProcessor} or a
16
- # {BatchSpanProcessor}.
17
- class MultiSpanExporter
18
- def initialize(span_exporters)
19
- @span_exporters = span_exporters.clone.freeze
20
- end
21
-
22
- # Called to export sampled {Span}s.
23
- #
24
- # @param [Enumerable<Span>] spans the list of sampled {Span}s to be
25
- # exported.
26
- # @param [optional Numeric] timeout An optional timeout in seconds.
27
- # @return [Integer] the result of the export.
28
- def export(spans, timeout: nil)
29
- start_time = OpenTelemetry::Common::Utilities.timeout_timestamp
30
- results = @span_exporters.map do |span_exporter|
31
- span_exporter.export(spans, timeout: OpenTelemetry::Common::Utilities.maybe_timeout(timeout, start_time))
32
- rescue => e # rubocop:disable Style/RescueStandardError
33
- OpenTelemetry.logger.warn("exception raised by export - #{e}")
34
- FAILURE
35
- end
36
- results.uniq.max || SUCCESS
37
- end
38
-
39
- # Called when {TracerProvider#force_flush} is called, if this exporter is
40
- # registered to a {TracerProvider} object.
41
- #
42
- # @param [optional Numeric] timeout An optional timeout in seconds.
43
- # @return [Integer] SUCCESS if no error occurred, FAILURE if a
44
- # non-specific failure occurred, TIMEOUT if a timeout occurred.
45
- def force_flush(timeout: nil)
46
- start_time = OpenTelemetry::Common::Utilities.timeout_timestamp
47
- results = @span_exporters.map do |processor|
48
- remaining_timeout = OpenTelemetry::Common::Utilities.maybe_timeout(timeout, start_time)
49
- return TIMEOUT if remaining_timeout&.zero?
50
-
51
- processor.force_flush(timeout: remaining_timeout)
52
- end
53
- results.uniq.max || SUCCESS
54
- end
55
-
56
- # Called when {TracerProvider#shutdown} is called, if this exporter is
57
- # registered to a {TracerProvider} object.
58
- #
59
- # @param [optional Numeric] timeout An optional timeout in seconds.
60
- # @return [Integer] SUCCESS if no error occurred, FAILURE if a
61
- # non-specific failure occurred, TIMEOUT if a timeout occurred.
62
- def shutdown(timeout: nil)
63
- start_time = OpenTelemetry::Common::Utilities.timeout_timestamp
64
- results = @span_exporters.map do |processor|
65
- remaining_timeout = OpenTelemetry::Common::Utilities.maybe_timeout(timeout, start_time)
66
- return TIMEOUT if remaining_timeout&.zero?
67
-
68
- processor.shutdown(timeout: remaining_timeout)
69
- end
70
- results.uniq.max || SUCCESS
71
- end
72
- end
73
- end
74
- end
75
- end
76
- end
@@ -1,86 +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 SDK
9
- module Trace
10
- # Implementation of the SpanProcessor duck type that simply forwards all
11
- # received events to a list of SpanProcessors.
12
- class MultiSpanProcessor
13
- # Creates a new {MultiSpanProcessor}.
14
- #
15
- # @param [Enumerable<SpanProcessor>] span_processors a collection of
16
- # SpanProcessors.
17
- # @return [MultiSpanProcessor]
18
- def initialize(span_processors)
19
- @span_processors = span_processors.to_a.freeze
20
- end
21
-
22
- # Called when a {Span} is started, if the {Span#recording?}
23
- # returns true.
24
- #
25
- # This method is called synchronously on the execution thread, should
26
- # not throw or block the execution thread.
27
- #
28
- # @param [Span] span the {Span} that just started.
29
- # @param [Context] parent_context the parent {Context} of the newly
30
- # started span.
31
- def on_start(span, parent_context)
32
- @span_processors.each { |processor| processor.on_start(span, parent_context) }
33
- end
34
-
35
- # Called when a {Span} is ended, if the {Span#recording?}
36
- # returns true.
37
- #
38
- # This method is called synchronously on the execution thread, should
39
- # not throw or block the execution thread.
40
- #
41
- # @param [Span] span the {Span} that just ended.
42
- def on_finish(span)
43
- @span_processors.each { |processor| processor.on_finish(span) }
44
- end
45
-
46
- # Export all ended spans to the configured `Exporter` that have not yet
47
- # been exported.
48
- #
49
- # This method should only be called in cases where it is absolutely
50
- # necessary, such as when using some FaaS providers that may suspend
51
- # the process after an invocation, but before the `Processor` exports
52
- # the completed spans.
53
- #
54
- # @param [optional Numeric] timeout An optional timeout in seconds.
55
- # @return [Integer] Export::SUCCESS if no error occurred, Export::FAILURE if
56
- # a non-specific failure occurred, Export::TIMEOUT if a timeout occurred.
57
- def force_flush(timeout: nil)
58
- start_time = OpenTelemetry::Common::Utilities.timeout_timestamp
59
- results = @span_processors.map do |processor|
60
- remaining_timeout = OpenTelemetry::Common::Utilities.maybe_timeout(timeout, start_time)
61
- return Export::TIMEOUT if remaining_timeout&.zero?
62
-
63
- processor.force_flush(timeout: remaining_timeout)
64
- end
65
- results.uniq.max
66
- end
67
-
68
- # Called when {TracerProvider#shutdown} is called.
69
- #
70
- # @param [optional Numeric] timeout An optional timeout in seconds.
71
- # @return [Integer] Export::SUCCESS if no error occurred, Export::FAILURE if
72
- # a non-specific failure occurred, Export::TIMEOUT if a timeout occurred.
73
- def shutdown(timeout: nil)
74
- start_time = OpenTelemetry::Common::Utilities.timeout_timestamp
75
- results = @span_processors.map do |processor|
76
- remaining_timeout = OpenTelemetry::Common::Utilities.maybe_timeout(timeout, start_time)
77
- return Export::TIMEOUT if remaining_timeout&.zero?
78
-
79
- processor.shutdown(timeout: remaining_timeout)
80
- end
81
- results.uniq.max
82
- end
83
- end
84
- end
85
- end
86
- end