opentelemetry-api 0.7.0 → 0.8.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/CHANGELOG.md +11 -0
- data/lib/opentelemetry/trace.rb +37 -2
- data/lib/opentelemetry/trace/link.rb +3 -3
- data/lib/opentelemetry/trace/propagation.rb +0 -1
- data/lib/opentelemetry/trace/propagation/trace_context/text_map_extractor.rb +1 -1
- data/lib/opentelemetry/trace/propagation/trace_context/text_map_injector.rb +2 -2
- data/lib/opentelemetry/trace/propagation/trace_context/trace_parent.rb +2 -2
- data/lib/opentelemetry/trace/status.rb +8 -8
- data/lib/opentelemetry/trace/tracer.rb +3 -36
- data/lib/opentelemetry/version.rb +1 -1
- metadata +7 -4
- data/lib/opentelemetry/trace/propagation/context_keys.rb +0 -35
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: dde8070adb35e548bd260c9a647783d3e240080b58be84712bf8f7dd45bb08a9
|
4
|
+
data.tar.gz: 21b7d0fb202e5ff7f4dc4546b422628494b1a6f683297e66a4fcc2ea93e1b784
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 628d5cb01f3ca3b681648aba7341c7a94035d076546f1ddd64fb2cef69a1620ad20a40e258689da1b096fbdfb447f8bce0b2216ec1ed6cad4a6edd907b13fef0
|
7
|
+
data.tar.gz: aabaabb7a44c0bdf48d55b86bfd04e51b3f837f628c361d457b593600dfb82e05a02976e34265bce49348ba91f39f1086d62e927f52587c047d1470f1eae83eb
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,16 @@
|
|
1
1
|
# Release History: opentelemetry-api
|
2
2
|
|
3
|
+
### v0.8.0 / 2020-10-27
|
4
|
+
|
5
|
+
* BREAKING CHANGE: Move context/span methods to Trace module
|
6
|
+
* BREAKING CHANGE: Remove 'canonical' from status codes
|
7
|
+
* BREAKING CHANGE: Assorted SpanContext fixes
|
8
|
+
|
9
|
+
* ADDED: B3 support
|
10
|
+
* FIXED: Move context/span methods to Trace module
|
11
|
+
* FIXED: Remove 'canonical' from status codes
|
12
|
+
* FIXED: Assorted SpanContext fixes
|
13
|
+
|
3
14
|
### v0.7.0 / 2020-10-07
|
4
15
|
|
5
16
|
* FIXED: Safely navigate span variable during error cases
|
data/lib/opentelemetry/trace.rb
CHANGED
@@ -9,6 +9,12 @@ module OpenTelemetry
|
|
9
9
|
# single logical operation, consolidated across various components of an
|
10
10
|
# application.
|
11
11
|
module Trace
|
12
|
+
extend self
|
13
|
+
|
14
|
+
CURRENT_SPAN_KEY = Context.create_key('current-span')
|
15
|
+
|
16
|
+
private_constant :CURRENT_SPAN_KEY
|
17
|
+
|
12
18
|
# An invalid trace identifier, a 16-byte string with all zero bytes.
|
13
19
|
INVALID_TRACE_ID = ("\0" * 16).b
|
14
20
|
|
@@ -19,7 +25,7 @@ module OpenTelemetry
|
|
19
25
|
# non-zero byte.
|
20
26
|
#
|
21
27
|
# @return [String] a valid trace ID.
|
22
|
-
def
|
28
|
+
def generate_trace_id
|
23
29
|
loop do
|
24
30
|
id = Random::DEFAULT.bytes(16)
|
25
31
|
return id unless id == INVALID_TRACE_ID
|
@@ -30,12 +36,41 @@ module OpenTelemetry
|
|
30
36
|
# non-zero byte.
|
31
37
|
#
|
32
38
|
# @return [String] a valid span ID.
|
33
|
-
def
|
39
|
+
def generate_span_id
|
34
40
|
loop do
|
35
41
|
id = Random::DEFAULT.bytes(8)
|
36
42
|
return id unless id == INVALID_SPAN_ID
|
37
43
|
end
|
38
44
|
end
|
45
|
+
|
46
|
+
# Returns the current span from the current or provided context
|
47
|
+
#
|
48
|
+
# @param [optional Context] context The context to lookup the current
|
49
|
+
# {Span} from. Defaults to Context.current
|
50
|
+
def current_span(context = nil)
|
51
|
+
context ||= Context.current
|
52
|
+
context.value(CURRENT_SPAN_KEY) || Span::INVALID
|
53
|
+
end
|
54
|
+
|
55
|
+
# Returns a context containing the span, derived from the optional parent
|
56
|
+
# context, or the current context if one was not provided.
|
57
|
+
#
|
58
|
+
# @param [optional Context] context The context to use as the parent for
|
59
|
+
# the returned context
|
60
|
+
def context_with_span(span, parent_context: Context.current)
|
61
|
+
parent_context.set_value(CURRENT_SPAN_KEY, span)
|
62
|
+
end
|
63
|
+
|
64
|
+
# Activates/deactivates the Span within the current Context, which makes the "current span"
|
65
|
+
# available implicitly.
|
66
|
+
#
|
67
|
+
# On exit, the Span that was active before calling this method will be reactivated.
|
68
|
+
#
|
69
|
+
# @param [Span] span the span to activate
|
70
|
+
# @yield [span, context] yields span and a context containing the span to the block.
|
71
|
+
def with_span(span)
|
72
|
+
Context.with_value(CURRENT_SPAN_KEY, span) { |c, s| yield s, c }
|
73
|
+
end
|
39
74
|
end
|
40
75
|
end
|
41
76
|
|
@@ -18,7 +18,7 @@ module OpenTelemetry
|
|
18
18
|
# Returns the {SpanContext} for this link
|
19
19
|
#
|
20
20
|
# @return [SpanContext]
|
21
|
-
attr_reader :
|
21
|
+
attr_reader :span_context
|
22
22
|
|
23
23
|
# Returns the frozen attributes for this link.
|
24
24
|
#
|
@@ -33,13 +33,13 @@ module OpenTelemetry
|
|
33
33
|
# frozen during Link initialization.
|
34
34
|
# @return [Link]
|
35
35
|
def initialize(span_context, attributes = nil)
|
36
|
-
@
|
36
|
+
@span_context = span_context
|
37
37
|
@attributes = attributes.freeze || EMPTY_ATTRIBUTES
|
38
38
|
end
|
39
39
|
|
40
40
|
# Returns true if two {Link}s are equal.
|
41
41
|
def ==(other)
|
42
|
-
other.
|
42
|
+
other.span_context == @span_context && other.attributes == @attributes
|
43
43
|
end
|
44
44
|
end
|
45
45
|
end
|
@@ -48,7 +48,7 @@ module OpenTelemetry
|
|
48
48
|
tracestate: tracestate,
|
49
49
|
remote: true)
|
50
50
|
span = Trace::Span.new(span_context: span_context)
|
51
|
-
|
51
|
+
OpenTelemetry::Trace.context_with_span(span)
|
52
52
|
rescue OpenTelemetry::Error
|
53
53
|
context
|
54
54
|
end
|
@@ -36,7 +36,7 @@ module OpenTelemetry
|
|
36
36
|
return carrier unless (span_context = span_context_from(context))
|
37
37
|
|
38
38
|
setter ||= DEFAULT_SETTER
|
39
|
-
setter.call(carrier, @traceparent_key, TraceParent.
|
39
|
+
setter.call(carrier, @traceparent_key, TraceParent.from_span_context(span_context).to_s)
|
40
40
|
setter.call(carrier, @tracestate_key, span_context.tracestate) unless span_context.tracestate.nil?
|
41
41
|
|
42
42
|
carrier
|
@@ -45,7 +45,7 @@ module OpenTelemetry
|
|
45
45
|
private
|
46
46
|
|
47
47
|
def span_context_from(context)
|
48
|
-
context
|
48
|
+
OpenTelemetry::Trace.current_span(context).context
|
49
49
|
end
|
50
50
|
end
|
51
51
|
end
|
@@ -31,9 +31,9 @@ module OpenTelemetry
|
|
31
31
|
|
32
32
|
class << self
|
33
33
|
# Creates a new {TraceParent} from a supplied {Trace::SpanContext}
|
34
|
-
# @param [SpanContext] ctx The context
|
34
|
+
# @param [SpanContext] ctx The span context
|
35
35
|
# @return [TraceParent] a trace parent
|
36
|
-
def
|
36
|
+
def from_span_context(ctx)
|
37
37
|
new(trace_id: ctx.trace_id, span_id: ctx.span_id, flags: ctx.trace_flags)
|
38
38
|
end
|
39
39
|
|
@@ -9,15 +9,15 @@ require 'opentelemetry/trace/util/http_to_status'
|
|
9
9
|
module OpenTelemetry
|
10
10
|
module Trace
|
11
11
|
# Status represents the status of a finished {Span}. It is composed of a
|
12
|
-
#
|
12
|
+
# status code in conjunction with an optional descriptive message.
|
13
13
|
class Status
|
14
14
|
# Convenience utility, not in API spec:
|
15
15
|
extend Util::HttpToStatus
|
16
16
|
|
17
|
-
# Retrieve the
|
17
|
+
# Retrieve the status code of this Status.
|
18
18
|
#
|
19
19
|
# @return [Integer]
|
20
|
-
attr_reader :
|
20
|
+
attr_reader :code
|
21
21
|
|
22
22
|
# Retrieve the description of this Status.
|
23
23
|
#
|
@@ -26,10 +26,10 @@ module OpenTelemetry
|
|
26
26
|
|
27
27
|
# Initialize a Status.
|
28
28
|
#
|
29
|
-
# @param [Integer]
|
29
|
+
# @param [Integer] code One of the status codes below
|
30
30
|
# @param [String] description
|
31
|
-
def initialize(
|
32
|
-
@
|
31
|
+
def initialize(code, description: '')
|
32
|
+
@code = code
|
33
33
|
@description = description
|
34
34
|
end
|
35
35
|
|
@@ -37,10 +37,10 @@ module OpenTelemetry
|
|
37
37
|
#
|
38
38
|
# @return [Boolean]
|
39
39
|
def ok?
|
40
|
-
@
|
40
|
+
@code != ERROR
|
41
41
|
end
|
42
42
|
|
43
|
-
# The following represents the
|
43
|
+
# The following represents the set of status codes of a
|
44
44
|
# finished {Span}
|
45
45
|
|
46
46
|
# The operation completed successfully.
|
@@ -8,28 +8,6 @@ module OpenTelemetry
|
|
8
8
|
module Trace
|
9
9
|
# No-op implementation of Tracer.
|
10
10
|
class Tracer
|
11
|
-
CURRENT_SPAN_KEY = Propagation::ContextKeys.current_span_key
|
12
|
-
|
13
|
-
private_constant :CURRENT_SPAN_KEY
|
14
|
-
|
15
|
-
# Returns the current span from the current or provided context
|
16
|
-
#
|
17
|
-
# @param [optional Context] context The context to lookup the current
|
18
|
-
# {Span} from. Defaults to Context.current
|
19
|
-
def current_span(context = nil)
|
20
|
-
context ||= Context.current
|
21
|
-
context.value(CURRENT_SPAN_KEY) || Span::INVALID
|
22
|
-
end
|
23
|
-
|
24
|
-
# Returns a context containing the span, derived from the optional parent
|
25
|
-
# context, or the current context if one was not provided.
|
26
|
-
#
|
27
|
-
# @param [optional Context] context The context to use as the parent for
|
28
|
-
# the returned context
|
29
|
-
def context_with_span(span, parent_context: Context.current)
|
30
|
-
parent_context.set_value(CURRENT_SPAN_KEY, span)
|
31
|
-
end
|
32
|
-
|
33
11
|
# This is a helper for the default use-case of extending the current trace with a span.
|
34
12
|
#
|
35
13
|
# With this helper:
|
@@ -38,7 +16,7 @@ module OpenTelemetry
|
|
38
16
|
#
|
39
17
|
# Equivalent without helper:
|
40
18
|
#
|
41
|
-
# OpenTelemetry.
|
19
|
+
# OpenTelemetry::Trace.with_span(tracer.start_span('do-the-thing')) do ... end
|
42
20
|
#
|
43
21
|
# On exit, the Span that was active before calling this method will be reactivated. If an
|
44
22
|
# exception occurs during the execution of the provided block, it will be recorded on the
|
@@ -48,7 +26,7 @@ module OpenTelemetry
|
|
48
26
|
def in_span(name, attributes: nil, links: nil, start_timestamp: nil, kind: nil, with_parent: nil)
|
49
27
|
span = nil
|
50
28
|
span = start_span(name, attributes: attributes, links: links, start_timestamp: start_timestamp, kind: kind, with_parent: with_parent)
|
51
|
-
with_span(span) { |s, c| yield s, c }
|
29
|
+
Trace.with_span(span) { |s, c| yield s, c }
|
52
30
|
rescue Exception => e # rubocop:disable Lint/RescueException
|
53
31
|
span&.record_exception(e)
|
54
32
|
span&.status = Status.new(Status::ERROR,
|
@@ -58,17 +36,6 @@ module OpenTelemetry
|
|
58
36
|
span&.finish
|
59
37
|
end
|
60
38
|
|
61
|
-
# Activates/deactivates the Span within the current Context, which makes the "current span"
|
62
|
-
# available implicitly.
|
63
|
-
#
|
64
|
-
# On exit, the Span that was active before calling this method will be reactivated.
|
65
|
-
#
|
66
|
-
# @param [Span] span the span to activate
|
67
|
-
# @yield [span, context] yields span and a context containing the span to the block.
|
68
|
-
def with_span(span)
|
69
|
-
Context.with_value(CURRENT_SPAN_KEY, span) { |c, s| yield s, c }
|
70
|
-
end
|
71
|
-
|
72
39
|
def start_root_span(name, attributes: nil, links: nil, start_timestamp: nil, kind: nil)
|
73
40
|
Span.new
|
74
41
|
end
|
@@ -82,7 +49,7 @@ module OpenTelemetry
|
|
82
49
|
#
|
83
50
|
# @return [Span]
|
84
51
|
def start_span(name, with_parent: nil, attributes: nil, links: nil, start_timestamp: nil, kind: nil)
|
85
|
-
span_context = current_span(with_parent).context
|
52
|
+
span_context = OpenTelemetry::Trace.current_span(with_parent).context
|
86
53
|
|
87
54
|
if span_context.valid?
|
88
55
|
Span.new(span_context: span_context)
|
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: 0.8.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- OpenTelemetry Authors
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-10-
|
11
|
+
date: 2020-10-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: benchmark-ipsa
|
@@ -178,7 +178,6 @@ files:
|
|
178
178
|
- lib/opentelemetry/trace.rb
|
179
179
|
- lib/opentelemetry/trace/link.rb
|
180
180
|
- lib/opentelemetry/trace/propagation.rb
|
181
|
-
- lib/opentelemetry/trace/propagation/context_keys.rb
|
182
181
|
- lib/opentelemetry/trace/propagation/trace_context.rb
|
183
182
|
- lib/opentelemetry/trace/propagation/trace_context/text_map_extractor.rb
|
184
183
|
- lib/opentelemetry/trace/propagation/trace_context/text_map_injector.rb
|
@@ -195,7 +194,11 @@ files:
|
|
195
194
|
homepage: https://github.com/open-telemetry/opentelemetry-ruby
|
196
195
|
licenses:
|
197
196
|
- Apache-2.0
|
198
|
-
metadata:
|
197
|
+
metadata:
|
198
|
+
changelog_uri: https://open-telemetry.github.io/opentelemetry-ruby/opentelemetry-api/v0.8.0/file.CHANGELOG.html
|
199
|
+
source_code_uri: https://github.com/open-telemetry/opentelemetry-ruby/tree/master/api
|
200
|
+
bug_tracker_uri: https://github.com/open-telemetry/opentelemetry-ruby/issues
|
201
|
+
documentation_uri: https://open-telemetry.github.io/opentelemetry-ruby/opentelemetry-api/v0.8.0
|
199
202
|
post_install_message:
|
200
203
|
rdoc_options: []
|
201
204
|
require_paths:
|
@@ -1,35 +0,0 @@
|
|
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
|
-
module Propagation
|
10
|
-
# Contains the keys used to index the current span, or extracted span
|
11
|
-
# context in a {Context} instance
|
12
|
-
module ContextKeys
|
13
|
-
extend self
|
14
|
-
|
15
|
-
EXTRACTED_SPAN_CONTEXT_KEY = Context.create_key('extracted-span-context')
|
16
|
-
CURRENT_SPAN_KEY = Context.create_key('current-span')
|
17
|
-
private_constant :EXTRACTED_SPAN_CONTEXT_KEY, :CURRENT_SPAN_KEY
|
18
|
-
|
19
|
-
# Returns the context key that an extracted span context is indexed by
|
20
|
-
#
|
21
|
-
# @return [Context::Key]
|
22
|
-
def extracted_span_context_key
|
23
|
-
EXTRACTED_SPAN_CONTEXT_KEY
|
24
|
-
end
|
25
|
-
|
26
|
-
# Returns the context key that the current span is indexed by
|
27
|
-
#
|
28
|
-
# @return [Context::Key]
|
29
|
-
def current_span_key
|
30
|
-
CURRENT_SPAN_KEY
|
31
|
-
end
|
32
|
-
end
|
33
|
-
end
|
34
|
-
end
|
35
|
-
end
|