lumberjack_data_dog 1.0.0 → 1.1.0
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/continuous_integration.yml +2 -5
- data/.standard.yml +1 -1
- data/CHANGE_LOG.md +20 -0
- data/README.md +17 -10
- data/VERSION +1 -1
- data/lib/lumberjack/data_dog.rb +23 -23
- data/lumberjack_data_dog.gemspec +8 -2
- metadata +10 -11
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 53517e1a4626e2ca86c9a78968008ce667612cb8121ad769a82484056ab7d23c
|
|
4
|
+
data.tar.gz: 3ad569bd2691572c29fbb14dfd569cde90ad8c38bd36dda3f0c720ce33b19e88
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: b52261c574346d6dad7fc25a2d898c7ae6280a8b8487aeb4341df43ba5d1c5e6a3cb692582dc3d97d7222ab386765fc9c49147adeb1145338a8abbec3e999b22
|
|
7
|
+
data.tar.gz: 829c023744c9bc34c1c96f02fe1facde15ccd2eaab80f0e29712679d252bfcccec4d154a9dd54d5c599532fe8c8c8dbc4cd0b6dff0458569b5951e6f07a0a761
|
|
@@ -3,10 +3,8 @@ name: Continuous Integration
|
|
|
3
3
|
on:
|
|
4
4
|
push:
|
|
5
5
|
branches:
|
|
6
|
-
-
|
|
6
|
+
- main
|
|
7
7
|
- actions-*
|
|
8
|
-
tags:
|
|
9
|
-
- v*
|
|
10
8
|
pull_request:
|
|
11
9
|
branches-ignore:
|
|
12
10
|
- actions-*
|
|
@@ -29,9 +27,8 @@ jobs:
|
|
|
29
27
|
standardrb: true
|
|
30
28
|
- ruby: "3.0"
|
|
31
29
|
- ruby: "2.7"
|
|
32
|
-
- ruby: "2.5"
|
|
33
30
|
steps:
|
|
34
|
-
- uses: actions/checkout@
|
|
31
|
+
- uses: actions/checkout@v4
|
|
35
32
|
- name: Set up Ruby
|
|
36
33
|
uses: ruby/setup-ruby@v1
|
|
37
34
|
with:
|
data/.standard.yml
CHANGED
data/CHANGE_LOG.md
CHANGED
|
@@ -4,6 +4,26 @@ All notable changes to this project will be documented in this file.
|
|
|
4
4
|
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
|
5
5
|
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
6
6
|
|
|
7
|
+
## 1.1.0
|
|
8
|
+
|
|
9
|
+
### Added
|
|
10
|
+
|
|
11
|
+
- Support for Lumberjack 2.0.
|
|
12
|
+
|
|
13
|
+
### Changed
|
|
14
|
+
|
|
15
|
+
- This is the last release for the gem under the `lumberjack_data_dog` name. Future updates are being released under the name `lumberjack_datadog`.
|
|
16
|
+
|
|
17
|
+
### Removed
|
|
18
|
+
|
|
19
|
+
- Support for Ruby < 2.7
|
|
20
|
+
|
|
21
|
+
## 1.0.1
|
|
22
|
+
|
|
23
|
+
### Added
|
|
24
|
+
|
|
25
|
+
- Logger options can now be sent to `Lumberjack::DataDog.setup`.
|
|
26
|
+
|
|
7
27
|
## 1.0.0
|
|
8
28
|
|
|
9
29
|
### Added
|
data/README.md
CHANGED
|
@@ -4,6 +4,9 @@
|
|
|
4
4
|
[](https://github.com/testdouble/standard)
|
|
5
5
|
[](https://badge.fury.io/rb/lumberjack_data_dog)
|
|
6
6
|
|
|
7
|
+
> [!IMPORTANT]
|
|
8
|
+
> This gem has been renamed to [`lumberjack_datadog`](https://github.com/bdurand/lumberjack_datadog). For new versions switch using that gem.
|
|
9
|
+
|
|
7
10
|
This gem provides a logging setup for using the [lumberjack](https://github.com/bdurand/lumberjack) gem with DataDog. It sets up JSON logging and maps values to DataDog's [standard attributes](https://docs.datadoghq.com/logs/processing/attributes_naming_convention/).
|
|
8
11
|
|
|
9
12
|
## Features
|
|
@@ -17,7 +20,7 @@ This gem provides a logging setup for using the [lumberjack](https://github.com/
|
|
|
17
20
|
- **Duration Logging**: Automatic conversion of duration values to nanoseconds for DataDog
|
|
18
21
|
- **Configurable Message Truncation**: Limit message length to prevent oversized logs
|
|
19
22
|
- **Thread Information**: Optional thread name logging
|
|
20
|
-
- **
|
|
23
|
+
- **attribute Remapping**: Flexible attribute transformation and remapping
|
|
21
24
|
- **Pretty JSON**: Optional pretty-printed JSON output for development
|
|
22
25
|
|
|
23
26
|
## Usage
|
|
@@ -39,7 +42,9 @@ logger.error("Something went wrong", request_id: "abc-123")
|
|
|
39
42
|
### Advanced Configuration
|
|
40
43
|
|
|
41
44
|
```ruby
|
|
42
|
-
logger
|
|
45
|
+
# The output device and logger options can be passed in the setup method.
|
|
46
|
+
# These are passed through to Lumberjack::Logger.new.
|
|
47
|
+
logger = Lumberjack::DataDog.setup(log_device, level: :info) do |config|
|
|
43
48
|
# Truncate messages longer than 1000 characters
|
|
44
49
|
config.max_message_length = 1000
|
|
45
50
|
|
|
@@ -49,12 +54,16 @@ logger = Lumberjack::DataDog.setup do |config|
|
|
|
49
54
|
# Disable PID logging
|
|
50
55
|
config.pid = false
|
|
51
56
|
|
|
52
|
-
# Remap custom
|
|
53
|
-
config.
|
|
57
|
+
# Remap custom attributes to DataDog attributes
|
|
58
|
+
config.remap_attributes(
|
|
54
59
|
user_id: "usr.id",
|
|
55
60
|
request_id: "http.request_id"
|
|
56
61
|
)
|
|
57
62
|
|
|
63
|
+
# Add a backtrace cleaner to remove unnecessary noise when logging exceptions.
|
|
64
|
+
# The cleaner object must respond to `clean` method.
|
|
65
|
+
config.backtrace_cleaner = Rails.backtrace_cleaner
|
|
66
|
+
|
|
58
67
|
# Enable pretty JSON for development
|
|
59
68
|
config.pretty = true
|
|
60
69
|
end
|
|
@@ -64,10 +73,8 @@ end
|
|
|
64
73
|
|
|
65
74
|
```ruby
|
|
66
75
|
# Log to a file instead of STDOUT
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
logger.info("Logged to file")
|
|
70
|
-
end
|
|
76
|
+
logger = Lumberjack::DataDog.setup("/var/log/app.log")
|
|
77
|
+
logger.info("Logged to file")
|
|
71
78
|
```
|
|
72
79
|
|
|
73
80
|
### Exception Logging
|
|
@@ -102,11 +109,11 @@ logger.info("API call", duration_micros: 1500) # microseconds
|
|
|
102
109
|
logger.info("Function", duration_ns: 1500000) # nanoseconds
|
|
103
110
|
```
|
|
104
111
|
|
|
105
|
-
### Custom
|
|
112
|
+
### Custom attribute Transformation
|
|
106
113
|
|
|
107
114
|
```ruby
|
|
108
115
|
logger = Lumberjack::DataDog.setup do |config|
|
|
109
|
-
config.
|
|
116
|
+
config.remap_attributes(
|
|
110
117
|
# Simple remapping
|
|
111
118
|
correlation_id: "trace.correlation_id",
|
|
112
119
|
|
data/VERSION
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
1.
|
|
1
|
+
1.1.0
|
data/lib/lumberjack/data_dog.rb
CHANGED
|
@@ -15,8 +15,8 @@ module Lumberjack::DataDog
|
|
|
15
15
|
attr_accessor :backtrace_cleaner
|
|
16
16
|
attr_accessor :thread_name
|
|
17
17
|
attr_accessor :pid
|
|
18
|
-
attr_accessor :
|
|
19
|
-
attr_reader :
|
|
18
|
+
attr_accessor :allow_all_attributes
|
|
19
|
+
attr_reader :attribute_mapping
|
|
20
20
|
attr_accessor :pretty
|
|
21
21
|
|
|
22
22
|
def initialize
|
|
@@ -24,13 +24,13 @@ module Lumberjack::DataDog
|
|
|
24
24
|
@backtrace_cleaner = nil
|
|
25
25
|
@thread_name = false
|
|
26
26
|
@pid = true
|
|
27
|
-
@
|
|
28
|
-
@
|
|
27
|
+
@allow_all_attributes = true
|
|
28
|
+
@attribute_mapping = {}
|
|
29
29
|
@pretty = false
|
|
30
30
|
end
|
|
31
31
|
|
|
32
|
-
def
|
|
33
|
-
@
|
|
32
|
+
def remap_attributes(attribute_mapping)
|
|
33
|
+
@attribute_mapping = @attribute_mapping.merge(attribute_mapping)
|
|
34
34
|
end
|
|
35
35
|
|
|
36
36
|
def validate!
|
|
@@ -45,51 +45,51 @@ module Lumberjack::DataDog
|
|
|
45
45
|
end
|
|
46
46
|
|
|
47
47
|
class << self
|
|
48
|
-
def setup(stream = $stdout, &block)
|
|
48
|
+
def setup(stream = $stdout, options = {}, &block)
|
|
49
49
|
config = Config.new
|
|
50
50
|
yield(config) if block_given?
|
|
51
51
|
config.validate!
|
|
52
52
|
|
|
53
|
-
new_logger(stream, config)
|
|
53
|
+
new_logger(stream, options, config)
|
|
54
54
|
end
|
|
55
55
|
|
|
56
56
|
private
|
|
57
57
|
|
|
58
|
-
def new_logger(stream, config)
|
|
59
|
-
logger = Lumberjack::Logger.new(json_device(stream, config))
|
|
58
|
+
def new_logger(stream, options, config)
|
|
59
|
+
logger = Lumberjack::Logger.new(json_device(stream, config), **options)
|
|
60
60
|
|
|
61
|
-
# Add the error to the error
|
|
61
|
+
# Add the error to the error attribute if an exception is logged as the message.
|
|
62
62
|
logger.message_formatter.add(Exception, message_exception_formatter)
|
|
63
63
|
|
|
64
|
-
# Split the error
|
|
65
|
-
logger.
|
|
64
|
+
# Split the error attribute up into standard attributes if it is an exception.
|
|
65
|
+
logger.attribute_formatter.add(Exception, exception_attribute_formatter(config))
|
|
66
66
|
|
|
67
67
|
if config.thread_name
|
|
68
68
|
if config.thread_name == :global
|
|
69
|
-
logger.
|
|
69
|
+
logger.tag!("logger.thread_name" => -> { Lumberjack::Utils.global_thread_id })
|
|
70
70
|
else
|
|
71
|
-
logger.
|
|
71
|
+
logger.tag!("logger.thread_name" => -> { Lumberjack::Utils.thread_name })
|
|
72
72
|
end
|
|
73
73
|
end
|
|
74
74
|
|
|
75
75
|
if config.pid == :global
|
|
76
|
-
logger.
|
|
76
|
+
logger.tag!("pid" => -> { Lumberjack::Utils.global_pid })
|
|
77
77
|
end
|
|
78
78
|
|
|
79
79
|
logger
|
|
80
80
|
end
|
|
81
81
|
|
|
82
82
|
def json_device(stream, config)
|
|
83
|
-
Lumberjack::JsonDevice.new(stream, mapping: json_mapping(config), pretty: config.pretty)
|
|
83
|
+
Lumberjack::JsonDevice.new(output: stream, mapping: json_mapping(config), pretty: config.pretty)
|
|
84
84
|
end
|
|
85
85
|
|
|
86
86
|
def json_mapping(config)
|
|
87
|
-
mapping = config.
|
|
87
|
+
mapping = config.attribute_mapping.transform_keys(&:to_sym)
|
|
88
88
|
mapping = mapping.merge(STANDARD_ATTRIBUTE_MAPPING)
|
|
89
89
|
|
|
90
90
|
mapping.delete(:pid) if !config.pid || config.pid == :global
|
|
91
91
|
|
|
92
|
-
mapping[:
|
|
92
|
+
mapping[:attributes] = "*" if config.allow_all_attributes
|
|
93
93
|
|
|
94
94
|
mapping[:message] = if config.max_message_length
|
|
95
95
|
truncate_message_transformer(config.max_message_length)
|
|
@@ -129,15 +129,15 @@ module Lumberjack::DataDog
|
|
|
129
129
|
end
|
|
130
130
|
end
|
|
131
131
|
|
|
132
|
-
def
|
|
132
|
+
def exception_attribute_formatter(config)
|
|
133
133
|
lambda do |error|
|
|
134
|
-
|
|
134
|
+
error_attributes = {"kind" => error.class.name, "message" => error.message}
|
|
135
135
|
trace = error.backtrace
|
|
136
136
|
if trace
|
|
137
137
|
trace = config.backtrace_cleaner.clean(trace) if config.backtrace_cleaner
|
|
138
|
-
|
|
138
|
+
error_attributes["stack"] = trace
|
|
139
139
|
end
|
|
140
|
-
|
|
140
|
+
error_attributes
|
|
141
141
|
end
|
|
142
142
|
end
|
|
143
143
|
end
|
data/lumberjack_data_dog.gemspec
CHANGED
|
@@ -8,6 +8,12 @@ Gem::Specification.new do |spec|
|
|
|
8
8
|
spec.homepage = "https://github.com/bdurand/lumberjack_data_dog"
|
|
9
9
|
spec.license = "MIT"
|
|
10
10
|
|
|
11
|
+
spec.metadata = {
|
|
12
|
+
"homepage_uri" => spec.homepage,
|
|
13
|
+
"source_code_uri" => spec.homepage,
|
|
14
|
+
"changelog_uri" => "#{spec.homepage}/blob/main/CHANGE_LOG.md"
|
|
15
|
+
}
|
|
16
|
+
|
|
11
17
|
# Specify which files should be added to the gem when it is released.
|
|
12
18
|
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
|
13
19
|
ignore_files = %w[
|
|
@@ -26,7 +32,7 @@ Gem::Specification.new do |spec|
|
|
|
26
32
|
|
|
27
33
|
spec.require_paths = ["lib"]
|
|
28
34
|
|
|
29
|
-
spec.required_ruby_version = ">= 2.
|
|
35
|
+
spec.required_ruby_version = ">= 2.7"
|
|
30
36
|
|
|
31
|
-
spec.add_dependency "lumberjack_json_device", ">=
|
|
37
|
+
spec.add_dependency "lumberjack_json_device", ">= 3.0.0"
|
|
32
38
|
end
|
metadata
CHANGED
|
@@ -1,14 +1,13 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: lumberjack_data_dog
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 1.
|
|
4
|
+
version: 1.1.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Brian Durand
|
|
8
|
-
autorequire:
|
|
9
8
|
bindir: bin
|
|
10
9
|
cert_chain: []
|
|
11
|
-
date:
|
|
10
|
+
date: 1980-01-02 00:00:00.000000000 Z
|
|
12
11
|
dependencies:
|
|
13
12
|
- !ruby/object:Gem::Dependency
|
|
14
13
|
name: lumberjack_json_device
|
|
@@ -16,15 +15,14 @@ dependencies:
|
|
|
16
15
|
requirements:
|
|
17
16
|
- - ">="
|
|
18
17
|
- !ruby/object:Gem::Version
|
|
19
|
-
version:
|
|
18
|
+
version: 3.0.0
|
|
20
19
|
type: :runtime
|
|
21
20
|
prerelease: false
|
|
22
21
|
version_requirements: !ruby/object:Gem::Requirement
|
|
23
22
|
requirements:
|
|
24
23
|
- - ">="
|
|
25
24
|
- !ruby/object:Gem::Version
|
|
26
|
-
version:
|
|
27
|
-
description:
|
|
25
|
+
version: 3.0.0
|
|
28
26
|
email:
|
|
29
27
|
- bbdurand@gmail.com
|
|
30
28
|
executables: []
|
|
@@ -44,8 +42,10 @@ files:
|
|
|
44
42
|
homepage: https://github.com/bdurand/lumberjack_data_dog
|
|
45
43
|
licenses:
|
|
46
44
|
- MIT
|
|
47
|
-
metadata:
|
|
48
|
-
|
|
45
|
+
metadata:
|
|
46
|
+
homepage_uri: https://github.com/bdurand/lumberjack_data_dog
|
|
47
|
+
source_code_uri: https://github.com/bdurand/lumberjack_data_dog
|
|
48
|
+
changelog_uri: https://github.com/bdurand/lumberjack_data_dog/blob/main/CHANGE_LOG.md
|
|
49
49
|
rdoc_options: []
|
|
50
50
|
require_paths:
|
|
51
51
|
- lib
|
|
@@ -53,15 +53,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
|
53
53
|
requirements:
|
|
54
54
|
- - ">="
|
|
55
55
|
- !ruby/object:Gem::Version
|
|
56
|
-
version: '2.
|
|
56
|
+
version: '2.7'
|
|
57
57
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
58
58
|
requirements:
|
|
59
59
|
- - ">="
|
|
60
60
|
- !ruby/object:Gem::Version
|
|
61
61
|
version: '0'
|
|
62
62
|
requirements: []
|
|
63
|
-
rubygems_version: 3.
|
|
64
|
-
signing_key:
|
|
63
|
+
rubygems_version: 3.6.9
|
|
65
64
|
specification_version: 4
|
|
66
65
|
summary: Lumberjack logging device that outputs JSON formatted for DataDog with standard
|
|
67
66
|
attribute mapping.
|