Skip to content

Commit

Permalink
core: Rename SinatraMiddleware to RackMiddleware (#16)
Browse files Browse the repository at this point in the history
  • Loading branch information
Eth3rnit3 authored Dec 10, 2024
1 parent d976842 commit b910990
Show file tree
Hide file tree
Showing 6 changed files with 85 additions and 63 deletions.
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
## v0.2.0 (2024-02-02)

### New feature:

- Add support for RackMiddleware ([`2e8e49e`](https://github.com/buyco/datadog-json-logger/commit/0bcaf99a7ca6082434ee5fbccee00d46a15813af)) (by Eth3rnit3)

### Breaking change:

- Rename SinatraMiddleware to RackMiddleware ([`2e8e49e`](https://github.com/buyco/datadog-json-logger/commit/0bcaf99a7ca6082434ee5fbccee00d46a15813af)) (by Eth3rnit3)

## v0.1.5 (2024-02-02)

### New feature:
Expand Down
119 changes: 64 additions & 55 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,39 +1,44 @@
PATH
remote: .
specs:
datadog-json_logger (0.1.10)
datadog-json_logger (0.2.0)
ddtrace (>= 1.16)

GEM
remote: https://rubygems.org/
specs:
abbrev (0.1.1)
addressable (2.8.5)
public_suffix (>= 2.0.2, < 6.0)
abbrev (0.1.2)
addressable (2.8.7)
public_suffix (>= 2.0.2, < 7.0)
ast (2.4.2)
axiom-types (0.1.1)
descendants_tracker (~> 0.0.4)
ice_nine (~> 0.11.0)
thread_safe (~> 0.3, >= 0.3.1)
byebug (11.1.3)
childprocess (5.1.0)
logger (~> 1.5)
coercible (1.0.0)
descendants_tracker (~> 0.0.1)
datadog-ci (0.3.0)
datadog-ci (0.8.3)
msgpack
ddtrace (1.16.2)
datadog-ci (~> 0.3.0)
debase-ruby_core_source (= 3.2.2)
libdatadog (~> 5.0.0.1.0)
date (3.4.1)
ddtrace (1.23.3)
datadog-ci (~> 0.8.1)
debase-ruby_core_source (= 3.3.1)
libdatadog (~> 7.0.0.1.0)
libddwaf (~> 1.14.0.0.0)
msgpack
debase-ruby_core_source (3.2.2)
debase-ruby_core_source (3.3.1)
descendants_tracker (0.0.4)
thread_safe (~> 0.3, >= 0.3.1)
diff-lcs (1.5.0)
docile (1.4.0)
erubi (1.12.0)
ffi (1.16.3)
flay (2.13.1)
diff-lcs (1.5.1)
docile (1.4.1)
erubi (1.13.0)
ffi (1.17.0)
ffi (1.17.0-arm64-darwin)
ffi (1.17.0-x86_64-linux-gnu)
flay (2.13.3)
erubi (~> 1.10)
path_expander (~> 1.0)
ruby_parser (~> 3.0)
Expand All @@ -43,112 +48,116 @@ GEM
ruby_parser (~> 3.1, > 3.1.0)
sexp_processor (~> 4.8)
ice_nine (0.11.2)
io-console (0.6.0)
io-console (0.8.0)
irb (1.9.1)
rdoc
reline (>= 0.3.8)
json (2.6.3)
json (2.9.0)
kwalify (0.7.2)
language_server-protocol (3.17.0.3)
launchy (2.5.2)
launchy (3.0.1)
addressable (~> 2.8)
libdatadog (5.0.0.1.0)
libdatadog (5.0.0.1.0-x86_64-linux)
childprocess (~> 5.0)
libdatadog (7.0.0.1.0)
libdatadog (7.0.0.1.0-x86_64-linux)
libddwaf (1.14.0.0.0)
ffi (~> 1.0)
libddwaf (1.14.0.0.0-arm64-darwin)
ffi (~> 1.0)
libddwaf (1.14.0.0.0-x86_64-linux)
ffi (~> 1.0)
msgpack (1.7.2)
parallel (1.23.0)
logger (1.6.2)
msgpack (1.7.5)
parallel (1.26.3)
parser (3.2.2.4)
ast (~> 2.4.1)
racc
path_expander (1.1.1)
psych (5.1.2)
path_expander (1.1.3)
psych (5.2.1)
date
stringio
public_suffix (5.0.4)
racc (1.7.3)
public_suffix (6.0.1)
racc (1.8.1)
rack (3.1.8)
rack-test (2.1.0)
rack (>= 1.3)
rainbow (3.1.1)
rake (13.1.0)
rake (13.2.1)
rbs (3.3.2)
abbrev
rdoc (6.7.0)
rdoc (6.8.1)
psych (>= 4.0.0)
reek (6.1.4)
kwalify (~> 0.7.0)
parser (~> 3.2.0)
rainbow (>= 2.0, < 4.0)
regexp_parser (2.8.2)
reline (0.4.0)
regexp_parser (2.9.3)
reline (0.5.12)
io-console (~> 0.5)
rexml (3.3.9)
rspec (3.12.0)
rspec-core (~> 3.12.0)
rspec-expectations (~> 3.12.0)
rspec-mocks (~> 3.12.0)
rspec-core (3.12.2)
rspec-support (~> 3.12.0)
rspec-expectations (3.12.3)
rspec (3.13.0)
rspec-core (~> 3.13.0)
rspec-expectations (~> 3.13.0)
rspec-mocks (~> 3.13.0)
rspec-core (3.13.2)
rspec-support (~> 3.13.0)
rspec-expectations (3.13.3)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.12.0)
rspec-mocks (3.12.6)
rspec-support (~> 3.13.0)
rspec-mocks (3.13.2)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.12.0)
rspec-support (3.12.1)
rubocop (1.57.2)
rspec-support (~> 3.13.0)
rspec-support (3.13.2)
rubocop (1.59.0)
json (~> 2.3)
language_server-protocol (>= 3.17.0)
parallel (~> 1.10)
parser (>= 3.2.2.4)
rainbow (>= 2.2.2, < 4.0)
regexp_parser (>= 1.8, < 3.0)
rexml (>= 3.2.5, < 4.0)
rubocop-ast (>= 1.28.1, < 2.0)
rubocop-ast (>= 1.30.0, < 2.0)
ruby-progressbar (~> 1.7)
unicode-display_width (>= 2.4.0, < 3.0)
rubocop-ast (1.30.0)
parser (>= 3.2.1.0)
rubocop-capybara (2.19.0)
rubocop-capybara (2.21.0)
rubocop (~> 1.41)
rubocop-factory_bot (2.26.0)
rubocop (~> 1.41)
rubocop-factory_bot (2.24.0)
rubocop (~> 1.33)
rubocop-rake (0.6.0)
rubocop (~> 1.0)
rubocop-rspec (2.25.0)
rubocop (~> 1.40)
rubocop-capybara (~> 2.17)
rubocop-factory_bot (~> 2.22)
ruby-progressbar (1.13.0)
ruby_parser (3.20.3)
ruby_parser (3.21.1)
racc (~> 1.5)
sexp_processor (~> 4.16)
rubycritic (4.9.0)
rubycritic (4.9.1)
flay (~> 2.13)
flog (~> 4.7)
launchy (>= 2.5.2)
parser (>= 3.2.2.1)
parser (>= 3.2.2.4)
rainbow (~> 3.1.1)
reek (~> 6.0, < 7.0)
reek (~> 6.0, < 6.2)
rexml
ruby_parser (~> 3.20)
ruby_parser (~> 3.21)
simplecov (>= 0.22.0)
tty-which (~> 0.5.0)
virtus (~> 2.0)
sexp_processor (4.17.0)
sexp_processor (4.17.3)
simplecov (0.22.0)
docile (~> 1.1)
simplecov-html (~> 0.11)
simplecov_json_formatter (~> 0.1)
simplecov-html (0.12.3)
simplecov-html (0.13.1)
simplecov_json_formatter (0.1.4)
stringio (3.1.1)
stringio (3.1.2)
thread_safe (0.3.6)
tty-which (0.5.0)
unicode-display_width (2.5.0)
unicode-display_width (2.6.0)
virtus (2.0.0)
axiom-types (~> 0.1)
coercible (~> 1.0)
Expand Down
11 changes: 7 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,15 +83,18 @@ Sinatra::Application.logger.info("hello")
# {"dd":{"trace_id":"0","span_id":"0","env":null,"service":"console","version":null},"timestamp":"2023-11-22 22:46:01 +0100","severity":"INFO ","progname":"my_app","message":"hello","my_custom_key":"my_value","my_custom_hash":{"key":"value"}}
```

### SinatraMiddleware
### RackMiddleware

`Datadog::SinatraMiddleware` formats Rack requests as JSON and disables the default textual stdout of `Rack::CommonLogger`:
`Datadog::RackMiddleware` formats Rack requests as JSON and disables the default textual stdout of `Rack::CommonLogger`:

```ruby
# Example in Sinatra (app.rb)
require 'datadog/sinatra_middleware'
require 'datadog/rack_middleware'

use Datadog::SinatraMiddleware, logger
use Datadog::RackMiddleware, logger

# Example in Rails (config.rb)
config.middleware.use Datadog::RackMiddleware, config.logger
```

## Features
Expand Down
2 changes: 1 addition & 1 deletion lib/datadog/loggers/version.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@

module Datadog
module Loggers
VERSION = "0.1.10"
VERSION = "0.2.0"
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ def log(_env, _status, _response_headers, _began_at)
end

module Datadog
class SinatraMiddleware
class RackMiddleware
attr_reader :app, :logger

def initialize(app, logger, opt = {})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
require "spec_helper"
require "rack/test"
require "datadog/json_logger"
require "datadog/sinatra_middleware"
require "datadog/rack_middleware"

RSpec.describe Datadog::SinatraMiddleware do
RSpec.describe Datadog::RackMiddleware do
let(:app) { ->(_env) { [status_code, { "Content-Type" => "text/html" }, ["Response"]] } }
let(:env) { Rack::MockRequest.env_for("/test") }
let(:logger) { Datadog::JSONLogger.new }
Expand Down

0 comments on commit b910990

Please sign in to comment.