opentelemetry-sdk 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (29) hide show
  1. checksums.yaml +7 -0
  2. data/CHANGELOG.md +1 -0
  3. data/LICENSE +201 -0
  4. data/lib/opentelemetry/sdk.rb +18 -0
  5. data/lib/opentelemetry/sdk/internal.rb +32 -0
  6. data/lib/opentelemetry/sdk/resources.rb +15 -0
  7. data/lib/opentelemetry/sdk/resources/resource.rb +75 -0
  8. data/lib/opentelemetry/sdk/trace.rb +24 -0
  9. data/lib/opentelemetry/sdk/trace/config.rb +18 -0
  10. data/lib/opentelemetry/sdk/trace/config/trace_config.rb +77 -0
  11. data/lib/opentelemetry/sdk/trace/export.rb +35 -0
  12. data/lib/opentelemetry/sdk/trace/export/batch_span_processor.rb +149 -0
  13. data/lib/opentelemetry/sdk/trace/export/console_span_exporter.rb +40 -0
  14. data/lib/opentelemetry/sdk/trace/export/in_memory_span_exporter.rb +86 -0
  15. data/lib/opentelemetry/sdk/trace/export/multi_span_exporter.rb +64 -0
  16. data/lib/opentelemetry/sdk/trace/export/noop_span_exporter.rb +42 -0
  17. data/lib/opentelemetry/sdk/trace/export/simple_span_processor.rb +63 -0
  18. data/lib/opentelemetry/sdk/trace/multi_span_processor.rb +51 -0
  19. data/lib/opentelemetry/sdk/trace/noop_span_processor.rb +41 -0
  20. data/lib/opentelemetry/sdk/trace/samplers.rb +106 -0
  21. data/lib/opentelemetry/sdk/trace/samplers/decision.rb +26 -0
  22. data/lib/opentelemetry/sdk/trace/samplers/probability_sampler.rb +74 -0
  23. data/lib/opentelemetry/sdk/trace/samplers/result.rb +54 -0
  24. data/lib/opentelemetry/sdk/trace/span.rb +317 -0
  25. data/lib/opentelemetry/sdk/trace/span_data.rb +32 -0
  26. data/lib/opentelemetry/sdk/trace/tracer.rb +67 -0
  27. data/lib/opentelemetry/sdk/trace/tracer_factory.rb +84 -0
  28. data/lib/opentelemetry/sdk/version.rb +12 -0
  29. metadata +196 -0
