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
|
# File 'lib/apirelio/event.rb', line 10
def build(context, service:, environment:, release:, metadata_keys:)
customer = context[:customer] || {}
application = context[:application] || {}
{
event_id: SecureRandom.uuid,
occurred_at: Time.now.utc.iso8601(3),
service: text(service, 120) || "ruby-api",
environment: environment.to_s,
method: (text(context[:method], 16) || "GET").upcase,
route: Route.normalize(context[:route]),
route_name: text(context[:route_name], 255),
status: integer(context.fetch(:status, 200), 100, 599),
duration_ms: integer(context.fetch(:duration_ms, 0), 0, 4_294_967_295),
request_bytes: optional_integer(context[:request_bytes]),
response_bytes: optional_integer(context[:response_bytes]),
customer_id: text(value(customer, :id), 255),
customer_name: text(value(customer, :name), 255),
customer_plan: text(value(customer, :plan), 120),
application_id: text(value(application, :id), 255),
application_name: text(value(application, :name), 255),
api_version: text(context[:api_version], 120),
sdk: text(context[:sdk], 120) || "ruby",
sdk_version: text(context[:sdk_version], 120) || "0.0.0",
release: text(release, 255),
error_code: text(context[:error_code], 255),
metadata: Metadata.sanitize(context[:metadata] || {}, allowed_keys: metadata_keys)
}
end
|