datadog-json_logger 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.rspec +3 -0
- data/.rubocop.yml +29 -0
- data/CHANGELOG.md +5 -0
- data/CODE_OF_CONDUCT.md +84 -0
- data/LICENSE.txt +21 -0
- data/README.md +110 -0
- data/Rakefile +12 -0
- data/datadog-json_logger.gemspec +40 -0
- data/lib/datadog/json_logger.rb +17 -0
- data/lib/datadog/loggers/json_formatter.rb +78 -0
- data/lib/datadog/loggers/version.rb +7 -0
- data/lib/datadog/sinatra_middleware.rb +81 -0
- data/sig/datadog/json_logger.rbs +6 -0
- metadata +76 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: a3e2c3addf5785012880280913d248bb4cf4a56aa2479a2510a9c6de9ffce724
|
4
|
+
data.tar.gz: f29ccec5312fc528fc1af220cf60b1babb06edb51486d992f0cf813ac48d32e8
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 7241111db933c2f99fbf138c10687aaa8cfcee40dfa69386638173232926e1b38c77b78fc15ecda0415dd47d21d3c6f1ede0050211c89bb0be28d72c7d10b64e
|
7
|
+
data.tar.gz: a2801e4b6e04f90adf080a213c0755723f708804654f8a9e7f5de71a457b7dbb5d037349985f2ef6dac523c1cfcdc1f9fa47f6f4409e8e54345aac707a52a87a
|
data/.rspec
ADDED
data/.rubocop.yml
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
AllCops:
|
2
|
+
NewCops: enable
|
3
|
+
TargetRubyVersion: 3.0
|
4
|
+
|
5
|
+
Style/StringLiterals:
|
6
|
+
Enabled: true
|
7
|
+
EnforcedStyle: double_quotes
|
8
|
+
|
9
|
+
Style/Documentation:
|
10
|
+
Enabled: false
|
11
|
+
|
12
|
+
Style/StringLiteralsInInterpolation:
|
13
|
+
Enabled: true
|
14
|
+
EnforcedStyle: double_quotes
|
15
|
+
|
16
|
+
Layout/LineLength:
|
17
|
+
Max: 120
|
18
|
+
|
19
|
+
Metrics/AbcSize:
|
20
|
+
Max: 30
|
21
|
+
|
22
|
+
Metrics/MethodLength:
|
23
|
+
Max: 30
|
24
|
+
|
25
|
+
Metrics/BlockLength:
|
26
|
+
Max: 100
|
27
|
+
|
28
|
+
Metrics/ParameterLists:
|
29
|
+
Max: 6
|
data/CHANGELOG.md
ADDED
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,84 @@
|
|
1
|
+
# Contributor Covenant Code of Conduct
|
2
|
+
|
3
|
+
## Our Pledge
|
4
|
+
|
5
|
+
We as members, contributors, and leaders pledge to make participation in our community a harassment-free experience for everyone, regardless of age, body size, visible or invisible disability, ethnicity, sex characteristics, gender identity and expression, level of experience, education, socio-economic status, nationality, personal appearance, race, religion, or sexual identity and orientation.
|
6
|
+
|
7
|
+
We pledge to act and interact in ways that contribute to an open, welcoming, diverse, inclusive, and healthy community.
|
8
|
+
|
9
|
+
## Our Standards
|
10
|
+
|
11
|
+
Examples of behavior that contributes to a positive environment for our community include:
|
12
|
+
|
13
|
+
* Demonstrating empathy and kindness toward other people
|
14
|
+
* Being respectful of differing opinions, viewpoints, and experiences
|
15
|
+
* Giving and gracefully accepting constructive feedback
|
16
|
+
* Accepting responsibility and apologizing to those affected by our mistakes, and learning from the experience
|
17
|
+
* Focusing on what is best not just for us as individuals, but for the overall community
|
18
|
+
|
19
|
+
Examples of unacceptable behavior include:
|
20
|
+
|
21
|
+
* The use of sexualized language or imagery, and sexual attention or
|
22
|
+
advances of any kind
|
23
|
+
* Trolling, insulting or derogatory comments, and personal or political attacks
|
24
|
+
* Public or private harassment
|
25
|
+
* Publishing others' private information, such as a physical or email
|
26
|
+
address, without their explicit permission
|
27
|
+
* Other conduct which could reasonably be considered inappropriate in a
|
28
|
+
professional setting
|
29
|
+
|
30
|
+
## Enforcement Responsibilities
|
31
|
+
|
32
|
+
Community leaders are responsible for clarifying and enforcing our standards of acceptable behavior and will take appropriate and fair corrective action in response to any behavior that they deem inappropriate, threatening, offensive, or harmful.
|
33
|
+
|
34
|
+
Community leaders have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, and will communicate reasons for moderation decisions when appropriate.
|
35
|
+
|
36
|
+
## Scope
|
37
|
+
|
38
|
+
This Code of Conduct applies within all community spaces, and also applies when an individual is officially representing the community in public spaces. Examples of representing our community include using an official e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event.
|
39
|
+
|
40
|
+
## Enforcement
|
41
|
+
|
42
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be reported to the community leaders responsible for enforcement at eth3rnit3@gmail.com. All complaints will be reviewed and investigated promptly and fairly.
|
43
|
+
|
44
|
+
All community leaders are obligated to respect the privacy and security of the reporter of any incident.
|
45
|
+
|
46
|
+
## Enforcement Guidelines
|
47
|
+
|
48
|
+
Community leaders will follow these Community Impact Guidelines in determining the consequences for any action they deem in violation of this Code of Conduct:
|
49
|
+
|
50
|
+
### 1. Correction
|
51
|
+
|
52
|
+
**Community Impact**: Use of inappropriate language or other behavior deemed unprofessional or unwelcome in the community.
|
53
|
+
|
54
|
+
**Consequence**: A private, written warning from community leaders, providing clarity around the nature of the violation and an explanation of why the behavior was inappropriate. A public apology may be requested.
|
55
|
+
|
56
|
+
### 2. Warning
|
57
|
+
|
58
|
+
**Community Impact**: A violation through a single incident or series of actions.
|
59
|
+
|
60
|
+
**Consequence**: A warning with consequences for continued behavior. No interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, for a specified period of time. This includes avoiding interactions in community spaces as well as external channels like social media. Violating these terms may lead to a temporary or permanent ban.
|
61
|
+
|
62
|
+
### 3. Temporary Ban
|
63
|
+
|
64
|
+
**Community Impact**: A serious violation of community standards, including sustained inappropriate behavior.
|
65
|
+
|
66
|
+
**Consequence**: A temporary ban from any sort of interaction or public communication with the community for a specified period of time. No public or private interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, is allowed during this period. Violating these terms may lead to a permanent ban.
|
67
|
+
|
68
|
+
### 4. Permanent Ban
|
69
|
+
|
70
|
+
**Community Impact**: Demonstrating a pattern of violation of community standards, including sustained inappropriate behavior, harassment of an individual, or aggression toward or disparagement of classes of individuals.
|
71
|
+
|
72
|
+
**Consequence**: A permanent ban from any sort of public interaction within the community.
|
73
|
+
|
74
|
+
## Attribution
|
75
|
+
|
76
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 2.0,
|
77
|
+
available at https://www.contributor-covenant.org/version/2/0/code_of_conduct.html.
|
78
|
+
|
79
|
+
Community Impact Guidelines were inspired by [Mozilla's code of conduct enforcement ladder](https://github.com/mozilla/diversity).
|
80
|
+
|
81
|
+
[homepage]: https://www.contributor-covenant.org
|
82
|
+
|
83
|
+
For answers to common questions about this code of conduct, see the FAQ at
|
84
|
+
https://www.contributor-covenant.org/faq. Translations are available at https://www.contributor-covenant.org/translations.
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2023 Eth3rnit3
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,110 @@
|
|
1
|
+
# Datadog::JSONLogger
|
2
|
+
|
3
|
+
[![Rubocop and Rspec](https://github.com/Eth3rnit3/datadog-json_logger/actions/workflows/main.yml/badge.svg?branch=main)](https://github.com/Eth3rnit3/datadog-json_logger/actions/workflows/main.yml)
|
4
|
+
|
5
|
+
`Datadog::JSONLogger` is a Ruby gem designed to seamlessly integrate Ruby applications with Datadog's logging and tracing services. This gem allows your Ruby application to format its output as JSON, including necessary correlation IDs and other details for optimal Datadog functionality.
|
6
|
+
|
7
|
+
## Prerequisites
|
8
|
+
|
9
|
+
Before you begin, ensure you have [ddtrace](https://github.com/DataDog/dd-trace-rb) configured in your Ruby application, as `Datadog::JSONLogger` relies on `ddtrace` for tracing data.
|
10
|
+
|
11
|
+
## Installation
|
12
|
+
|
13
|
+
Add this line to your application's Gemfile:
|
14
|
+
|
15
|
+
```ruby
|
16
|
+
gem 'datadog-json_logger'
|
17
|
+
```
|
18
|
+
|
19
|
+
And then execute:
|
20
|
+
|
21
|
+
```bash
|
22
|
+
bundle install
|
23
|
+
```
|
24
|
+
|
25
|
+
Or install it yourself as:
|
26
|
+
|
27
|
+
```bash
|
28
|
+
gem install datadog-json_logger
|
29
|
+
```
|
30
|
+
|
31
|
+
## Usage
|
32
|
+
|
33
|
+
### JSONLogger
|
34
|
+
|
35
|
+
`Datadog::JSONLogger` can be easily integrated into your Ruby application. Here's a quick example of how to use it in a Sinatra application:
|
36
|
+
|
37
|
+
```ruby
|
38
|
+
# Example in Sinatra (app.rb)
|
39
|
+
require 'datadog/json_logger'
|
40
|
+
|
41
|
+
def logger
|
42
|
+
@logger ||= Datadog::JSONLogger.new
|
43
|
+
end
|
44
|
+
|
45
|
+
set :logger, logger
|
46
|
+
|
47
|
+
Sinatra::Application.logger.info("hello")
|
48
|
+
# => {"dd":{"trace_id":"0","span_id":"0","env":null,"service":"console","version":null},"timestamp":"2023-11-22 22:28:00 +0100","severity":"INFO ","progname":"","message":"hello"}
|
49
|
+
```
|
50
|
+
|
51
|
+
#### Add Custom Keys
|
52
|
+
Create a custom formatter that inherits from `Datadog::Loggers::JSONFormatter` to add custom keys as shown below:
|
53
|
+
|
54
|
+
```ruby
|
55
|
+
class CustomFormatter < Datadog::Loggers::JSONFormatter
|
56
|
+
def self.call(severity, datetime, progname, msg)
|
57
|
+
super do |log_hash|
|
58
|
+
log_hash[:my_custom_key] = "my_value"
|
59
|
+
log_hash[:my_custom_hash] = { key: "value" }
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
def logger
|
65
|
+
return @logger if @logger
|
66
|
+
|
67
|
+
@logger = Datadog::JSONLogger.new
|
68
|
+
@logger.progname = "my_app"
|
69
|
+
@logger.formatter = CustomFormatter
|
70
|
+
@logger
|
71
|
+
end
|
72
|
+
|
73
|
+
Sinatra::Application.logger.info("hello")
|
74
|
+
# {"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"}}
|
75
|
+
```
|
76
|
+
|
77
|
+
### SinatraMiddleware
|
78
|
+
|
79
|
+
`Datadog::SinatraMiddleware` formats Rack requests as JSON and disables the default textual stdout of `Rack::CommonLogger`:
|
80
|
+
|
81
|
+
```ruby
|
82
|
+
# Example in Sinatra (app.rb)
|
83
|
+
require 'datadog/sinatra_middleware'
|
84
|
+
|
85
|
+
use Datadog::SinatraMiddleware, logger
|
86
|
+
```
|
87
|
+
|
88
|
+
## Development
|
89
|
+
|
90
|
+
After checking out the repo, run `bundle install` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
91
|
+
|
92
|
+
To install this gem onto your local machine, run `bundle exec rake install`.
|
93
|
+
|
94
|
+
## Contributing
|
95
|
+
|
96
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/eth3rnit3/datadog-json_logger. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/eth3rnit3/datadog-json_logger/blob/main/CODE_OF_CONDUCT.md).
|
97
|
+
|
98
|
+
1. Fork the repository (https://github.com/eth3rnit3/datadog-json_logger/fork)
|
99
|
+
2. Create your feature branch (`git checkout -b feature/my_feature`)
|
100
|
+
3. Commit your changes (`git commit -am 'Add a new feature'`)
|
101
|
+
4. Push the branch (`git push origin feature/my_feature`)
|
102
|
+
5. Open a Pull Request
|
103
|
+
|
104
|
+
## License
|
105
|
+
|
106
|
+
This gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
107
|
+
|
108
|
+
## Code of Conduct
|
109
|
+
|
110
|
+
Everyone interacting in the Datadog::JSONLogger project's codebases, issue trackers, chat rooms, and mailing lists is expected to follow the [code of conduct](https://github.com/eth3rnit3/datadog-json_logger/blob/main/CODE_OF_CONDUCT.md).
|
data/Rakefile
ADDED
@@ -0,0 +1,40 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative "lib/datadog/loggers/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |spec|
|
6
|
+
spec.name = "datadog-json_logger"
|
7
|
+
spec.version = Datadog::Loggers::VERSION
|
8
|
+
spec.authors = ["Eth3rnit3"]
|
9
|
+
spec.email = ["eth3rnit3@gmail.com"]
|
10
|
+
|
11
|
+
spec.summary = "Connect your ruby application to Datadog logging and tracing."
|
12
|
+
spec.description = "This gem provides easy integration for connecting a ruby application to Datadog's logging and tracing services." # rubocop:disable Layout/LineLength
|
13
|
+
spec.homepage = "https://github.com/eth3rnit3/datadog-json_logger"
|
14
|
+
spec.license = "MIT"
|
15
|
+
spec.required_ruby_version = ">= 3.0"
|
16
|
+
|
17
|
+
spec.metadata["allowed_push_host"] = "https://rubygems.org"
|
18
|
+
|
19
|
+
spec.metadata["homepage_uri"] = spec.homepage
|
20
|
+
spec.metadata["source_code_uri"] = "https://github.com/eth3rnit3/datadog-json_logger"
|
21
|
+
spec.metadata["changelog_uri"] = "https://github.com/eth3rnit3/datadog-json_logger/blob/main/CHANGELOG.md"
|
22
|
+
|
23
|
+
# Specify which files should be added to the gem when it is released.
|
24
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
25
|
+
spec.files = Dir.chdir(__dir__) do
|
26
|
+
`git ls-files -z`.split("\x0").reject do |f|
|
27
|
+
(File.expand_path(f) == __FILE__) ||
|
28
|
+
f.start_with?(*%w[bin/ test/ spec/ features/ .git .circleci appveyor Gemfile])
|
29
|
+
end
|
30
|
+
end
|
31
|
+
spec.bindir = "exe"
|
32
|
+
spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
|
33
|
+
spec.require_paths = ["lib"]
|
34
|
+
|
35
|
+
spec.add_dependency "ddtrace", "~> 1.16.2"
|
36
|
+
|
37
|
+
# For more information and examples about making a new gem, check out our
|
38
|
+
# guide at: https://bundler.io/guides/creating_gem.html
|
39
|
+
spec.metadata["rubygems_mfa_required"] = "true"
|
40
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "logger"
|
4
|
+
require_relative "loggers/version"
|
5
|
+
require_relative "loggers/json_formatter"
|
6
|
+
|
7
|
+
module Datadog
|
8
|
+
class Error < StandardError; end
|
9
|
+
|
10
|
+
class JSONLogger < Logger
|
11
|
+
def initialize(output = nil)
|
12
|
+
$stdout.sync = true
|
13
|
+
super(output || $stdout)
|
14
|
+
@default_formatter = ::Datadog::Loggers::JSONFormatter
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,78 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "ddtrace"
|
4
|
+
require "logger"
|
5
|
+
require "json"
|
6
|
+
|
7
|
+
module Datadog
|
8
|
+
module Loggers
|
9
|
+
class JSONFormatter < Logger::Formatter
|
10
|
+
def self.call(severity, datetime, progname, msg)
|
11
|
+
log_hash = base_log_hash(severity, datetime, progname)
|
12
|
+
formatter = formatter_for(msg)
|
13
|
+
formatter.format(log_hash, msg)
|
14
|
+
|
15
|
+
yield(log_hash) if block_given?
|
16
|
+
|
17
|
+
"#{log_hash.to_json}\r\n"
|
18
|
+
end
|
19
|
+
|
20
|
+
def self.base_log_hash(severity, datetime, progname)
|
21
|
+
{
|
22
|
+
dd: correlation_hash,
|
23
|
+
timestamp: datetime.to_s,
|
24
|
+
severity: severity.ljust(5).to_s,
|
25
|
+
progname: progname.to_s
|
26
|
+
}
|
27
|
+
end
|
28
|
+
|
29
|
+
def self.formatter_for(msg)
|
30
|
+
case msg
|
31
|
+
when Hash then HashFormatter
|
32
|
+
when Exception then ExceptionFormatter
|
33
|
+
when String then StringFormatter
|
34
|
+
else DefaultFormatter
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
def self.correlation_hash
|
39
|
+
correlation = Datadog::Tracing.correlation
|
40
|
+
{
|
41
|
+
trace_id: correlation.trace_id&.to_s,
|
42
|
+
span_id: correlation.span_id&.to_s,
|
43
|
+
env: correlation.env&.to_s,
|
44
|
+
service: correlation.service&.to_s,
|
45
|
+
version: correlation.version&.to_s
|
46
|
+
}
|
47
|
+
end
|
48
|
+
|
49
|
+
class HashFormatter
|
50
|
+
def self.format(log_hash, msg)
|
51
|
+
log_hash.merge!(msg)
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
class ExceptionFormatter
|
56
|
+
def self.format(log_hash, exception)
|
57
|
+
log_hash.merge!(
|
58
|
+
exception: exception,
|
59
|
+
exception_message: exception.message,
|
60
|
+
exception_backtrace: exception.backtrace
|
61
|
+
)
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
class StringFormatter
|
66
|
+
def self.format(log_hash, msg)
|
67
|
+
log_hash[:message] = msg.dup.force_encoding("utf-8")
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
class DefaultFormatter
|
72
|
+
def self.format(log_hash, msg)
|
73
|
+
log_hash[:message] = msg.to_s
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
@@ -0,0 +1,81 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "uri"
|
4
|
+
require "json"
|
5
|
+
|
6
|
+
module Rack
|
7
|
+
class CommonLogger
|
8
|
+
def log(_env, _status, _response_headers, _began_at)
|
9
|
+
# Disable default rack logger output
|
10
|
+
nil
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
module Datadog
|
16
|
+
class SinatraMiddleware
|
17
|
+
attr_reader :app, :logger
|
18
|
+
|
19
|
+
def initialize(app, logger)
|
20
|
+
@app = app
|
21
|
+
@logger = logger
|
22
|
+
end
|
23
|
+
|
24
|
+
def call(env)
|
25
|
+
request = Rack::Request.new(env)
|
26
|
+
start_time = Time.now
|
27
|
+
|
28
|
+
status, headers, body = safely_process_request(env)
|
29
|
+
end_time = Time.now
|
30
|
+
|
31
|
+
log_request(request, env, status, headers, start_time, end_time)
|
32
|
+
|
33
|
+
[status, headers, body]
|
34
|
+
rescue StandardError => e
|
35
|
+
handle_exception(e)
|
36
|
+
end
|
37
|
+
|
38
|
+
private
|
39
|
+
|
40
|
+
def safely_process_request(env)
|
41
|
+
app.call(env)
|
42
|
+
rescue StandardError
|
43
|
+
[500, { "Content-Type" => "text/html" }, ["Internal Server Error"]]
|
44
|
+
end
|
45
|
+
|
46
|
+
def log_request(request, env, status, headers, start_time, end_time)
|
47
|
+
log_data = {
|
48
|
+
request: true,
|
49
|
+
request_ip: request.ip,
|
50
|
+
method: request.request_method,
|
51
|
+
controller: env["sinatra.controller_name"],
|
52
|
+
action: env["sinatra.action_name"],
|
53
|
+
path: request.path,
|
54
|
+
params: parse_query(request.query_string),
|
55
|
+
status: status,
|
56
|
+
format: headers["Content-Type"],
|
57
|
+
duration: calculate_duration(start_time, end_time)
|
58
|
+
}
|
59
|
+
|
60
|
+
logger.info(log_data)
|
61
|
+
end
|
62
|
+
|
63
|
+
def calculate_duration(start_time, end_time)
|
64
|
+
((end_time - start_time) * 1000).round # Duration in milliseconds
|
65
|
+
end
|
66
|
+
|
67
|
+
def parse_query(query_string)
|
68
|
+
URI.decode_www_form(query_string).to_h
|
69
|
+
end
|
70
|
+
|
71
|
+
def handle_exception(exception)
|
72
|
+
logger.error(
|
73
|
+
exception: exception.class.name,
|
74
|
+
exception_message: exception.message,
|
75
|
+
exception_backtrace: exception.backtrace
|
76
|
+
)
|
77
|
+
|
78
|
+
raise exception
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
metadata
ADDED
@@ -0,0 +1,76 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: datadog-json_logger
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Eth3rnit3
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2024-02-04 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: ddtrace
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 1.16.2
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 1.16.2
|
27
|
+
description: This gem provides easy integration for connecting a ruby application
|
28
|
+
to Datadog's logging and tracing services.
|
29
|
+
email:
|
30
|
+
- eth3rnit3@gmail.com
|
31
|
+
executables: []
|
32
|
+
extensions: []
|
33
|
+
extra_rdoc_files: []
|
34
|
+
files:
|
35
|
+
- ".rspec"
|
36
|
+
- ".rubocop.yml"
|
37
|
+
- CHANGELOG.md
|
38
|
+
- CODE_OF_CONDUCT.md
|
39
|
+
- LICENSE.txt
|
40
|
+
- README.md
|
41
|
+
- Rakefile
|
42
|
+
- datadog-json_logger.gemspec
|
43
|
+
- lib/datadog/json_logger.rb
|
44
|
+
- lib/datadog/loggers/json_formatter.rb
|
45
|
+
- lib/datadog/loggers/version.rb
|
46
|
+
- lib/datadog/sinatra_middleware.rb
|
47
|
+
- sig/datadog/json_logger.rbs
|
48
|
+
homepage: https://github.com/eth3rnit3/datadog-json_logger
|
49
|
+
licenses:
|
50
|
+
- MIT
|
51
|
+
metadata:
|
52
|
+
allowed_push_host: https://rubygems.org
|
53
|
+
homepage_uri: https://github.com/eth3rnit3/datadog-json_logger
|
54
|
+
source_code_uri: https://github.com/eth3rnit3/datadog-json_logger
|
55
|
+
changelog_uri: https://github.com/eth3rnit3/datadog-json_logger/blob/main/CHANGELOG.md
|
56
|
+
rubygems_mfa_required: 'true'
|
57
|
+
post_install_message:
|
58
|
+
rdoc_options: []
|
59
|
+
require_paths:
|
60
|
+
- lib
|
61
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
62
|
+
requirements:
|
63
|
+
- - ">="
|
64
|
+
- !ruby/object:Gem::Version
|
65
|
+
version: '3.0'
|
66
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
67
|
+
requirements:
|
68
|
+
- - ">="
|
69
|
+
- !ruby/object:Gem::Version
|
70
|
+
version: '0'
|
71
|
+
requirements: []
|
72
|
+
rubygems_version: 3.5.5
|
73
|
+
signing_key:
|
74
|
+
specification_version: 4
|
75
|
+
summary: Connect your ruby application to Datadog logging and tracing.
|
76
|
+
test_files: []
|