logtail-rack 0.2.3 → 0.2.5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 43f0b7693831d0097e1496ba79258afc7b8b7cda69d805fa99248cbc79812181
4
- data.tar.gz: 23bdde6dc4a16420b3f8604edc3266775b248e2a51177be01c64a314577612d9
3
+ metadata.gz: ea4d53412f33978d3cc76fc31a163946d6903e7959301178aae01c32e7b51230
4
+ data.tar.gz: bb99faa3536a6f42582585336689c206b22086455cb24c642a07b97b7d28cf37
5
5
  SHA512:
6
- metadata.gz: f9dc63f41ea21c4f31360608d82ec1cbf6652cac1774a28695a845a36858a95215ee24d49696278f07267266922659559cee8790a85767e64cd143e833232950
7
- data.tar.gz: c1faf9719cac776039dac04d3acc9b91b9520f9f7983a4db242344e9f66cfedd37feb0bfe8b6575185b883918e45b37eaf76a61708f364dd627a8805349f6989
6
+ metadata.gz: 87d33e37c66ad70843676eb7560ed66ab395f62643eb49670d620008d664c92460f3b293bc429b84f47ac4a363e042c8986575c5472188dcd325ed4bca273970
7
+ data.tar.gz: 97b69afc3342e0089c542574d2b3babfa2ac45fc96758205d7802761191b455325620f35e7b3e4759d7fc1a85883f8c8abc7a489db26e12000598d5bbd55156f
data/.gitignore CHANGED
@@ -10,6 +10,7 @@
10
10
  .ruby-version
11
11
  coverage
12
12
  Gemfile.lock
13
+ !/example-project/Gemfile.lock
13
14
  *.swp
14
15
  *.gem
15
16
 
