logtail 0.1.13 → 0.1.15
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 +4 -4
- data/.github/workflows/main.yml +13 -12
- data/Gemfile +1 -0
- data/Rakefile +4 -4
- data/example-project/Gemfile +1 -1
- data/example-project/Gemfile.lock +2 -2
- data/example-project/README.md +4 -4
- data/example-project/main.rb +5 -5
- data/lib/logtail/log_devices/http.rb +23 -20
- data/lib/logtail/log_entry.rb +1 -1
- data/lib/logtail/version.rb +1 -1
- data/spec/logtail/log_devices/http_spec.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6576745c59d3a1051e33d2c80c72cb085657d1ac5d4ffdc3eddd25d453eb7ce0
|
4
|
+
data.tar.gz: dabb146bd9c0904bed8213745d027fc87844314fe792c591eacb917c6be66cd9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 53ca720088be23dc6896413709c24d669afb1bf62297b6366467b4a36e912c153403ad8a38ab0edf134932c84893bc5bd5a02c76bc2b7a52e468b731474c89ed
|
7
|
+
data.tar.gz: ed3d8f6af7c41eee437253d6b510d76dd521c3b747791a7ef5049b59b47924da838e1e05395c4c8186e809119de4d6edaf0d0debde18652716f273933f9e97b7
|
data/.github/workflows/main.yml
CHANGED
@@ -15,18 +15,19 @@ jobs:
|
|
15
15
|
|
16
16
|
matrix:
|
17
17
|
ruby-version:
|
18
|
-
- 3
|
19
|
-
- 3.
|
20
|
-
- 3.
|
21
|
-
- 2
|
22
|
-
-
|
23
|
-
-
|
24
|
-
- 2.
|
25
|
-
- 2.
|
26
|
-
-
|
27
|
-
- jruby-9.
|
28
|
-
-
|
29
|
-
- truffleruby-
|
18
|
+
- "3"
|
19
|
+
- "3.4"
|
20
|
+
- "3.3"
|
21
|
+
- "3.2"
|
22
|
+
- "3.1"
|
23
|
+
- "3.0"
|
24
|
+
- "2.7"
|
25
|
+
- "2.6"
|
26
|
+
- "2.5"
|
27
|
+
- "jruby-9.4.3.0"
|
28
|
+
- "jruby-9.2.14.0"
|
29
|
+
- "truffleruby-23.0.0"
|
30
|
+
- "truffleruby-22.1.0"
|
30
31
|
|
31
32
|
steps:
|
32
33
|
- uses: actions/checkout@v2
|
data/Gemfile
CHANGED
data/Rakefile
CHANGED
@@ -15,7 +15,7 @@ def puts_with_level(message, level = :info)
|
|
15
15
|
end
|
16
16
|
|
17
17
|
task :test_the_pipes, [:source_token] do |t, args|
|
18
|
-
support_email = "
|
18
|
+
support_email = "hello@betterstack.com"
|
19
19
|
# Do not modify below this line. It's important to keep the `Logtail::Logger`
|
20
20
|
# because it provides an API for logging structured data and capturing context.
|
21
21
|
header = <<~HEREDOC
|
@@ -31,7 +31,7 @@ task :test_the_pipes, [:source_token] do |t, args|
|
|
31
31
|
if response.is_a?(Exception)
|
32
32
|
message = <<~HEREDOC
|
33
33
|
Unable to deliver logs.
|
34
|
-
Here's what we received from the
|
34
|
+
Here's what we received from the Better Stack Telemetry API:
|
35
35
|
#{response.inspect}
|
36
36
|
If you continue to have trouble please contact support:
|
37
37
|
#{support_email}
|
@@ -39,13 +39,13 @@ task :test_the_pipes, [:source_token] do |t, args|
|
|
39
39
|
puts_with_level(message, :error)
|
40
40
|
elsif response.is_a?(Net::HTTPResponse)
|
41
41
|
if response.code.start_with? '2'
|
42
|
-
puts_with_level("Logs successfully sent! View them at https://
|
42
|
+
puts_with_level("Logs successfully sent! View them at https://telemetry.betterstack.com",
|
43
43
|
:success)
|
44
44
|
else
|
45
45
|
message =
|
46
46
|
<<~HEREDOC
|
47
47
|
Unable to deliver logs.
|
48
|
-
We received a #{response.code} response from the
|
48
|
+
We received a #{response.code} response from the Better Stack Telemetry API:
|
49
49
|
#{response.body.inspect}
|
50
50
|
If you continue to have trouble please contact support:
|
51
51
|
#{support_email}
|
data/example-project/Gemfile
CHANGED
@@ -1,2 +1,2 @@
|
|
1
1
|
source 'https://rubygems.org'
|
2
|
-
gem "logtail", "~> 0.1.
|
2
|
+
gem "logtail", "~> 0.1.15"
|
data/example-project/README.md
CHANGED
@@ -15,13 +15,13 @@ This will install all dependencies listed in the `Gemfile.lock` file.
|
|
15
15
|
Alternatively, add `gem "logtail"` to your `Gemfile` manually and then run `bundle install`.
|
16
16
|
|
17
17
|
## Run the example project
|
18
|
-
|
19
|
-
|
20
|
-
|
18
|
+
|
19
|
+
_Don't forget to replace `<source_token>` and `<ingesting_host>` with your actual source token and ingesting host which you can find by going to **[Sources](https://telemetry.betterstack.com/team/0/sources) -> Configure** in Better Stack._
|
20
|
+
|
21
21
|
To run the example application, run the following command adding your source token:
|
22
22
|
|
23
23
|
```bash
|
24
|
-
bundle exec ruby main.rb <
|
24
|
+
bundle exec ruby main.rb <source_token> <ingesting_host>
|
25
25
|
```
|
26
26
|
|
27
27
|
This will create a total of 5 different logs, each corresponding to a different log level. You can review these logs in Logtail.
|
data/example-project/main.rb
CHANGED
@@ -7,12 +7,12 @@
|
|
7
7
|
require "logtail"
|
8
8
|
|
9
9
|
# Check for program arguments
|
10
|
-
if ARGV.length !=
|
11
|
-
puts "Program needs source token to run. Run the program as followed\nbundle exec ruby main.rb <
|
10
|
+
if ARGV.length != 2
|
11
|
+
puts "Program needs source token and ingesting host to run. Run the program as followed\nbundle exec ruby main.rb <source_token> <ingesting_host>"
|
12
12
|
exit
|
13
13
|
end
|
14
14
|
# Create logger
|
15
|
-
http_device = Logtail::LogDevices::HTTP.new(ARGV[0])
|
15
|
+
http_device = Logtail::LogDevices::HTTP.new(ARGV[0], ingesting_host: ARGV[1])
|
16
16
|
logger = Logtail::Logger.new(http_device)
|
17
17
|
|
18
18
|
# Filter logs that shouldn't be sent to Better Stack, see {Logtail::LogEntry} for available attributes
|
@@ -21,10 +21,10 @@ Logtail.config.filter_sent_to_better_stack { |log_entry| log_entry.message.inclu
|
|
21
21
|
# LOGGING
|
22
22
|
|
23
23
|
# Send debug logs messages using the debug() method
|
24
|
-
logger.debug("
|
24
|
+
logger.debug("Better Stack is ready!")
|
25
25
|
|
26
26
|
# Send informative messages about interesting events using the info() method
|
27
|
-
logger.info("I am using
|
27
|
+
logger.info("I am using Better Stack!")
|
28
28
|
|
29
29
|
# Send messages about worrying events using the warn() method
|
30
30
|
# You can also log additional structured data
|
@@ -17,11 +17,9 @@ module Logtail
|
|
17
17
|
#
|
18
18
|
# See {#initialize} for options and more details.
|
19
19
|
class HTTP
|
20
|
-
|
21
|
-
|
22
|
-
|
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
|
25
23
|
CONTENT_TYPE = "application/msgpack".freeze
|
26
24
|
USER_AGENT = "Logtail Ruby/#{Logtail::VERSION} (HTTP)".freeze
|
27
25
|
|
@@ -36,15 +34,15 @@ module Logtail
|
|
36
34
|
# you can drop the log messages instead by passing a {DroppingSizedQueue} via the
|
37
35
|
# `:request_queue` option.
|
38
36
|
#
|
39
|
-
# @param source_token [String] The API key provided to you after you add your
|
40
|
-
# [
|
37
|
+
# @param source_token [String] The API key provided to you after you add your source to
|
38
|
+
# [Better Stack](https://telemetry.betterstack.com).
|
41
39
|
# @param [Hash] options the options to create a HTTP log device with.
|
42
40
|
# @option attributes [Symbol] :batch_size (1000) Determines the maximum of log lines in
|
43
41
|
# each HTTP payload. If the queue exceeds this limit an HTTP request will be issued. Bigger
|
44
42
|
# payloads mean higher throughput, but also use more memory. Logtail will not accept
|
45
43
|
# payloads larger than 1mb.
|
46
44
|
# @option attributes [Symbol] :flush_continuously (true) This should only be disabled under
|
47
|
-
# special
|
45
|
+
# special circumstances (like test suites). Setting this to `false` disables the
|
48
46
|
# continuous flushing of log message. As a result, flushing must be handled externally
|
49
47
|
# via the #flush method.
|
50
48
|
# @option attributes [Symbol] :flush_interval (1) How often the client should
|
@@ -55,25 +53,30 @@ module Logtail
|
|
55
53
|
# single persistent connection. After this number is met, the connection will be closed
|
56
54
|
# and a new one will be opened.
|
57
55
|
# @option attributes [Symbol] :request_queue (FlushableDroppingSizedQueue.new(25)) The request
|
58
|
-
# queue object that queues Net::HTTP requests for delivery. By
|
56
|
+
# queue object that queues Net::HTTP requests for delivery. By default this is a
|
59
57
|
# `FlushableDroppingSizedQueue` of size `25`. Meaning once the queue fills up to 25
|
60
58
|
# requests new requests will be dropped. If you'd prefer to apply back pressure,
|
61
59
|
# ensuring you do not lose log data, pass a standard {SizedQueue}. See examples for
|
62
60
|
# an example.
|
63
|
-
# @option attributes [Symbol] :
|
64
|
-
# The default is set via {
|
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}.
|
65
63
|
#
|
66
64
|
# @example Basic usage
|
67
|
-
# Logtail::Logger.new(Logtail::LogDevices::HTTP.new("
|
65
|
+
# Logtail::Logger.new(Logtail::LogDevices::HTTP.new("<source_token>", ingesting_host: "<ingesting_host>"))
|
68
66
|
#
|
69
67
|
# @example Apply back pressure instead of dropping messages
|
70
|
-
# http_log_device = Logtail::LogDevices::HTTP.new("
|
68
|
+
# http_log_device = Logtail::LogDevices::HTTP.new("<source_token>", ingesting_host: "<ingesting_host>", request_queue: SizedQueue.new(25))
|
71
69
|
# Logtail::Logger.new(http_log_device)
|
72
70
|
def initialize(source_token, options = {})
|
71
|
+
# Handle backward-compatibility of argument names
|
72
|
+
options[:ingesting_host] ||= options[:logtail_host]
|
73
|
+
options[:ingesting_port] ||= options[:logtail_port]
|
74
|
+
options[:ingesting_scheme] ||= options[:logtail_scheme]
|
75
|
+
|
73
76
|
@source_token = source_token || raise(ArgumentError.new("The source_token parameter cannot be blank"))
|
74
|
-
@
|
75
|
-
@
|
76
|
-
@
|
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
|
77
80
|
@batch_size = options[:batch_size] || 1_000
|
78
81
|
@flush_continuously = options[:flush_continuously] != false
|
79
82
|
@flush_interval = options[:flush_interval] || 2 # 2 seconds
|
@@ -153,7 +156,7 @@ module Logtail
|
|
153
156
|
if @last_resp.nil?
|
154
157
|
print "."
|
155
158
|
elsif @last_resp.code == "202"
|
156
|
-
puts "Log delivery successful! View your logs at https://
|
159
|
+
puts "Log delivery successful! View your logs at https://telemetry.betterstack.com"
|
157
160
|
else
|
158
161
|
raise <<-MESSAGE
|
159
162
|
|
@@ -282,9 +285,9 @@ MESSAGE
|
|
282
285
|
|
283
286
|
# Builds an `Net::HTTP` object to deliver requests over.
|
284
287
|
def build_http
|
285
|
-
http = Net::HTTP.new(@
|
288
|
+
http = Net::HTTP.new(@ingesting_host, @ingesting_port)
|
286
289
|
http.set_debug_output(Config.instance.debug_logger) if Config.instance.debug_logger
|
287
|
-
if @
|
290
|
+
if @ingesting_scheme == 'https'
|
288
291
|
http.use_ssl = true
|
289
292
|
# Verification on Windows fails despite having a valid certificate.
|
290
293
|
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
|
@@ -360,7 +363,7 @@ MESSAGE
|
|
360
363
|
|
361
364
|
Logtail::Config.instance.debug do
|
362
365
|
if resp.code == "202"
|
363
|
-
"Logs successfully sent! View your logs at https://
|
366
|
+
"Logs successfully sent! View your logs at https://telemetry.betterstack.com"
|
364
367
|
else
|
365
368
|
"Log delivery failed! status: #{resp.code}, body: #{resp.body}"
|
366
369
|
end
|
data/lib/logtail/log_entry.rb
CHANGED
@@ -16,7 +16,7 @@ module Logtail
|
|
16
16
|
|
17
17
|
attr_reader :context_snapshot, :event, :level, :message, :progname, :tags, :time
|
18
18
|
|
19
|
-
# Creates a log entry suitable to be sent to the
|
19
|
+
# Creates a log entry suitable to be sent to the Better Stack Telemetry API.
|
20
20
|
# @param level [Integer] the log level / severity
|
21
21
|
# @param time [Time] the exact time the log message was written
|
22
22
|
# @param progname [String] the progname scope for the log message
|
data/lib/logtail/version.rb
CHANGED
@@ -125,7 +125,7 @@ describe Logtail::LogDevices::HTTP do
|
|
125
125
|
let(:time) { Time.utc(2016, 9, 1, 12, 0, 0) }
|
126
126
|
|
127
127
|
it "should deliver requests on an interval" do
|
128
|
-
stub = stub_request(:post, "https://in.
|
128
|
+
stub = stub_request(:post, "https://in.logs.betterstack.com/").
|
129
129
|
with(
|
130
130
|
:body => start_with("\x92\x84\xA5level\xA4INFO\xA2dt\xBB2016-09-01T12:00:00.000000Z\xA7message\xB2test log message 1".force_encoding("ASCII-8BIT")),
|
131
131
|
:headers => {
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: logtail
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.15
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Better Stack
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2025-02-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: msgpack
|