opentelemetry-api 0.7.0 → 0.12.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 +31 -0
- data/LICENSE +1 -1
- data/lib/opentelemetry-api.rb +1 -1
- data/lib/opentelemetry.rb +16 -2
- data/lib/opentelemetry/baggage.rb +1 -1
- data/lib/opentelemetry/baggage/builder.rb +1 -1
- data/lib/opentelemetry/baggage/manager.rb +1 -1
- data/lib/opentelemetry/baggage/propagation.rb +1 -1
- data/lib/opentelemetry/baggage/propagation/context_keys.rb +1 -1
- data/lib/opentelemetry/baggage/propagation/text_map_extractor.rb +1 -1
- data/lib/opentelemetry/baggage/propagation/text_map_injector.rb +1 -1
- data/lib/opentelemetry/context.rb +1 -1
- data/lib/opentelemetry/context/key.rb +1 -1
- data/lib/opentelemetry/context/propagation.rb +1 -1
- data/lib/opentelemetry/context/propagation/composite_propagator.rb +1 -1
- data/lib/opentelemetry/context/propagation/default_getter.rb +1 -1
- data/lib/opentelemetry/context/propagation/default_setter.rb +1 -1
- data/lib/opentelemetry/context/propagation/noop_extractor.rb +1 -1
- data/lib/opentelemetry/context/propagation/noop_injector.rb +1 -1
- data/lib/opentelemetry/context/propagation/propagation.rb +1 -1
- data/lib/opentelemetry/context/propagation/propagator.rb +1 -1
- data/lib/opentelemetry/error.rb +1 -1
- data/lib/opentelemetry/instrumentation.rb +1 -1
- data/lib/opentelemetry/instrumentation/base.rb +1 -1
- data/lib/opentelemetry/instrumentation/registry.rb +2 -3
- data/lib/opentelemetry/metrics.rb +1 -1
- data/lib/opentelemetry/metrics/handles.rb +1 -1
- data/lib/opentelemetry/metrics/instruments.rb +1 -1
- data/lib/opentelemetry/metrics/meter.rb +1 -1
- data/lib/opentelemetry/metrics/meter_provider.rb +1 -1
- data/lib/opentelemetry/trace.rb +39 -3
- data/lib/opentelemetry/trace/link.rb +4 -4
- data/lib/opentelemetry/trace/propagation.rb +1 -2
- data/lib/opentelemetry/trace/propagation/trace_context.rb +1 -1
- data/lib/opentelemetry/trace/propagation/trace_context/text_map_extractor.rb +4 -6
- data/lib/opentelemetry/trace/propagation/trace_context/text_map_injector.rb +4 -4
- data/lib/opentelemetry/trace/propagation/trace_context/trace_parent.rb +3 -3
- data/lib/opentelemetry/trace/span.rb +1 -1
- data/lib/opentelemetry/trace/span_context.rb +3 -3
- data/lib/opentelemetry/trace/span_kind.rb +1 -1
- data/lib/opentelemetry/trace/status.rb +9 -9
- data/lib/opentelemetry/trace/trace_flags.rb +1 -1
- data/lib/opentelemetry/trace/tracer.rb +4 -37
- data/lib/opentelemetry/trace/tracer_provider.rb +1 -1
- data/lib/opentelemetry/trace/tracestate.rb +158 -0
- data/lib/opentelemetry/trace/util/http_to_status.rb +1 -1
- data/lib/opentelemetry/version.rb +2 -2
- metadata +8 -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: c7c58fd79dce24997ec350919d59c831940d6604acea611b2a0be72177f0b692
|
4
|
+
data.tar.gz: a0c08af587e1002da839ff0f4d9860f528256fbb3dbba3b885c0494f06c71b95
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3988fc0200883dadf62a8623d6c727d032c6648c2bc4e860cac0e3f7ae3e8bacc6a0c8a05638272cbf24d254cfaf3723bfdb2564e306bb99e029d1f88860d5d4
|
7
|
+
data.tar.gz: 183d0203693f3585a153992582aee24e7df9ce3afc66ba536dd3dcfc7295ca00226b3cb02f468fa9ce17fce2dc6b5a54523c5cfba4b79c87d8f879255d6a34e1
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,36 @@
|
|
1
1
|
# Release History: opentelemetry-api
|
2
2
|
|
3
|
+
### v0.12.0 / 2020-12-24
|
4
|
+
|
5
|
+
* ADDED: Structured error handling
|
6
|
+
|
7
|
+
### v0.11.0 / 2020-12-11
|
8
|
+
|
9
|
+
* BREAKING CHANGE: Implement tracestate
|
10
|
+
|
11
|
+
* ADDED: Implement tracestate
|
12
|
+
* FIXED: Missing white space from install messages
|
13
|
+
* FIXED: Copyright comments to not reference year
|
14
|
+
|
15
|
+
### v0.10.0 / 2020-12-03
|
16
|
+
|
17
|
+
* (No significant changes)
|
18
|
+
|
19
|
+
### v0.9.0 / 2020-11-27
|
20
|
+
|
21
|
+
* (No significant changes)
|
22
|
+
|
23
|
+
### v0.8.0 / 2020-10-27
|
24
|
+
|
25
|
+
* BREAKING CHANGE: Move context/span methods to Trace module
|
26
|
+
* BREAKING CHANGE: Remove 'canonical' from status codes
|
27
|
+
* BREAKING CHANGE: Assorted SpanContext fixes
|
28
|
+
|
29
|
+
* ADDED: B3 support
|
30
|
+
* FIXED: Move context/span methods to Trace module
|
31
|
+
* FIXED: Remove 'canonical' from status codes
|
32
|
+
* FIXED: Assorted SpanContext fixes
|
33
|
+
|
3
34
|
### v0.7.0 / 2020-10-07
|
4
35
|
|
5
36
|
* FIXED: Safely navigate span variable during error cases
|
data/LICENSE
CHANGED
@@ -186,7 +186,7 @@
|
|
186
186
|
same "printed page" as the copyright notice for easier
|
187
187
|
identification within third-party archives.
|
188
188
|
|
189
|
-
Copyright
|
189
|
+
Copyright The OpenTelemetry Authors
|
190
190
|
|
191
191
|
Licensed under the Apache License, Version 2.0 (the "License");
|
192
192
|
you may not use this file except in compliance with the License.
|
data/lib/opentelemetry-api.rb
CHANGED
data/lib/opentelemetry.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
# Copyright
|
3
|
+
# Copyright The OpenTelemetry Authors
|
4
4
|
#
|
5
5
|
# SPDX-License-Identifier: Apache-2.0
|
6
6
|
|
@@ -22,13 +22,27 @@ require 'opentelemetry/version'
|
|
22
22
|
module OpenTelemetry
|
23
23
|
extend self
|
24
24
|
|
25
|
-
attr_writer :tracer_provider, :meter_provider, :baggage, :logger
|
25
|
+
attr_writer :tracer_provider, :meter_provider, :baggage, :logger, :error_handler
|
26
26
|
|
27
27
|
# @return [Object, Logger] configured Logger or a default STDOUT Logger.
|
28
28
|
def logger
|
29
29
|
@logger ||= Logger.new(STDOUT, level: ENV['OTEL_LOG_LEVEL'] || Logger::INFO)
|
30
30
|
end
|
31
31
|
|
32
|
+
# @return [Callable] configured error handler or a default that logs the
|
33
|
+
# exception and message at ERROR level.
|
34
|
+
def error_handler
|
35
|
+
@error_handler ||= ->(exception: nil, message: nil) { logger.error("OpenTelemetry error: #{[message, exception&.message].compact.join(' - ')}") }
|
36
|
+
end
|
37
|
+
|
38
|
+
# Handles an error by calling the configured error_handler.
|
39
|
+
#
|
40
|
+
# @param [optional Exception] exception The exception to be handled
|
41
|
+
# @param [optional String] message An error message.
|
42
|
+
def handle_error(exception: nil, message: nil)
|
43
|
+
error_handler.call(exception: exception, message: message)
|
44
|
+
end
|
45
|
+
|
32
46
|
# @return [Object, Trace::TracerProvider] registered tracer provider or a
|
33
47
|
# default no-op implementation of the tracer provider.
|
34
48
|
def tracer_provider
|
data/lib/opentelemetry/error.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
# Copyright
|
3
|
+
# Copyright The OpenTelemetry Authors
|
4
4
|
#
|
5
5
|
# SPDX-License-Identifier: Apache-2.0
|
6
6
|
|
@@ -79,8 +79,7 @@ module OpenTelemetry
|
|
79
79
|
OpenTelemetry.logger.warn "Instrumentation: #{instrumentation.name} failed to install"
|
80
80
|
end
|
81
81
|
rescue => e # rubocop:disable Style/RescueStandardError
|
82
|
-
OpenTelemetry.
|
83
|
-
"during install #{e}: #{e.backtrace}"
|
82
|
+
OpenTelemetry.handle_error(exception: e, message: "Instrumentation: #{instrumentation.name} unhandled exception during install: #{e.backtrace}")
|
84
83
|
end
|
85
84
|
end
|
86
85
|
end
|
data/lib/opentelemetry/trace.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
# Copyright
|
3
|
+
# Copyright The OpenTelemetry Authors
|
4
4
|
#
|
5
5
|
# SPDX-License-Identifier: Apache-2.0
|
6
6
|
|
@@ -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,17 +36,47 @@ 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
|
|
42
77
|
require 'opentelemetry/trace/link'
|
43
78
|
require 'opentelemetry/trace/trace_flags'
|
79
|
+
require 'opentelemetry/trace/tracestate'
|
44
80
|
require 'opentelemetry/trace/span_context'
|
45
81
|
require 'opentelemetry/trace/span_kind'
|
46
82
|
require 'opentelemetry/trace/span'
|
@@ -1,6 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
# Copyright
|
3
|
+
# Copyright The OpenTelemetry Authors
|
4
4
|
#
|
5
5
|
# SPDX-License-Identifier: Apache-2.0
|
6
6
|
|
@@ -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
|
@@ -1,10 +1,9 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
# Copyright
|
3
|
+
# Copyright The OpenTelemetry Authors
|
4
4
|
#
|
5
5
|
# SPDX-License-Identifier: Apache-2.0
|
6
6
|
|
7
|
-
require 'opentelemetry/trace/propagation/context_keys'
|
8
7
|
require 'opentelemetry/trace/propagation/trace_context'
|
9
8
|
|
10
9
|
module OpenTelemetry
|
@@ -1,6 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
# Copyright
|
3
|
+
# Copyright The OpenTelemetry Authors
|
4
4
|
#
|
5
5
|
# SPDX-License-Identifier: Apache-2.0
|
6
6
|
module OpenTelemetry
|
@@ -37,10 +37,8 @@ module OpenTelemetry
|
|
37
37
|
# context if parsing fails.
|
38
38
|
def extract(carrier, context, &getter)
|
39
39
|
getter ||= default_getter
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
tracestate = getter.call(carrier, @tracestate_key)
|
40
|
+
tp = TraceParent.from_string(getter.call(carrier, @traceparent_key))
|
41
|
+
tracestate = Tracestate.from_string(getter.call(carrier, @tracestate_key))
|
44
42
|
|
45
43
|
span_context = Trace::SpanContext.new(trace_id: tp.trace_id,
|
46
44
|
span_id: tp.span_id,
|
@@ -48,7 +46,7 @@ module OpenTelemetry
|
|
48
46
|
tracestate: tracestate,
|
49
47
|
remote: true)
|
50
48
|
span = Trace::Span.new(span_context: span_context)
|
51
|
-
|
49
|
+
OpenTelemetry::Trace.context_with_span(span)
|
52
50
|
rescue OpenTelemetry::Error
|
53
51
|
context
|
54
52
|
end
|
@@ -1,6 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
# Copyright
|
3
|
+
# Copyright The OpenTelemetry Authors
|
4
4
|
#
|
5
5
|
# SPDX-License-Identifier: Apache-2.0
|
6
6
|
module OpenTelemetry
|
@@ -36,8 +36,8 @@ 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.
|
40
|
-
setter.call(carrier, @tracestate_key, span_context.tracestate) unless span_context.tracestate.
|
39
|
+
setter.call(carrier, @traceparent_key, TraceParent.from_span_context(span_context).to_s)
|
40
|
+
setter.call(carrier, @tracestate_key, span_context.tracestate.to_s) unless span_context.tracestate.empty?
|
41
41
|
|
42
42
|
carrier
|
43
43
|
end
|
@@ -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
|
@@ -1,6 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
# Copyright
|
3
|
+
# Copyright The OpenTelemetry Authors
|
4
4
|
#
|
5
5
|
# SPDX-License-Identifier: Apache-2.0
|
6
6
|
module OpenTelemetry
|
@@ -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
|
|
@@ -1,6 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
# Copyright
|
3
|
+
# Copyright The OpenTelemetry Authors
|
4
4
|
#
|
5
5
|
# SPDX-License-Identifier: Apache-2.0
|
6
6
|
|
@@ -18,14 +18,14 @@ module OpenTelemetry
|
|
18
18
|
# @param [optional String] trace_id The trace ID associated with a {Span}.
|
19
19
|
# @param [optional String] span_id The span ID associated with a {Span}.
|
20
20
|
# @param [optional TraceFlags] trace_flags The trace flags associated with a {Span}.
|
21
|
-
# @param [optional
|
21
|
+
# @param [optional Tracestate] tracestate The tracestate associated with a {Span}. May be nil.
|
22
22
|
# @param [optional Boolean] remote Whether the {SpanContext} was extracted from the wire.
|
23
23
|
# @return [SpanContext]
|
24
24
|
def initialize(
|
25
25
|
trace_id: Trace.generate_trace_id,
|
26
26
|
span_id: Trace.generate_span_id,
|
27
27
|
trace_flags: TraceFlags::DEFAULT,
|
28
|
-
tracestate:
|
28
|
+
tracestate: Tracestate::DEFAULT,
|
29
29
|
remote: false
|
30
30
|
)
|
31
31
|
@trace_id = trace_id
|
@@ -1,6 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
# Copyright
|
3
|
+
# Copyright The OpenTelemetry Authors
|
4
4
|
#
|
5
5
|
# SPDX-License-Identifier: Apache-2.0
|
6
6
|
|
@@ -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.
|
@@ -1,6 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
# Copyright
|
3
|
+
# Copyright The OpenTelemetry Authors
|
4
4
|
#
|
5
5
|
# SPDX-License-Identifier: Apache-2.0
|
6
6
|
|
@@ -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)
|
@@ -0,0 +1,158 @@
|
|
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 Trace
|
9
|
+
# Tracestate is a part of SpanContext, represented by an immutable list of
|
10
|
+
# string key/value pairs and formally defined by the W3C Trace Context
|
11
|
+
# specification https://www.w3.org/TR/trace-context/
|
12
|
+
class Tracestate
|
13
|
+
class << self
|
14
|
+
private :new # rubocop:disable Style/AccessModifierDeclarations
|
15
|
+
|
16
|
+
# Returns a newly created Tracestate parsed from the header provided.
|
17
|
+
#
|
18
|
+
# @param [String] header Encoding of the tracestate header defined by
|
19
|
+
# the W3C Trace Context specification https://www.w3.org/TR/trace-context/
|
20
|
+
# @return [Tracestate] A new Tracestate instance or DEFAULT
|
21
|
+
def from_string(header) # rubocop:disable Metrics/CyclomaticComplexity:
|
22
|
+
return DEFAULT if header.nil? || header.empty?
|
23
|
+
|
24
|
+
hash = header.split(',').each_with_object({}) do |member, memo|
|
25
|
+
member.strip!
|
26
|
+
kv = member.split('=')
|
27
|
+
k, v = *kv
|
28
|
+
next unless kv.length == 2 && VALID_KEY.match?(k) && VALID_VALUE.match?(v)
|
29
|
+
|
30
|
+
memo[k] = v
|
31
|
+
end
|
32
|
+
return DEFAULT if hash.empty?
|
33
|
+
|
34
|
+
new(hash)
|
35
|
+
end
|
36
|
+
|
37
|
+
# Returns a Tracestate created from a Hash.
|
38
|
+
#
|
39
|
+
# @param [Hash<String, String>] hash Key-value pairs to store in the
|
40
|
+
# Tracestate. Keys and values are validated against the W3C Trace
|
41
|
+
# Context specification, and any invalid members are logged at
|
42
|
+
# DEBUG level and dropped.
|
43
|
+
# @return [Tracestate] A new Tracestate instance or DEFAULT
|
44
|
+
def from_hash(hash)
|
45
|
+
hash = hash.select do |k, v|
|
46
|
+
valid = VALID_KEY.match?(k) && VALID_VALUE.match?(v)
|
47
|
+
OpenTelemetry.logger.debug("Invalid Tracestate member - #{k} : #{v}") unless valid
|
48
|
+
valid
|
49
|
+
end
|
50
|
+
new(hash)
|
51
|
+
end
|
52
|
+
|
53
|
+
# @api private
|
54
|
+
# Returns a new Tracestate created from the Hash provided. This
|
55
|
+
# skips validation of the keys and values, assuming they are already
|
56
|
+
# valid.
|
57
|
+
# This method is intended only for the use of instance methods in
|
58
|
+
# this class.
|
59
|
+
def create(hash)
|
60
|
+
new(hash)
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
MAX_MEMBER_COUNT = 32 # Defined by https://www.w3.org/TR/trace-context/
|
65
|
+
VALID_KEY = Regexp.union(%r(^[a-z][a-z0-9_\-*/]{,255}$), %r(^[a-z0-9][a-z0-9_\-*/]{,240}@[a-z][a-z0-9_\-*/]{,13}$)).freeze
|
66
|
+
VALID_VALUE = /^[ -~&&[^,=]]{,255}[!-~&&[^,=]]$/.freeze
|
67
|
+
private_constant(:MAX_MEMBER_COUNT, :VALID_KEY, :VALID_VALUE)
|
68
|
+
|
69
|
+
# @api private
|
70
|
+
# The constructor is private and only for use internally by the class.
|
71
|
+
# Users should use the {from_hash} or {from_string} factory methods to
|
72
|
+
# obtain a {Tracestate} instance.
|
73
|
+
#
|
74
|
+
# @param [Hash<String, String>] hash Key-value pairs
|
75
|
+
# @return [Tracestate]
|
76
|
+
def initialize(hash)
|
77
|
+
excess = hash.size - MAX_MEMBER_COUNT
|
78
|
+
hash = Hash[hash.drop(excess)] if excess.positive?
|
79
|
+
@hash = hash.freeze
|
80
|
+
end
|
81
|
+
|
82
|
+
# Returns the value associated with the given key, or nil if the key
|
83
|
+
# is not present.
|
84
|
+
#
|
85
|
+
# @param [String] key The key to lookup.
|
86
|
+
# @return [String] The value associated with the key, or nil.
|
87
|
+
def value(key)
|
88
|
+
@hash[key]
|
89
|
+
end
|
90
|
+
|
91
|
+
alias [] value
|
92
|
+
|
93
|
+
# Adds a new key/value pair or updates an existing value for a given key.
|
94
|
+
# Keys and values are validated against the W3C Trace Context
|
95
|
+
# specification, and any invalid members are logged at DEBUG level and
|
96
|
+
# ignored.
|
97
|
+
#
|
98
|
+
# @param [String] key The key to add or update.
|
99
|
+
# @param [String] value The value to add or update.
|
100
|
+
# @return [Tracestate] self, if unchanged, or a new Tracestate containing
|
101
|
+
# the new or updated key/value pair.
|
102
|
+
def set_value(key, value)
|
103
|
+
return self unless VALID_KEY.match?(key) && VALID_VALUE.match?(value)
|
104
|
+
|
105
|
+
h = Hash[@hash]
|
106
|
+
h[key] = value
|
107
|
+
self.class.create(h)
|
108
|
+
end
|
109
|
+
|
110
|
+
# Deletes the key/value pair associated with the given key.
|
111
|
+
#
|
112
|
+
# @param [String] key The key to remove.
|
113
|
+
# @return [Tracestate] self, if unchanged, or a new Tracestate without
|
114
|
+
# the specified key.
|
115
|
+
def delete(key)
|
116
|
+
return self unless @hash.key?(key)
|
117
|
+
|
118
|
+
h = Hash[@hash]
|
119
|
+
h.delete(key)
|
120
|
+
self.class.create(h)
|
121
|
+
end
|
122
|
+
|
123
|
+
# Returns this Tracestate encoded according to the W3C Trace Context
|
124
|
+
# specification https://www.w3.org/TR/trace-context/
|
125
|
+
#
|
126
|
+
# @return [String] this Tracestate encoded as a string.
|
127
|
+
def to_s
|
128
|
+
@hash.inject(+'') do |memo, (k, v)|
|
129
|
+
memo << k << '=' << v << ','
|
130
|
+
end.chop! || ''
|
131
|
+
end
|
132
|
+
|
133
|
+
# Returns this Tracestate as a Hash.
|
134
|
+
#
|
135
|
+
# @return [Hash] the members of this Tracestate
|
136
|
+
def to_h
|
137
|
+
@hash.dup
|
138
|
+
end
|
139
|
+
|
140
|
+
# Returns true if this Tracestate is empty.
|
141
|
+
#
|
142
|
+
# @return [Boolean] true if this Tracestate is empty, else false.
|
143
|
+
def empty?
|
144
|
+
@hash.empty?
|
145
|
+
end
|
146
|
+
|
147
|
+
# Returns true if this Tracestate equals other.
|
148
|
+
#
|
149
|
+
# @param [Tracestate] other The Tracestate for comparison.
|
150
|
+
# @return [Boolean] true if this Tracestate == other, else false.
|
151
|
+
def ==(other)
|
152
|
+
@hash == other.to_h
|
153
|
+
end
|
154
|
+
|
155
|
+
DEFAULT = new({})
|
156
|
+
end
|
157
|
+
end
|
158
|
+
end
|
@@ -1,10 +1,10 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
# Copyright
|
3
|
+
# Copyright The OpenTelemetry Authors
|
4
4
|
#
|
5
5
|
# SPDX-License-Identifier: Apache-2.0
|
6
6
|
|
7
7
|
module OpenTelemetry
|
8
8
|
## Current OpenTelemetry version
|
9
|
-
VERSION = '0.
|
9
|
+
VERSION = '0.12.0'
|
10
10
|
end
|
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.12.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-
|
11
|
+
date: 2020-12-24 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
|
@@ -190,12 +189,17 @@ files:
|
|
190
189
|
- lib/opentelemetry/trace/trace_flags.rb
|
191
190
|
- lib/opentelemetry/trace/tracer.rb
|
192
191
|
- lib/opentelemetry/trace/tracer_provider.rb
|
192
|
+
- lib/opentelemetry/trace/tracestate.rb
|
193
193
|
- lib/opentelemetry/trace/util/http_to_status.rb
|
194
194
|
- lib/opentelemetry/version.rb
|
195
195
|
homepage: https://github.com/open-telemetry/opentelemetry-ruby
|
196
196
|
licenses:
|
197
197
|
- Apache-2.0
|
198
|
-
metadata:
|
198
|
+
metadata:
|
199
|
+
changelog_uri: https://open-telemetry.github.io/opentelemetry-ruby/opentelemetry-api/v0.12.0/file.CHANGELOG.html
|
200
|
+
source_code_uri: https://github.com/open-telemetry/opentelemetry-ruby/tree/master/api
|
201
|
+
bug_tracker_uri: https://github.com/open-telemetry/opentelemetry-ruby/issues
|
202
|
+
documentation_uri: https://open-telemetry.github.io/opentelemetry-ruby/opentelemetry-api/v0.12.0
|
199
203
|
post_install_message:
|
200
204
|
rdoc_options: []
|
201
205
|
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
|