Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using logrus JSON formatter with logcontext-v2 #606

Open
betabandido opened this issue Nov 25, 2022 · 2 comments
Open

Using logrus JSON formatter with logcontext-v2 #606

betabandido opened this issue Nov 25, 2022 · 2 comments

Comments

@betabandido
Copy link

Summary

We would like to use the new logcontext v2, but continue using a JSON formatter that extracts the different logrus fields into individual fields in the log details in New Relic Logs.

Desired Behaviour

In our applications we use logcontext v1 (https://github.com/newrelic/go-agent/tree/master/v3/integrations/logcontext) together with the nrlogrusplugin. We have seen there is now a v2 available for logcontext. We would like to use this new version as it is able to easily annotate log statements outside of a transaction. Otherwise, we need to rely on something like

txn := newRelicApp.StartTransaction("dummy")
log.WithContext(newrelic.NewContext(context.Background(), txn)).
	Info("some message")
txn.End()

which seems a little bit too much just to log a message.

The issue with using logcontext v2 is that we have not been able to use a JSON formatter (New Relic's documentation only mentions the TextFormatter, so we wonder if it is the only one supported at this moment). We have tried:

log.SetFormatter(nrlogrus.NewFormatter(newRelicApp, &log.JSONFormatter{}))

and while we do see the logs on New Relic, the JSON fields are not extracted and they are simply listed in the log message field (as a string, instead of individual fields). That means we cannot easily query using NRQL.

Is it actually possible to use a JSON formatter with logcontext v2 and still get the old behavior (where the different JSON fields get extracted and are available in New Relic Logs)?

@iamemilio
Copy link
Contributor

Hi, we fully support ANY valid logrus formatter, since we are able to extract the value from the logrus fields before they get formatted. This is correctly labeled as an enhancement, and is something we are planning to bring to the v2 logging products in the future.

@betabandido
Copy link
Author

betabandido commented Dec 1, 2022

Do you have any timeline for this? In the meanwhile, do you have any suggestion other than doing something along the lines of the solution mentioned above? The one using logcontext v1 and this "trick":

txn := newRelicApp.StartTransaction("dummy")
log.WithContext(newrelic.NewContext(context.Background(), txn)).
	Info("some message")
txn.End()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants