logtail-rack 0.2.4 → 0.2.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/README.md +17 -5
- data/example-project/Gemfile +7 -0
- data/example-project/Gemfile.lock +25 -0
- data/example-project/README.md +40 -0
- data/example-project/config.ru +23 -0
- data/example-project/logging_app.rb +24 -0
- data/lib/logtail-rack/http_events.rb +5 -4
- data/lib/logtail-rack/version.rb +1 -1
- metadata +7 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ea4d53412f33978d3cc76fc31a163946d6903e7959301178aae01c32e7b51230
|
4
|
+
data.tar.gz: bb99faa3536a6f42582585336689c206b22086455cb24c642a07b97b7d28cf37
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 87d33e37c66ad70843676eb7560ed66ab395f62643eb49670d620008d664c92460f3b293bc429b84f47ac4a363e042c8986575c5472188dcd325ed4bca273970
|
7
|
+
data.tar.gz: 97b69afc3342e0089c542574d2b3babfa2ac45fc96758205d7802761191b455325620f35e7b3e4759d7fc1a85883f8c8abc7a489db26e12000598d5bbd55156f
|
data/.gitignore
CHANGED
data/README.md
CHANGED
@@ -1,10 +1,22 @@
|
|
1
|
-
#
|
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/
|
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
|
-
|
8
|
-
turning your Rack logs into rich structured events.
|
20
|
+
---
|
9
21
|
|
10
|
-
|
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,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
|
@@ -269,10 +269,11 @@ module Logtail
|
|
269
269
|
end
|
270
270
|
|
271
271
|
def filter_http_headers(headers)
|
272
|
-
headers.
|
273
|
-
|
274
|
-
|
275
|
-
|
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)
|
data/lib/logtail-rack/version.rb
CHANGED
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.
|
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:
|
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
|