@@ -0,0 +1,32 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Copyright 2019 OpenTelemetry Authors
4
+ #
5
+ # SPDX-License-Identifier: Apache-2.0
6
+
7
+ module OpenTelemetry
8
+ module SDK
9
+ # The Trace module contains the OpenTelemetry tracing reference
10
+ # implementation.
11
+ module Trace
12
+ # SpanData is a Struct containing {Span} data for export.
13
+ SpanData = Struct.new(:name,
14
+ :kind,
15
+ :status,
16
+ :parent_span_id,
17
+ :child_count,
18
+ :total_recorded_attributes,
19
+ :total_recorded_events,
20
+ :total_recorded_links,
21
+ :start_timestamp,
22
+ :end_timestamp,
23
+ :attributes,
24
+ :links,
25
+ :events,
26
+ :library_resource,
27
+ :span_id,
28
+ :trace_id,
29
+ :trace_flags)
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,67 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Copyright 2019 OpenTelemetry Authors
4
+ #
5
+ # SPDX-License-Identifier: Apache-2.0
6
+
7
+ module OpenTelemetry
8
+ module SDK
9
+ module Trace
10
+ # {Tracer} is the SDK implementation of {OpenTelemetry::Trace::Tracer}.
11
+ class Tracer < OpenTelemetry::Trace::Tracer
12
+ attr_reader :name
13
+ attr_reader :version
14
+
15
+ # @api private
16
+ #
17
+ # Returns a new {Tracer} instance.
18
+ #
19
+ # @param [String] name Instrumentation package name
20
+ # @param [String] version Instrumentation package version
21
+ #
22
+ # @return [Tracer]
23
+ def initialize(name, version)
24
+ @name = name
25
+ @version = version
26
+ @resource = Resources::Resource.create('name' => name, 'version' => version)
27
+ end
28
+
29
+ def start_root_span(name, attributes: nil, links: nil, start_timestamp: nil, kind: nil, sampling_hint: nil)
30
+ parent_span_context = OpenTelemetry::Trace::SpanContext::INVALID
31
+ start_span(name, with_parent_context: parent_span_context, attributes: attributes, links: links, start_timestamp: start_timestamp, kind: kind, sampling_hint: sampling_hint)
32
+ end
33
+
34
+ def start_span(name, with_parent: nil, with_parent_context: nil, attributes: nil, links: nil, start_timestamp: nil, kind: nil, sampling_hint: nil) # rubocop:disable Metrics/AbcSize
35
+ name ||= 'empty'
36
+
37
+ parent_span_context = with_parent&.context || with_parent_context || current_span.context
38
+ parent_span_context = nil unless parent_span_context.valid?
39
+ parent_span_id = parent_span_context&.span_id
40
+ tracestate = parent_span_context&.tracestate
41
+ trace_id = parent_span_context&.trace_id
42
+ trace_id ||= OpenTelemetry::Trace.generate_trace_id
43
+ span_id = OpenTelemetry::Trace.generate_span_id
44
+ sampler = OpenTelemetry.tracer_factory.active_trace_config.sampler
45
+ result = sampler.call(trace_id: trace_id, span_id: span_id, parent_context: parent_span_context, hint: sampling_hint, links: links, name: name, kind: kind, attributes: attributes)
46
+
47
+ internal_create_span(result, name, kind, trace_id, span_id, parent_span_id, attributes, links, start_timestamp, tracestate)
48
+ end
49
+
50
+ private
51
+
52
+ def internal_create_span(result, name, kind, trace_id, span_id, parent_span_id, attributes, links, start_timestamp, tracestate) # rubocop:disable Metrics/AbcSize
53
+ if result.recording? && !OpenTelemetry.tracer_factory.stopped?
54
+ trace_flags = result.sampled? ? OpenTelemetry::Trace::TraceFlags::SAMPLED : OpenTelemetry::Trace::TraceFlags::DEFAULT
55
+ context = OpenTelemetry::Trace::SpanContext.new(trace_id: trace_id, trace_flags: trace_flags, tracestate: tracestate)
56
+ attributes = attributes&.merge(result.attributes) || result.attributes
57
+ active_trace_config = OpenTelemetry.tracer_factory.active_trace_config
58
+ active_span_processor = OpenTelemetry.tracer_factory.active_span_processor
59
+ Span.new(context, name, kind, parent_span_id, active_trace_config, active_span_processor, attributes, links, start_timestamp || Time.now, @resource)
60
+ else
61
+ OpenTelemetry::Trace::Span.new(span_context: OpenTelemetry::Trace::SpanContext.new(trace_id: trace_id))
62
+ end
63
+ end
64
+ end
65
+ end
66
+ end
67
+ end
@@ -0,0 +1,84 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Copyright 2019 OpenTelemetry Authors
4
+ #
5
+ # SPDX-License-Identifier: Apache-2.0
6
+
7
+ module OpenTelemetry
8
+ module SDK
9
+ module Trace
10
+ # {TracerFactory} is the SDK implementation of {OpenTelemetry::Trace::TracerFactory}.
11
+ class TracerFactory < OpenTelemetry::Trace::TracerFactory
12
+ Key = Struct.new(:name, :version)
13
+ private_constant(:Key)
14
+
15
+ attr_accessor :active_trace_config
16
+ attr_reader :active_span_processor
17
+ attr_reader :stopped
18
+ alias stopped? stopped
19
+
20
+ # Returns a new {TracerFactory} instance.
21
+ #
22
+ # @return [TracerFactory]
23
+ def initialize
24
+ @mutex = Mutex.new
25
+ @registry = {}
26
+ @active_span_processor = NoopSpanProcessor.instance
27
+ @active_trace_config = Config::TraceConfig::DEFAULT
28
+ @registered_span_processors = []
29
+ @stopped = false
30
+ end
31
+
32
+ # Returns a {Tracer} instance.
33
+ #
34
+ # @param [optional String] name Instrumentation package name
35
+ # @param [optional String] version Instrumentation package version
36
+ #
37
+ # @return [Tracer]
38
+ def tracer(name = nil, version = nil)
39
+ name ||= ''
40
+ version ||= ''
41
+ @mutex.synchronize { @registry[Key.new(name, version)] ||= Tracer.new(name, version) }
42
+ end
43
+
44
+ # Attempts to stop all the activity for this {Tracer}. Calls
45
+ # SpanProcessor#shutdown for all registered SpanProcessors.
46
+ #
47
+ # This operation may block until all the Spans are processed. Must be
48
+ # called before turning off the main application to ensure all data are
49
+ # processed and exported.
50
+ #
51
+ # After this is called all the newly created {Span}s will be no-op.
52
+ def shutdown
53
+ @mutex.synchronize do
54
+ if @stopped
55
+ OpenTelemetry.logger.warn('calling Tracer#shutdown multiple times.')
56
+ return
57
+ end
58
+ @active_span_processor.shutdown
59
+ @stopped = true
60
+ end
61
+ end
62
+
63
+ # Adds a new SpanProcessor to this {Tracer}.
64
+ #
65
+ # Any registered processor causes overhead, consider to use an
66
+ # async/batch processor especially for span exporting, and export to
67
+ # multiple backends using the
68
+ # {io.opentelemetry.sdk.trace.export.MultiSpanExporter}.
69
+ #
70
+ # @param span_processor the new SpanProcessor to be added.
71
+ def add_span_processor(span_processor)
72
+ @mutex.synchronize do
73
+ if @stopped
74
+ OpenTelemetry.logger.warn('calling Tracer#add_span_processor after shutdown.')
75
+ return
76
+ end
77
+ @registered_span_processors << span_processor
78
+ @active_span_processor = MultiSpanProcessor.new(@registered_span_processors)
79
+ end
80
+ end
81
+ end
82
+ end
83
+ end
84
+ end
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Copyright 2019 OpenTelemetry Authors
4
+ #
5
+ # SPDX-License-Identifier: Apache-2.0
6
+
7
+ module OpenTelemetry
8
+ module SDK
9
+ ## Current OpenTelemetry version
10
+ VERSION = '0.2.0'
11
+ end
12
+ end
metadata ADDED
@@ -0,0 +1,196 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: opentelemetry-sdk
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.2.0
5
+ platform: ruby
6
+ authors:
7
+ - OpenTelemetry Authors
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2019-11-13 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: opentelemetry-api
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '0.0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '0.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '1.17'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '1.17'
41
+ - !ruby/object:Gem::Dependency
42
+ name: faraday
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '0.13'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '0.13'
55
+ - !ruby/object:Gem::Dependency
56
+ name: minitest
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '5.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '5.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rake
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '12.0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '12.0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rubocop
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: 0.73.0
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: 0.73.0
97
+ - !ruby/object:Gem::Dependency
98
+ name: simplecov
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: '0.17'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: '0.17'
111
+ - !ruby/object:Gem::Dependency
112
+ name: yard
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - "~>"
116
+ - !ruby/object:Gem::Version
117
+ version: '0.9'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - "~>"
123
+ - !ruby/object:Gem::Version
124
+ version: '0.9'
125
+ - !ruby/object:Gem::Dependency
126
+ name: yard-doctest
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - "~>"
130
+ - !ruby/object:Gem::Version
131
+ version: 0.1.6
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - "~>"
137
+ - !ruby/object:Gem::Version
138
+ version: 0.1.6
139
+ description: A stats collection and distributed tracing framework
140
+ email:
141
+ - cncf-opentelemetry-contributors@lists.cncf.io
142
+ executables: []
143
+ extensions: []
144
+ extra_rdoc_files: []
145
+ files:
146
+ - CHANGELOG.md
147
+ - LICENSE
148
+ - lib/opentelemetry/sdk.rb
149
+ - lib/opentelemetry/sdk/internal.rb
150
+ - lib/opentelemetry/sdk/resources.rb
151
+ - lib/opentelemetry/sdk/resources/resource.rb
152
+ - lib/opentelemetry/sdk/trace.rb
153
+ - lib/opentelemetry/sdk/trace/config.rb
154
+ - lib/opentelemetry/sdk/trace/config/trace_config.rb
155
+ - lib/opentelemetry/sdk/trace/export.rb
156
+ - lib/opentelemetry/sdk/trace/export/batch_span_processor.rb
157
+ - lib/opentelemetry/sdk/trace/export/console_span_exporter.rb
158
+ - lib/opentelemetry/sdk/trace/export/in_memory_span_exporter.rb
159
+ - lib/opentelemetry/sdk/trace/export/multi_span_exporter.rb
160
+ - lib/opentelemetry/sdk/trace/export/noop_span_exporter.rb
161
+ - lib/opentelemetry/sdk/trace/export/simple_span_processor.rb
162
+ - lib/opentelemetry/sdk/trace/multi_span_processor.rb
163
+ - lib/opentelemetry/sdk/trace/noop_span_processor.rb
164
+ - lib/opentelemetry/sdk/trace/samplers.rb
165
+ - lib/opentelemetry/sdk/trace/samplers/decision.rb
166
+ - lib/opentelemetry/sdk/trace/samplers/probability_sampler.rb
167
+ - lib/opentelemetry/sdk/trace/samplers/result.rb
168
+ - lib/opentelemetry/sdk/trace/span.rb
169
+ - lib/opentelemetry/sdk/trace/span_data.rb
170
+ - lib/opentelemetry/sdk/trace/tracer.rb
171
+ - lib/opentelemetry/sdk/trace/tracer_factory.rb
172
+ - lib/opentelemetry/sdk/version.rb
173
+ homepage: https://github.com/open-telemetry/opentelemetry-ruby
174
+ licenses:
175
+ - Apache-2.0
176
+ metadata: {}
177
+ post_install_message:
178
+ rdoc_options: []
179
+ require_paths:
180
+ - lib
181
+ required_ruby_version: !ruby/object:Gem::Requirement
182
+ requirements:
183
+ - - ">="
184
+ - !ruby/object:Gem::Version
185
+ version: 2.4.0
186
+ required_rubygems_version: !ruby/object:Gem::Requirement
187
+ requirements:
188
+ - - ">="
189
+ - !ruby/object:Gem::Version
190
+ version: '0'
191
+ requirements: []
192
+ rubygems_version: 3.0.3
193
+ signing_key:
194
+ specification_version: 4
195
+ summary: A stats collection and distributed tracing framework
196
+ test_files: []