yes-core 2.4.3 → 2.4.5
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
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 1015d6ea5414383b562af2eee6665410cbf5e434e849015bc679eb30c7677a28
|
|
4
|
+
data.tar.gz: cba436f63754c8d5b74c371d83558f4deb16353fbde8d502a1e45d757971f161
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 3d9abb7576fb11421f5d8a85e67c421947659d70eb73d45317208f8f08a616778cba920fe431e6798d2ffcbeee24085c89aea89659b4579b74afa84464630cf0
|
|
7
|
+
data.tar.gz: fb8e7e151455887d7c7175778508be1c357c47e517ed170bca6e6f535bbf338c32c50698e6e8bdc37ab7b991f9f3e7a912aefc7bd3c12eb3e0dc3310d59f6258
|
data/CHANGELOG.md
CHANGED
|
@@ -13,7 +13,11 @@ module Yes
|
|
|
13
13
|
class CommandHandler
|
|
14
14
|
# Span attribute naming the command that ran. The span keeps a fixed name so its
|
|
15
15
|
# latency histogram stays one series per service; this is how the command is identified.
|
|
16
|
-
|
|
16
|
+
#
|
|
17
|
+
# Not the bare `command`: CommandCerbosAuthorizer already puts the serialised command
|
|
18
|
+
# on an attribute of that name, and a metrics pipeline that exports span attributes by
|
|
19
|
+
# name cannot tell the two apart. It would export the payload, one series per payload.
|
|
20
|
+
COMMAND_ATTRIBUTE = 'command.name'
|
|
17
21
|
|
|
18
22
|
include Yes::Core::OpenTelemetry::Trackable
|
|
19
23
|
|
|
@@ -7,6 +7,13 @@ module Yes
|
|
|
7
7
|
class EventPublisher
|
|
8
8
|
include Yes::Core::OpenTelemetry::Trackable
|
|
9
9
|
|
|
10
|
+
# Prefix of the span attributes that carry single event metadata entries
|
|
11
|
+
METADATA_ATTRIBUTE_PREFIX = 'event.metadata.'
|
|
12
|
+
# Metadata value types that are recorded as their own span attribute. The OpenTelemetry SDK
|
|
13
|
+
# rejects other numerics (e.g. BigDecimal), so only Integer and Float are listed.
|
|
14
|
+
SCALAR_METADATA_TYPES = [String, Symbol, Integer, Float, TrueClass, FalseClass].freeze
|
|
15
|
+
private_constant :METADATA_ATTRIBUTE_PREFIX, :SCALAR_METADATA_TYPES
|
|
16
|
+
|
|
10
17
|
# Value object containing aggregate data needed for event publication
|
|
11
18
|
AggregateEventPublicationData = Struct.new(:id, :context, :name, :revision, keyword_init: true) do
|
|
12
19
|
def self.from_aggregate(aggregate)
|
|
@@ -153,16 +160,34 @@ module Yes
|
|
|
153
160
|
meta
|
|
154
161
|
end
|
|
155
162
|
|
|
163
|
+
# Records the event on the current span: type, data and metadata as JSON, plus every
|
|
164
|
+
# scalar top-level metadata entry as its own `event.metadata.<key>` attribute, so tracing
|
|
165
|
+
# backends can derive metrics dimensioned by a metadata key. Nil, hash and array values
|
|
166
|
+
# are left out; they remain readable in the JSON attribute.
|
|
167
|
+
#
|
|
168
|
+
# @param event [PgEventstore::Event] The event about to be published
|
|
169
|
+
# @return [void]
|
|
156
170
|
def otl_record_event_data(event)
|
|
157
171
|
self.class.current_span&.add_attributes(
|
|
158
172
|
{
|
|
159
173
|
'event.type' => event.type,
|
|
160
174
|
'event.data' => event.data.to_json,
|
|
161
|
-
'event.metadata' => event.metadata.to_json
|
|
175
|
+
'event.metadata' => event.metadata.to_json,
|
|
176
|
+
**scalar_metadata_attributes(event.metadata)
|
|
162
177
|
}
|
|
163
178
|
)
|
|
164
179
|
end
|
|
165
180
|
|
|
181
|
+
# @param metadata [Hash] The event metadata
|
|
182
|
+
# @return [Hash{String => String, Numeric, Boolean}] Scalar metadata entries keyed by span attribute name
|
|
183
|
+
def scalar_metadata_attributes(metadata)
|
|
184
|
+
metadata.each_with_object({}) do |(key, value), attributes|
|
|
185
|
+
next unless SCALAR_METADATA_TYPES.any? { value.is_a?(_1) }
|
|
186
|
+
|
|
187
|
+
attributes["#{METADATA_ATTRIBUTE_PREFIX}#{key}"] = value.is_a?(Symbol) ? value.to_s : value
|
|
188
|
+
end
|
|
189
|
+
end
|
|
190
|
+
|
|
166
191
|
def otl_record_response(result)
|
|
167
192
|
if ENV['STATSD_ADDR'].present?
|
|
168
193
|
StatsD.increment(
|
data/lib/yes/core/version.rb
CHANGED