opentelemetry-api 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (33) hide show
  1. checksums.yaml +7 -0
  2. data/CHANGELOG.md +1 -0
  3. data/LICENSE +201 -0
  4. data/lib/opentelemetry.rb +43 -0
  5. data/lib/opentelemetry/context.rb +31 -0
  6. data/lib/opentelemetry/distributed_context.rb +19 -0
  7. data/lib/opentelemetry/distributed_context/distributed_context.rb +24 -0
  8. data/lib/opentelemetry/distributed_context/entry.rb +66 -0
  9. data/lib/opentelemetry/distributed_context/manager.rb +12 -0
  10. data/lib/opentelemetry/distributed_context/propagation.rb +19 -0
  11. data/lib/opentelemetry/distributed_context/propagation/binary_format.rb +26 -0
  12. data/lib/opentelemetry/distributed_context/propagation/text_format.rb +76 -0
  13. data/lib/opentelemetry/distributed_context/propagation/trace_parent.rb +124 -0
  14. data/lib/opentelemetry/error.rb +9 -0
  15. data/lib/opentelemetry/internal.rb +22 -0
  16. data/lib/opentelemetry/metrics.rb +16 -0
  17. data/lib/opentelemetry/metrics/handles.rb +54 -0
  18. data/lib/opentelemetry/metrics/instruments.rb +156 -0
  19. data/lib/opentelemetry/metrics/meter.rb +109 -0
  20. data/lib/opentelemetry/metrics/meter_factory.rb +22 -0
  21. data/lib/opentelemetry/trace.rb +53 -0
  22. data/lib/opentelemetry/trace/event.rb +45 -0
  23. data/lib/opentelemetry/trace/link.rb +45 -0
  24. data/lib/opentelemetry/trace/sampling_hint.rb +22 -0
  25. data/lib/opentelemetry/trace/span.rb +137 -0
  26. data/lib/opentelemetry/trace/span_context.rb +56 -0
  27. data/lib/opentelemetry/trace/span_kind.rb +35 -0
  28. data/lib/opentelemetry/trace/status.rb +109 -0
  29. data/lib/opentelemetry/trace/trace_flags.rb +50 -0
  30. data/lib/opentelemetry/trace/tracer.rb +69 -0
  31. data/lib/opentelemetry/trace/tracer_factory.rb +45 -0
  32. data/lib/opentelemetry/version.rb +10 -0
  33. metadata +200 -0
