Include Rails log_tags in metadata
Nobody has claimed this yet.
Assessment
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Newbie friendliness
- 45/100
- Issue type
- Feature
- Clarity
- Mostly clear
- Activity status
- Stale
- Tech stack
- rails, ruby
- Domain
- observability-sre
Research direction
Start by locating Logdna::Ruby#log and the logger setup used with ActiveSupport::TaggedLogging. Verify how current tags should be added to log metadata while preserving existing metadata, then confirm that tagged Rails logs include the request_id in the resulting metadata.
Written by the indexing model from the issue text.
Description
I've made this change locally. But I think it could go in the public gem. I'm using ActiveSupport::TaggedLogging in Rails to include log tags like this:
# This is the default in Rails, but could include more stuff if desired
config.log_tags = [:request_id]
# Send logs to LogDNA
log_dna_logger = Logdna::Ruby.new(
Rails.application.secrets.log_dna_api_key, {
env: "development",
app: "ShayHi",
level: Logger::DEBUG
}
)
# Wrap LogDNA logger in TaggedLogging to add log tags
config.logger = ActiveSupport::TaggedLogging.new(log_dna_logger)
I then modified Logdna::Ruby#log to include the tags in the metadata
def log(message = nil, opts = {})
# MY NEW CODE BELOW vvv
if formatter.current_tags.present?
opts[:meta] = (opts[:meta] || {}).merge(tags: formatter.current_tags.join(" "))
end
# MY NEW CODE ABOVE ^^^
if message.nil? && block_given?
message = yield
end
if message.nil?
@internal_logger.debug("provide either a message or block")
return
end
message = message.to_s.encode("UTF-8")
@client.write_to_buffer(message, default_opts.merge(opts).merge(
timestamp: (Time.now.to_f * 1000).to_i
))
end
Logs now look like this:
This is particularly useful for including the Rails request_id in the log metadata. I can open a PR if this is something you're interested in adding to the gem for everyone.
- Dominant language
- Ruby
- Stars
- 19
- Forks
- 18
- PR merge metrics
- No merged PRs in 30d
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from logdna/ruby
-
Difficulty 4/5 3-5 days Newbie friendliness 35/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 52/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 45/100
-
Difficulty 3/5 1-2 days Newbie friendliness 35/100
-
Difficulty 3/5 1-2 days Newbie friendliness 45/100
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
simp/pupmod-simp-simp#395 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 80/100
simp/pupmod-simp-rsyslog#219 ·
-
Difficulty 1/5 Under an hour Newbie friendliness 90/100
simp/pupmod-simp-pupmod#256 ·
-
Difficulty 1/5 Under an hour Newbie friendliness 90/100
simp/pupmod-simp-sudo#150 ·
-
Difficulty 1/5 Under an hour Newbie friendliness 90/100