data/README.md CHANGED
@@ -1,10 +1,22 @@
1
- # 🪵 Logtail Integration For Rack
1
+ # [Better Stack](https://betterstack.com/logs) Rack client
2
+
3
+ 📣 Logtail is now part of Better Stack. [Learn more ⇗](https://betterstack.com/press/introducing-better-stack/)
4
+
5
+ [![Better Stack dashboard](https://github.com/logtail/logtail-python/assets/10132717/e2a1196b-7924-4abc-9b85-055e17b5d499)](https://betterstack.com/logs)
2
6
 
3
7
  [![ISC License](https://img.shields.io/badge/license-ISC-ff69b4.svg)](LICENSE.md)
4
8
  [![Gem Version](https://badge.fury.io/rb/logtail-rack.svg)](https://badge.fury.io/rb/logtail-rack)
5
- [![Build Status](https://github.com/logtail/logtail-ruby-rack/workflows/build/badge.svg)](https://github.com/logtail/logtail-ruby-rack/actions?query=workflow%3Abuild)
9
+ [![Build Status](https://github.com/logtail/logtail-ruby-rack/actions/workflows/main.yml/badge.svg)](https://github.com/logtail/logtail-ruby-rack/actions/workflows/main.yml)
10
+
11
+ Experience SQL-compatible structured log management based on ClickHouse. [Learn more ⇗](https://betterstack.com/logs)
12
+
13
+ ## Documentation
14
+
15
+ [Getting started ⇗](https://betterstack.com/docs/logs/ruby-and-rails/#logging-from-rack)
16
+
17
+ ## Need help?
18
+ Please let us know at [hello@betterstack.com](mailto:hello@betterstack.com). We're happy to help!
6
19
 
7
- This library integrates the [`logtail` Ruby library](https://github.com/logtail/logtail-ruby) with the [rack](https://github.com/rack/rack) framework,
8
- turning your Rack logs into rich structured events.
20
+ ---
9
21
 
10
- * **Sign-up: [https://logtail.com](https://logtail.com)**
22
+ [ISC license](https://github.com/logtail/logtail-ruby-rack/blob/main/LICENSE.md), [example project](https://github.com/logtail/logtail-ruby-rack/tree/main/example-project)
@@ -0,0 +1,7 @@
1
+ source "https://rubygems.org"
2
+
3
+ gem "rack", "~> 3.0"
4
+
5
+ gem "rackup", "~> 2.1"
6
+
7
+ gem "logtail-rack", "~> 0.2.4"
@@ -0,0 +1,25 @@
1
+ GEM
2
+ remote: https://rubygems.org/
3
+ specs:
4
+ logtail (0.1.12)
5
+ msgpack (~> 1.0)
6
+ logtail-rack (0.2.4)
7
+ logtail (~> 0.1)
8
+ rack (>= 1.2, < 4.0)
9
+ msgpack (1.7.2)
10
+ rack (3.0.0)
11
+ rackup (2.1.0)
12
+ rack (>= 3)
13
+ webrick (~> 1.8)
14
+ webrick (1.8.1)
15
+
16
+ PLATFORMS
17
+ arm64-darwin-22
18
+
19
+ DEPENDENCIES
20
+ logtail-rack (~> 0.2.4)
21
+ rack (~> 3.0)
22
+ rackup (~> 2.1)
23
+
24
+ BUNDLED WITH
25
+ 2.3.14
@@ -0,0 +1,40 @@
1
+ # Example project
2
+
3
+ To help you get started with using Better Stack in your Rack projects, we have prepared a simple program that showcases the usage of Logtail logger.
4
+
5
+ ## Download and install the example project
6
+
7
+ You can download the [example project](https://github.com/logtail/logtail-ruby-rack/tree/main/example-project) from GitHub directly or you can clone it to a select directory. Make sure you are in the projects directory and run the following command:
8
+
9
+ ```bash
10
+ bundle install
11
+ ```
12
+
13
+ This will install all dependencies listed in the `Gemfile.lock` file.
14
+
15
+ Then replace `<SOURCE_TOKEN>` in `config.ru` with your actual source token which you can find by going to [Better Stack Logs](https://logs.betterstack.com/dashboard) -> Source -> Edit.
16
+
17
+ ```ruby
18
+ http_io_device = Logtail::LogDevices::HTTP.new("<YOUR_ACTUAL_SOURCE_TOKEN>")
19
+ ```
20
+
21
+ ## Run the example project
22
+
23
+ To run the example application, run the following command:
24
+
25
+ ```bash
26
+ rackup
27
+ ```
28
+
29
+ This will start a local server and you visit [http://127.0.0.1:9292](http://127.0.0.1:9292) in your browser.
30
+
31
+ You should see the following output:
32
+
33
+ ```bash
34
+ All done!
35
+ Log into your Logtail account to check your logs.
36
+ ```
37
+
38
+ This will create a total of 4 different logs. You can review these logs in Better Stack.
39
+
40
+ You can visit any path on the server to see the request path being logged in context. Visit [/error](http://127.0.0.1:9292) to see an example exception being logged.
@@ -0,0 +1,23 @@
1
+ require 'logtail-rack'
2
+ require './logging_app'
3
+
4
+ # Initialization of logging middlewares
5
+ use Logtail::Integrations::Rack::HTTPContext
6
+ use Logtail::Integrations::Rack::HTTPEvents
7
+ use Logtail::Integrations::Rack::ErrorEvent
8
+
9
+ # HTTP IO device sends logs to Better Stack, replace <SOURCE_TOKEN> with your real source token
10
+ http_io_device = Logtail::LogDevices::HTTP.new("<SOURCE_TOKEN>")
11
+
12
+ # STDOUT IO device sends logs to console output
13
+ stdout_io_device = STDOUT
14
+
15
+ # Logger initialization, you can use any number of IO devices
16
+ logger = Logtail::Logger.new(http_io_device, stdout_io_device)
17
+ Logtail::Config.instance.logger = logger
18
+
19
+ # App initialization
20
+ logging_app = LoggingApp.new(logger)
21
+ run do |env|
22
+ logging_app.run(env)
23
+ end
@@ -0,0 +1,24 @@
1
+ require 'logtail-rack'
2
+
3
+ class LoggingApp
4
+ def initialize(logger)
5
+ @logger = logger
6
+ end
7
+
8
+ def run(env)
9
+ @logger.info("I am using Better Stack! 🚀")
10
+
11
+ # You can also provide additional information when logging
12
+ @logger.debug("Logging structured data...",
13
+ name: {
14
+ first: "John",
15
+ last: "Smith"
16
+ },
17
+ id: 123456
18
+ )
19
+
20
+ raise RuntimeError.new("Visiting /error raises an error. You should see it in Better Stack.") if env["REQUEST_PATH"].start_with?("/error")
21
+
22
+ [200, {}, ["All done!\nLog into your Logtail account to check your logs."]]
23
+ end
24
+ end
@@ -12,7 +12,7 @@ module Logtail
12
12
  def call(env)
13
13
  request = Util::Request.new(env)
14
14
  context = Contexts::HTTP.new(
15
- host: Util::Encoding.force_utf8_encoding(request),
15
+ host: Util::Encoding.force_utf8_encoding(request.host),
16
16
  method: Util::Encoding.force_utf8_encoding(request.request_method),
17
17
  path: request.path,
18
18
  remote_addr: Util::Encoding.force_utf8_encoding(request.ip),
@@ -269,10 +269,11 @@ module Logtail
269
269
  end
270
270
 
271
271
  def filter_http_headers(headers)
272
- headers.each do |name, _|
273
- normalized_header_name = self.class.normalize_header_name(name)
274
- headers[name] = "[FILTERED]" if self.class.http_header_filters&.include?(normalized_header_name)
275
- end
272
+ headers.map do |name, value|
273
+ normalized_name = self.class.normalize_header_name(name)
274
+ is_filtered = self.class.http_header_filters&.include?(normalized_name)
275
+ [name, is_filtered ? "[FILTERED]" : value]
276
+ end.to_h
276
277
  end
277
278
 
278
279
  def safe_to_i(val)
@@ -1,7 +1,7 @@
1
1
  module Logtail
2
2
  module Integrations
3
3
  module Rack
4
- VERSION = "0.2.3"
4
+ VERSION = "0.2.5"
5
5
  end
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: logtail-rack
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.3
4
+ version: 0.2.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Logtail
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2023-08-29 00:00:00.000000000 Z
11
+ date: 2024-01-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: logtail
@@ -100,6 +100,11 @@ files:
100
100
  - LICENSE.md
101
101
  - README.md
102
102
  - Rakefile
103
+ - example-project/Gemfile
104
+ - example-project/Gemfile.lock
105
+ - example-project/README.md
106
+ - example-project/config.ru
107
+ - example-project/logging_app.rb
103
108
  - lib/logtail-rack.rb
104
109
  - lib/logtail-rack/config.rb
105
110
  - lib/logtail-rack/error_event.rb
@@ -136,7 +141,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
136
141
  - !ruby/object:Gem::Version
137
142
  version: '0'
138
143
  requirements: []
139
- rubygems_version: 3.3.3
144
+ rubygems_version: 3.3.7
140
145
  signing_key:
141
146
  specification_version: 4
142
147
  summary: Logtail integration for Rack