@@ -0,0 +1,35 @@
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 Trace
9
+ # Type of span. Can be used to specify additional relationships between spans in addition to a
10
+ # parent/child relationship. For API ergonomics, use of the symbols rather than the constants
11
+ # may be preferred. For example:
12
+ #
13
+ # span = tracer.start_span('op', kind: :client)
14
+ module SpanKind
15
+ # Default value. Indicates that the span is used internally.
16
+ INTERNAL = :internal
17
+
18
+ # Indicates that the span covers server-side handling of an RPC or other remote request.
19
+ SERVER = :server
20
+
21
+ # Indicates that the span covers the client-side wrapper around an RPC or other remote request.
22
+ CLIENT = :client
23
+
24
+ # Indicates that the span describes producer sending a message to a broker. Unlike client and
25
+ # server, there is no direct critical path latency relationship between producer and consumer
26
+ # spans.
27
+ PRODUCER = :producer
28
+
29
+ # Indicates that the span describes consumer recieving a message from a broker. Unlike client
30
+ # and server, there is no direct critical path latency relationship between producer and
31
+ # consumer spans.
32
+ CONSUMER = :consumer
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,109 @@
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 Trace
9
+ # Status represents the status of a finished {Span}. It is composed of a
10
+ # canonical code in conjunction with an optional descriptive message.
11
+ class Status
12
+ # Retrieve the canonical code of this Status.
13
+ #
14
+ # @return [Integer]
15
+ attr_reader :canonical_code
16
+
17
+ # Retrieve the description of this Status.
18
+ #
19
+ # @return [String]
20
+ attr_reader :description
21
+
22
+ # Initialize a Status.
23
+ #
24
+ # @param [Integer] canonical_code One of the standard GRPC codes: https://github.com/grpc/grpc/blob/master/doc/statuscodes.md
25
+ # @param [String] description
26
+ def initialize(canonical_code, description: '')
27
+ @canonical_code = canonical_code
28
+ @description = description
29
+ end
30
+
31
+ # Returns false if this {Status} represents an error, else returns true.
32
+ #
33
+ # @return [Boolean]
34
+ def ok?
35
+ @canonical_code == OK
36
+ end
37
+
38
+ # The following represents the canonical set of status codes of a
39
+ # finished {Span}, following the standard GRPC codes:
40
+ # https://github.com/grpc/grpc/blob/master/doc/statuscodes.md
41
+
42
+ # The operation completed successfully.
43
+ OK = 0
44
+
45
+ # The operation was cancelled (typically by the caller).
46
+ CANCELLED = 1
47
+
48
+ # An unknown error.
49
+ UNKNOWN_ERROR = 2
50
+
51
+ # Client specified an invalid argument. Note that this differs from
52
+ # {FAILED_PRECONDITION}. {INVALID_ARGUMENT} indicates arguments that are
53
+ # problematic regardless of the state of the system.
54
+ INVALID_ARGUMENT = 3
55
+
56
+ # Deadline expired before operation could complete. For operations that
57
+ # change the state of the system, this error may be returned even if the
58
+ # operation has completed successfully.
59
+ DEADLINE_EXCEEDED = 4
60
+
61
+ # Some requested entity (e.g., file or directory) was not found.
62
+ NOT_FOUND = 5
63
+
64
+ # Some entity that we attempted to create (e.g., file or directory)
65
+ # already exists.
66
+ ALREADY_EXISTS = 6
67
+
68
+ # The caller does not have permission to execute the specified operation.
69
+ # {PERMISSION_DENIED} must not be used if the caller cannot be identified
70
+ # (use {UNAUTHENTICATED} instead for those errors).
71
+ PERMISSION_DENIED = 7
72
+
73
+ # Some resource has been exhausted, perhaps a per-user quota, or perhaps
74
+ # the entire file system is out of space.
75
+ RESOURCE_EXHAUSTED = 8
76
+
77
+ # Operation was rejected because the system is not in a state required
78
+ # for the operation's execution.
79
+ FAILED_PRECONDITION = 9
80
+
81
+ # The operation was aborted, typically due to a concurrency issue like
82
+ # sequencer check failures, transaction aborts, etc.
83
+ ABORTED = 10
84
+
85
+ # Operation was attempted past the valid range. E.g., seeking or reading
86
+ # past end of file. Unlike {INVALID_ARGUMENT}, this error indicates a
87
+ # problem that may be fixed if the system state changes.
88
+ OUT_OF_RANGE = 11
89
+
90
+ # Operation is not implemented or not supported/enabled in this service.
91
+ UNIMPLEMENTED = 12
92
+
93
+ # Internal errors. Means some invariants expected by underlying system
94
+ # has been broken.
95
+ INTERNAL_ERROR = 13
96
+
97
+ # The service is currently unavailable. This is a most likely a transient
98
+ # condition and may be corrected by retrying with a backoff.
99
+ UNAVAILABLE = 14
100
+
101
+ # Unrecoverable data loss or corruption.
102
+ DATA_LOSS = 15
103
+
104
+ # The request does not have valid authentication credentials for the
105
+ # operation.
106
+ UNAUTHENTICATED = 16
107
+ end
108
+ end
109
+ end
@@ -0,0 +1,50 @@
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 Trace
9
+ # TraceFlags contain details about the trace. Unlike Tracestate values,
10
+ # TraceFlags are present in all traces. Currently, the only TraceFlag is a
11
+ # boolean {sampled?} {https://www.w3.org/TR/trace-context/#trace-flags flag}.
12
+ class TraceFlags
13
+ class << self
14
+ private :new # rubocop:disable Style/AccessModifierDeclarations
15
+
16
+ # Returns a newly created {TraceFlags} with the specified flags.
17
+ #
18
+ # @param [Integer] flags 8-bit byte of bit flags
19
+ # @return [TraceFlags]
20
+ def from_byte(flags)
21
+ flags = 0 unless flags & ~0xFF == 0 # rubocop:disable Style/NumericPredicate
22
+
23
+ new(flags)
24
+ end
25
+ end
26
+
27
+ # @api private
28
+ # The constructor is private and only for use internally by the class.
29
+ # Users should use the {from_byte} factory method to obtain a {TraceFlags}
30
+ # instance.
31
+ #
32
+ # @param [Integer] flags 8-bit byte of bit flags
33
+ # @return [TraceFlags]
34
+ def initialize(flags)
35
+ @flags = flags
36
+ end
37
+
38
+ # Returns whether the caller may have recorded trace data. When false,
39
+ # the caller did not record trace data out-of-band.
40
+ #
41
+ # @return [Boolean]
42
+ def sampled?
43
+ (@flags & 1) != 0
44
+ end
45
+
46
+ DEFAULT = from_byte(0)
47
+ SAMPLED = from_byte(1)
48
+ end
49
+ end
50
+ end
@@ -0,0 +1,69 @@
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 Trace
9
+ # No-op implementation of Tracer.
10
+ class Tracer
11
+ CONTEXT_SPAN_KEY = :__span__
12
+ private_constant(:CONTEXT_SPAN_KEY)
13
+
14
+ def current_span
15
+ Context.get(CONTEXT_SPAN_KEY) || Span::INVALID
16
+ end
17
+
18
+ # This is a helper for the default use-case of extending the current trace with a span.
19
+ #
20
+ # With this helper:
21
+ #
22
+ # OpenTelemetry.tracer.in_span('do-the-thing') do ... end
23
+ #
24
+ # Equivalent without helper:
25
+ #
26
+ # OpenTelemetry.tracer.with_span(OpenTelemetry.tracer.start_span('do-the-thing')) do ... end
27
+ #
28
+ # On exit, the Span that was active before calling this method will be reactivated.
29
+ def in_span(name, attributes: nil, links: nil, start_timestamp: nil, kind: nil, sampling_hint: nil, with_parent: nil, with_parent_context: nil)
30
+ span = start_span(name, attributes: attributes, links: links, start_timestamp: start_timestamp, kind: kind, sampling_hint: sampling_hint, with_parent: with_parent, with_parent_context: with_parent_context)
31
+ with_span(span) { |s| yield s }
32
+ ensure
33
+ span.finish
34
+ end
35
+
36
+ # Activates/deactivates the Span within the current Context, which makes the "current span"
37
+ # available implicitly.
38
+ #
39
+ # On exit, the Span that was active before calling this method will be reactivated.
40
+ def with_span(span)
41
+ Context.with(CONTEXT_SPAN_KEY, span) { |s| yield s }
42
+ end
43
+
44
+ def start_root_span(name, attributes: nil, links: nil, start_timestamp: nil, kind: nil, sampling_hint: nil)
45
+ Span.new
46
+ end
47
+
48
+ # Used when a caller wants to manage the activation/deactivation and lifecycle of
49
+ # the Span and its parent manually.
50
+ #
51
+ # Parent context can be either passed explicitly, or inferred from currently activated span.
52
+ #
53
+ # @param [optional Span] with_parent Explicitly managed parent Span, overrides
54
+ # +with_parent_context+.
55
+ # @param [optional SpanContext] with_parent_context Explicitly managed. Overridden by
56
+ # +with_parent+.
57
+ #
58
+ # @return [Span]
59
+ def start_span(name, with_parent: nil, with_parent_context: nil, attributes: nil, links: nil, start_timestamp: nil, kind: nil, sampling_hint: nil)
60
+ span_context = with_parent&.context || with_parent_context || current_span.context
61
+ if span_context.valid?
62
+ Span.new(span_context: span_context)
63
+ else
64
+ Span.new
65
+ end
66
+ end
67
+ end
68
+ end
69
+ end
@@ -0,0 +1,45 @@
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 Trace
9
+ # No-op implementation of a tracer factory.
10
+ class TracerFactory
11
+ HTTP_TEXT_FORMAT = DistributedContext::Propagation::TextFormat.new(
12
+ traceparent_header_key: 'traceparent',
13
+ tracestate_header_key: 'tracestate'
14
+ )
15
+ RACK_HTTP_TEXT_FORMAT = DistributedContext::Propagation::TextFormat.new(
16
+ traceparent_header_key: 'HTTP_TRACEPARENT',
17
+ tracestate_header_key: 'HTTP_TRACESTATE'
18
+ )
19
+ BINARY_FORMAT = DistributedContext::Propagation::BinaryFormat.new
20
+ private_constant(:HTTP_TEXT_FORMAT, :RACK_HTTP_TEXT_FORMAT, :BINARY_FORMAT)
21
+
22
+ # Returns a {Tracer} instance.
23
+ #
24
+ # @param [optional String] name Instrumentation package name
25
+ # @param [optional String] version Instrumentation package version
26
+ #
27
+ # @return [Tracer]
28
+ def tracer(name = nil, version = nil)
29
+ @tracer ||= Tracer.new
30
+ end
31
+
32
+ def binary_format
33
+ BINARY_FORMAT
34
+ end
35
+
36
+ def http_text_format
37
+ HTTP_TEXT_FORMAT
38
+ end
39
+
40
+ def rack_http_text_format
41
+ RACK_HTTP_TEXT_FORMAT
42
+ end
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Copyright 2019 OpenTelemetry Authors
4
+ #
5
+ # SPDX-License-Identifier: Apache-2.0
6
+
7
+ module OpenTelemetry
8
+ ## Current OpenTelemetry version
9
+ VERSION = '0.2.0'
10
+ end
metadata ADDED
@@ -0,0 +1,200 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: opentelemetry-api
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: benchmark-ipsa
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 0.2.0
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 0.2.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.rb
149
+ - lib/opentelemetry/context.rb
150
+ - lib/opentelemetry/distributed_context.rb
151
+ - lib/opentelemetry/distributed_context/distributed_context.rb
152
+ - lib/opentelemetry/distributed_context/entry.rb
153
+ - lib/opentelemetry/distributed_context/manager.rb
154
+ - lib/opentelemetry/distributed_context/propagation.rb
155
+ - lib/opentelemetry/distributed_context/propagation/binary_format.rb
156
+ - lib/opentelemetry/distributed_context/propagation/text_format.rb
157
+ - lib/opentelemetry/distributed_context/propagation/trace_parent.rb
158
+ - lib/opentelemetry/error.rb
159
+ - lib/opentelemetry/internal.rb
160
+ - lib/opentelemetry/metrics.rb
161
+ - lib/opentelemetry/metrics/handles.rb
162
+ - lib/opentelemetry/metrics/instruments.rb
163
+ - lib/opentelemetry/metrics/meter.rb
164
+ - lib/opentelemetry/metrics/meter_factory.rb
165
+ - lib/opentelemetry/trace.rb
166
+ - lib/opentelemetry/trace/event.rb
167
+ - lib/opentelemetry/trace/link.rb
168
+ - lib/opentelemetry/trace/sampling_hint.rb
169
+ - lib/opentelemetry/trace/span.rb
170
+ - lib/opentelemetry/trace/span_context.rb
171
+ - lib/opentelemetry/trace/span_kind.rb
172
+ - lib/opentelemetry/trace/status.rb
173
+ - lib/opentelemetry/trace/trace_flags.rb
174
+ - lib/opentelemetry/trace/tracer.rb
175
+ - lib/opentelemetry/trace/tracer_factory.rb
176
+ - lib/opentelemetry/version.rb
177
+ homepage: https://github.com/open-telemetry/opentelemetry-ruby
178
+ licenses:
179
+ - Apache-2.0
180
+ metadata: {}
181
+ post_install_message:
182
+ rdoc_options: []
183
+ require_paths:
184
+ - lib
185
+ required_ruby_version: !ruby/object:Gem::Requirement
186
+ requirements:
187
+ - - ">="
188
+ - !ruby/object:Gem::Version
189
+ version: 2.4.0
190
+ required_rubygems_version: !ruby/object:Gem::Requirement
191
+ requirements:
192
+ - - ">="
193
+ - !ruby/object:Gem::Version
194
+ version: '0'
195
+ requirements: []
196
+ rubygems_version: 3.0.3
197
+ signing_key:
198
+ specification_version: 4
199
+ summary: A stats collection and distributed tracing framework
200
+ test_files: []