Skip to content

Commit 09637b2

Browse files
authored
T-4821 Use ingestion_* options, update outdated naming (#32)
1 parent 9a76381 commit 09637b2

File tree

5 files changed

+33
-30
lines changed

5 files changed

+33
-30
lines changed

Rakefile

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ def puts_with_level(message, level = :info)
1515
end
1616

1717
task :test_the_pipes, [:source_token] do |t, args|
18-
support_email = "support@logtail.com"
18+
support_email = "hello@betterstack.com"
1919
# Do not modify below this line. It's important to keep the `Logtail::Logger`
2020
# because it provides an API for logging structured data and capturing context.
2121
header = <<~HEREDOC
@@ -31,21 +31,21 @@ task :test_the_pipes, [:source_token] do |t, args|
3131
if response.is_a?(Exception)
3232
message = <<~HEREDOC
3333
Unable to deliver logs.
34-
Here's what we received from the Logtail API:
34+
Here's what we received from the Better Stack Telemetry API:
3535
#{response.inspect}
3636
If you continue to have trouble please contact support:
3737
#{support_email}
3838
HEREDOC
3939
puts_with_level(message, :error)
4040
elsif response.is_a?(Net::HTTPResponse)
4141
if response.code.start_with? '2'
42-
puts_with_level("Logs successfully sent! View them at https://logtail.com",
42+
puts_with_level("Logs successfully sent! View them at https://telemetry.betterstack.com",
4343
:success)
4444
else
4545
message =
4646
<<~HEREDOC
4747
Unable to deliver logs.
48-
We received a #{response.code} response from the Logtail API:
48+
We received a #{response.code} response from the Better Stack Telemetry API:
4949
#{response.body.inspect}
5050
If you continue to have trouble please contact support:
5151
#{support_email}

example-project/main.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
exit
1313
end
1414
# Create logger
15-
http_device = Logtail::LogDevices::HTTP.new(ARGV[0], logtail_host: ARGV[1])
15+
http_device = Logtail::LogDevices::HTTP.new(ARGV[0], ingesting_host: ARGV[1])
1616
logger = Logtail::Logger.new(http_device)
1717

1818
# Filter logs that shouldn't be sent to Better Stack, see {Logtail::LogEntry} for available attributes
@@ -21,10 +21,10 @@
2121
# LOGGING
2222

2323
# Send debug logs messages using the debug() method
24-
logger.debug("Logtail is ready!")
24+
logger.debug("Better Stack is ready!")
2525

2626
# Send informative messages about interesting events using the info() method
27-
logger.info("I am using Logtail!")
27+
logger.info("I am using Better Stack!")
2828

2929
# Send messages about worrying events using the warn() method
3030
# You can also log additional structured data

lib/logtail/log_devices/http.rb

Lines changed: 24 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,11 @@ module LogDevices
1717
#
1818
# See {#initialize} for options and more details.
1919
class HTTP
20-
LOGTAIL_STAGING_HOST = "in.logtail.dev".freeze
21-
LOGTAIL_PRODUCTION_HOST = "in.logtail.com".freeze
22-
LOGTAIL_HOST = ENV['LOGTAIL_STAGING'] ? LOGTAIL_STAGING_HOST : LOGTAIL_PRODUCTION_HOST
23-
LOGTAIL_PORT = 443
24-
LOGTAIL_SCHEME = "https".freeze
20+
DEFAULT_INGESTING_HOST = "in.logs.betterstack.com".freeze
21+
DEFAULT_INGESTING_PORT = 443
22+
DEFAULT_INGESTING_SCHEME = "https".freeze
2523
CONTENT_TYPE = "application/msgpack".freeze
26-
USER_AGENT = "Logtail Ruby/#{Logtail::VERSION} (HTTP)".freeze
24+
USER_AGENT = "Better Stack Telemetry for Ruby/#{Logtail::VERSION} (HTTP)".freeze
2725

2826
# Instantiates a new HTTP log device that can be passed to {Logtail::Logger#initialize}.
2927
#
@@ -36,15 +34,15 @@ class HTTP
3634
# you can drop the log messages instead by passing a {DroppingSizedQueue} via the
3735
# `:request_queue` option.
3836
#
39-
# @param source_token [String] The API key provided to you after you add your application to
40-
# [Logtail](https://logtail.com).
37+
# @param source_token [String] The API key provided to you after you add your source to
38+
# [Better Stack](https://telemetry.betterstack.com).
4139
# @param [Hash] options the options to create a HTTP log device with.
4240
# @option attributes [Symbol] :batch_size (1000) Determines the maximum of log lines in
4341
# each HTTP payload. If the queue exceeds this limit an HTTP request will be issued. Bigger
4442
# payloads mean higher throughput, but also use more memory. Logtail will not accept
4543
# payloads larger than 1mb.
4644
# @option attributes [Symbol] :flush_continuously (true) This should only be disabled under
47-
# special circumstsances (like test suites). Setting this to `false` disables the
45+
# special circumstances (like test suites). Setting this to `false` disables the
4846
# continuous flushing of log message. As a result, flushing must be handled externally
4947
# via the #flush method.
5048
# @option attributes [Symbol] :flush_interval (1) How often the client should
@@ -55,25 +53,30 @@ class HTTP
5553
# single persistent connection. After this number is met, the connection will be closed
5654
# and a new one will be opened.
5755
# @option attributes [Symbol] :request_queue (FlushableDroppingSizedQueue.new(25)) The request
58-
# queue object that queues Net::HTTP requests for delivery. By deafult this is a
56+
# queue object that queues Net::HTTP requests for delivery. By default this is a
5957
# `FlushableDroppingSizedQueue` of size `25`. Meaning once the queue fills up to 25
6058
# requests new requests will be dropped. If you'd prefer to apply back pressure,
6159
# ensuring you do not lose log data, pass a standard {SizedQueue}. See examples for
6260
# an example.
63-
# @option attributes [Symbol] :logtail_host The Logtail host to delivery the log lines to.
64-
# The default is set via {LOGTAIL_HOST}.
61+
# @option attributes [Symbol] :ingesting_host The Better Stack Telemetry ingesting host to delivery the log lines to.
62+
# The default is set via {INGESTING_HOST}.
6563
#
6664
# @example Basic usage
67-
# Logtail::Logger.new(Logtail::LogDevices::HTTP.new("my_logtail_source_token"))
65+
# Logtail::Logger.new(Logtail::LogDevices::HTTP.new("<source_token>", ingesting_host: "<ingesting_host>"))
6866
#
6967
# @example Apply back pressure instead of dropping messages
70-
# http_log_device = Logtail::LogDevices::HTTP.new("my_logtail_source_token", request_queue: SizedQueue.new(25))
68+
# http_log_device = Logtail::LogDevices::HTTP.new("<source_token>", ingesting_host: "<ingesting_host>", request_queue: SizedQueue.new(25))
7169
# Logtail::Logger.new(http_log_device)
7270
def initialize(source_token, options = {})
71+
# Handle backward-compatibility of argument names
72+
options[:ingesting_host] ||= options[:ingesting_host] if options[:ingesting_host].present?
73+
options[:ingesting_port] ||= options[:logtail_port] if options[:logtail_port].present?
74+
options[:ingesting_scheme] ||= options[:logtail_scheme] if options[:logtail_scheme].present?
75+
7376
@source_token = source_token || raise(ArgumentError.new("The source_token parameter cannot be blank"))
74-
@logtail_host = options[:logtail_host] || ENV['LOGTAIL_HOST'] || LOGTAIL_HOST
75-
@logtail_port = options[:logtail_port] || ENV['LOGTAIL_PORT'] || LOGTAIL_PORT
76-
@logtail_scheme = options[:logtail_scheme] || ENV['LOGTAIL_SCHEME'] || LOGTAIL_SCHEME
77+
@ingesting_host = options[:ingesting_host] || ENV['INGESTING_HOST'] || ENV['LOGTAIL_HOST'] || DEFAULT_INGESTING_HOST
78+
@ingesting_port = options[:ingesting_port] || ENV['INGESTING_PORT'] || ENV['LOGTAIL_PORT'] || DEFAULT_INGESTING_PORT
79+
@ingesting_scheme = options[:ingesting_scheme] || ENV['INGESTING_SCHEME'] || ENV['LOGTAIL_SCHEME'] || DEFAULT_INGESTING_SCHEME
7780
@batch_size = options[:batch_size] || 1_000
7881
@flush_continuously = options[:flush_continuously] != false
7982
@flush_interval = options[:flush_interval] || 2 # 2 seconds
@@ -153,7 +156,7 @@ def verify_delivery!
153156
if @last_resp.nil?
154157
print "."
155158
elsif @last_resp.code == "202"
156-
puts "Log delivery successful! View your logs at https://logtail.com"
159+
puts "Log delivery successful! View your logs at https://telemetry.betterstack.com"
157160
else
158161
raise <<-MESSAGE
159162
@@ -282,9 +285,9 @@ def intervaled_flush_ready?
282285

283286
# Builds an `Net::HTTP` object to deliver requests over.
284287
def build_http
285-
http = Net::HTTP.new(@logtail_host, @logtail_port)
288+
http = Net::HTTP.new(@ingesting_host, @ingesting_port)
286289
http.set_debug_output(Config.instance.debug_logger) if Config.instance.debug_logger
287-
if @logtail_scheme == 'https'
290+
if @ingesting_scheme == 'https'
288291
http.use_ssl = true
289292
# Verification on Windows fails despite having a valid certificate.
290293
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
@@ -360,7 +363,7 @@ def deliver_requests(conn)
360363

361364
Logtail::Config.instance.debug do
362365
if resp.code == "202"
363-
"Logs successfully sent! View your logs at https://logtail.com"
366+
"Logs successfully sent! View your logs at https://telemetry.betterstack.com"
364367
else
365368
"Log delivery failed! status: #{resp.code}, body: #{resp.body}"
366369
end

lib/logtail/log_entry.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ class LogEntry #:nodoc:
1616

1717
attr_reader :context_snapshot, :event, :level, :message, :progname, :tags, :time
1818

19-
# Creates a log entry suitable to be sent to the Logtail API.
19+
# Creates a log entry suitable to be sent to the Better Stack Telemetry API.
2020
# @param level [Integer] the log level / severity
2121
# @param time [Time] the exact time the log message was written
2222
# @param progname [String] the progname scope for the log message

spec/logtail/log_devices/http_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@
125125
let(:time) { Time.utc(2016, 9, 1, 12, 0, 0) }
126126

127127
it "should deliver requests on an interval" do
128-
stub = stub_request(:post, "https://in.logtail.com/").
128+
stub = stub_request(:post, "https://in.logs.betterstack.com/").
129129
with(
130130
:body => start_with("\x92\x84\xA5level\xA4INFO\xA2dt\xBB2016-09-01T12:00:00.000000Z\xA7message\xB2test log message 1".force_encoding("ASCII-8BIT")),
131131
:headers => {

0 commit comments

Comments
 (0)