This repository has been archived by the owner on Dec 8, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
73 changed files
with
1,076 additions
and
994 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
module Timber | ||
module Events | ||
# The HTTP client request event tracks *outgoing* HTTP requests giving you structured insight | ||
# into communication with external services. | ||
# | ||
# @note This event should be installed automatically through integrations, | ||
# such as the {Integrations::NetHTTP} integration. | ||
class HTTPClientRequest < Timber::Event | ||
attr_reader :body, :headers, :host, :method, :path, :port, :query_string, :request_id, | ||
:scheme, :service_name | ||
|
||
def initialize(attributes) | ||
@body = Util::HTTPEvent.normalize_body(attributes[:body]) | ||
@headers = Util::HTTPEvent.normalize_headers(attributes[:headers]) | ||
@host = attributes[:host] || raise(ArgumentError.new(":host is required")) | ||
@method = Util::HTTPEvent.normalize_method(attributes[:method]) || raise(ArgumentError.new(":method is required")) | ||
@path = attributes[:path] || raise(ArgumentError.new(":path is required")) | ||
@port = attributes[:port] | ||
@query_string = Util::HTTPEvent.normalize_query_string(attributes[:query_string]) | ||
@request_id = attributes[:request_id] | ||
@scheme = attributes[:scheme] || raise(ArgumentError.new(":scheme is required")) | ||
@service_name = attributes[:service_name] | ||
end | ||
|
||
def to_hash | ||
{body: body, headers: headers, host: host, method: method, path: path, port: port, | ||
query_string: query_string, request_id: request_id, scheme: scheme, | ||
service_name: service_name} | ||
end | ||
alias to_h to_hash | ||
|
||
def as_json(_options = {}) | ||
{:server_side_app => {:http_client_request => to_hash}} | ||
end | ||
|
||
def message | ||
message = 'Outgoing HTTP request to ' | ||
|
||
if service_name | ||
mesage << " #{service_name} [#{method}] #{full_path}" | ||
else | ||
message << " [#{method}] #{full_url}" | ||
end | ||
end | ||
|
||
def status_description | ||
Rack::Utils::HTTP_STATUS_CODES[status] | ||
end | ||
|
||
private | ||
def full_path | ||
Util::HTTPEvent.full_path(path, query_string) | ||
end | ||
|
||
def full_url | ||
"#{scheme}#{host}#{full_path}" | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
module Timber | ||
module Events | ||
# The HTTP client response event tracks responses for *outgoing* HTTP *requests*. | ||
# This gives you structured insight into communication with external services. | ||
# | ||
# @note This event should be installed automatically through integrations, | ||
# such as the {Integrations::NetHTTP} integration. | ||
class HTTPClientResponse < Timber::Event | ||
attr_reader :body, :headers, :request_id, :service_name, :status, :time_ms | ||
|
||
def initialize(attributes) | ||
@body = Util::HTTPEvent.normalize_body(attributes[:body]) | ||
@headers = Util::HTTPEvent.normalize_headers(attributes[:headers]) | ||
@request_id = attributes[:request_id] | ||
@service_name = attributes[:service_name] | ||
@status = attributes[:status] || raise(ArgumentError.new(":status is required")) | ||
@time_ms = attributes[:time_ms] || raise(ArgumentError.new(":time_ms is required")) | ||
@time_ms = @time_ms.round(6) | ||
end | ||
|
||
def to_hash | ||
{body: body, headers: headers, request_id: request_id, service_name: service_name, | ||
status: status, time_ms: time_ms} | ||
end | ||
alias to_h to_hash | ||
|
||
def as_json(_options = {}) | ||
{:server_side_app => {:http_client_response => to_hash}} | ||
end | ||
|
||
def message | ||
message = "Outgoing HTTP response" | ||
|
||
if service_name | ||
message << " from #{service_name}" | ||
end | ||
|
||
message << " #{status_description} in #{time_ms}ms" | ||
end | ||
|
||
def status_description | ||
Rack::Utils::HTTP_STATUS_CODES[status] | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.