-
Notifications
You must be signed in to change notification settings - Fork 251
/
Copy pathspan.rb
161 lines (149 loc) · 5.81 KB
/
span.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
# frozen_string_literal: true
# Copyright The OpenTelemetry Authors
#
# SPDX-License-Identifier: Apache-2.0
module OpenTelemetry
module Trace
# Span represents a single operation within a trace. Spans can be nested to
# form a trace tree. Often, a trace contains a root span that describes the
# end-to-end latency and, optionally, one or more sub-spans for its
# sub-operations.
#
# Once Span {Tracer#start_span is created} - Span operations can be used to
# add additional properties to it like attributes, links, events, name and
# resulting status. Span cannot be used to retrieve these properties. This
# prevents the mis-use of spans as an in-process information propagation
# mechanism.
#
# {Span} must be ended by calling {#finish}.
class Span
# Retrieve the spans SpanContext
#
# The returned value may be used even after the Span is finished.
#
# @return [SpanContext]
attr_reader :context
# Spans must be created using {Tracer}. This is for internal use only.
#
# @api private
def initialize(span_context: nil)
@context = span_context || SpanContext.new
end
# Return whether this span is recording.
#
# @return [Boolean] true if this Span is active and recording information
# like events with the #add_event operation and attributes using
# #set_attribute.
def recording?
false
end
# Set attribute
#
# Note that the OpenTelemetry project
# {https://github.com/open-telemetry/opentelemetry-specification/blob/master/specification/data-semantic-conventions.md
# documents} certain "standard attributes" that have prescribed semantic
# meanings.
#
# @param [String] key
# @param [String, Boolean, Numeric, Array<String, Numeric, Boolean>] value
# Values must be non-nil and (array of) string, boolean or numeric type.
# Array values must not contain nil elements and all elements must be of
# the same basic type (string, numeric, boolean).
#
# @return [self] returns itself
def set_attribute(key, value)
self
end
alias []= set_attribute
# Add attributes
#
# Note that the OpenTelemetry project
# {https://github.com/open-telemetry/opentelemetry-specification/blob/master/specification/data-semantic-conventions.md
# documents} certain "standard attributes" that have prescribed semantic
# meanings.
#
# @param [Hash{String => String, Numeric, Boolean, Array<String, Numeric, Boolean>}] attributes
# Values must be non-nil and (array of) string, boolean or numeric type.
# Array values must not contain nil elements and all elements must be of
# the same basic type (string, numeric, boolean).
#
# @return [self] returns itself
def add_attributes(attributes)
self
end
# Add an event to a {Span}.
#
# Example:
#
# span.add_event('event', attributes: {'eager' => true})
#
# Note that the OpenTelemetry project
# {https://github.com/open-telemetry/opentelemetry-specification/blob/master/specification/data-semantic-conventions.md
# documents} certain "standard event names and keys" which have
# prescribed semantic meanings.
#
# @param [String] name Name of the event.
# @param [optional Hash{String => String, Numeric, Boolean, Array<String, Numeric, Boolean>}]
# attributes One or more key:value pairs, where the keys must be
# strings and the values may be (array of) string, boolean or numeric
# type.
# @param [optional Time] timestamp Optional timestamp for the event.
#
# @return [self] returns itself
def add_event(name, attributes: nil, timestamp: nil)
self
end
# Record an exception during the execution of this span. Multiple exceptions
# can be recorded on a span.
#
# @param [Exception] exception The exception to recorded
# @param [optional Hash{String => String, Numeric, Boolean, Array<String, Numeric, Boolean>}]
# attributes One or more key:value pairs, where the keys must be
# strings and the values may be (array of) string, boolean or numeric
# type.
#
# @return [void]
def record_exception(exception, attributes: nil); end
# Sets the Status to the Span
#
# If used, this will override the default Span status. Default status is unset.
#
# Only the value of the last call will be recorded, and implementations
# are free to ignore previous calls.
#
# @param [Status] status The new status, which overrides the default Span
# status, which is OK.
#
# @return [void]
def status=(status); end
# Updates the Span name
#
# Upon this update, any sampling behavior based on Span name will depend
# on the implementation.
#
# @param [String] new_name The new operation name, which supersedes
# whatever was passed in when the Span was started
#
# @return [void]
def name=(new_name); end
# Finishes the Span
#
# Implementations MUST ignore all subsequent calls to {#finish} (there
# might be exceptions when Tracer is streaming event and has no mutable
# state associated with the Span).
#
# Call to {#finish} MUST not have any effects on child spans. Those may
# still be running and can be ended later.
#
# This API MUST be non-blocking.
#
# @param [Time] end_timestamp optional end timestamp for the span.
#
# @return [self] returns itself
def finish(end_timestamp: nil)
self
end
INVALID = new(span_context: SpanContext::INVALID)
end
end
end