semantic_logger icon indicating copy to clipboard operation
semantic_logger copied to clipboard

Don't nest attributes under message in newrelic logs appender

Open fabn opened this issue 1 year ago • 2 comments

Environment

Provide at least:

  • Ruby Version: 3.2.2
  • Semantic Logger Version: 4.16.0
  • Application/framework names and versions (Rails 7.x)
  • Rails Semantic Logger Version, if applicable. 4.17.0

Expected Behavior

In JSON should be something like:

{
  "entity.guid": "MTQ0ODQ2MHxBUE18QVBQTElDQVRJT058OTY2Mjk2ODk",
  "entity.guids": "MTQ0ODQ2MHxBUE18QVBQTElDQVRJT058OTY2Mjk2ODk",
  "entity.name": "Motohelp Rails (staging)",
  "entity.type": "SERVICE",
  "file.name": "(pry)",
  "hostname": "worker-6b6c685bf7-8b8c8",
  "level": "INFO",
  "line.number": "2",
  "logger.name": "Test",
  "application": "Semantic Logger",
  "duration": 100,
  "duration_human": "100.0ms",
  "environment": "production",
  "message": "Login time",
  "payload.ip_address": "127.0.0.1",
  "payload.user": "Joe",
  "tags": "[]",
  "newrelic.source": "logs.APM",
  "thread.name": "6500",
  "timestamp": 1727874680026
}

Actual Behavior

Current behavior implemented in #222 is to nest everything under message key (I guess because NR method to log doesn't support attributes), so by using your appender we get this:

image

It would be super nice to lift everything in top level, They implemented https://github.com/newrelic/newrelic-ruby-agent/pull/2084 (and also have a proposal to have them contextually https://github.com/newrelic/newrelic-ruby-agent/issues/2297)

I don't know if NewRelic::Agent.agent.log_event_aggregator.add_custom_attributes(foo: 'bar', baz: 'bat') can be used as is, but it could help.

fabn avatar Oct 02 '24 13:10 fabn

Hey @fabn. Hope you're gearing up for an excellent New Years.

I've got a PR out here if you'd like to help engage in some testing and feedback.

https://github.com/reidmorrison/semantic_logger/pull/307

rtizzy avatar Dec 31 '24 11:12 rtizzy

@rtizzy seems awesome, I'll try that as soon as I can.

Thanks and happy new year to you as well

fabn avatar Dec 31 '24 12:12 fabn