-
-
Notifications
You must be signed in to change notification settings - Fork 3.6k
EmbedAPI: log success requests #8689
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
Conversation
446bbe5
to
bcbe3b3
Compare
Log success requests using `django-structlog` and send them New Relic to know what projects are using EmbedAPI, if they are using sphinx-hoverxref and what version of it. This is the minimum configuration required to start using structlog + New Relic. If we are happy with the results we can migrate the other logs to structlog, which should be simple, but a little tedious to do search&replace. In the future, we can also set up django-structlog to log Celery tasks as well.
bcbe3b3
to
d65241d
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks like an interesting approach. I haven't played around too much with the NR interface, but it looks like a good first attempt at capturing this data in a way we can aggregate. I believe AWS also has a similar product that does log aggregation/querying, so this feels like a good integration point that isn't locking us in to a specific backend too deeply.
I'm a little worried about swapping out our entire logging infra as part of this change. It makes it a higher stakes change if we want to try to get it into production as a test. It seems like structlog would be useful in other ways in our code though, so if y'all think it would be work adding I'm 👍 on taking the work on now as part of this.
Changing(*) our entire logging infra to structlog + NewRelic has other benefits as well and it's something I've been wanting for years now (did I mention Loggly already? 😅 ). For example,
So, I'd be 👍🏼 on working towards this change as a whole by doing the steps mentioned in the PR's description and keep using (r)syslog together with New Relic. One last thing that I'd like to know if it's possible is to "send logs in chunk" since I would like to avoid hitting an API endpoint for each |
c45eab5
to
9c1f625
Compare
Pushing this a release out, this still looks to be in a draft state. |
9c1f625
to
4962494
Compare
I did the minimal implementation using structlog + New Relic formatter + rsyslog to send data to NR. As we are using a mixture of Note that all the logging keeps working in the same way, but the log entries coming from structlog (those from EmbedAPI) are rendered as JSON in the console for now. Once we migrate our logging to structlog we can have a lot nicer rendering. Example, |
8622310
to
3444dda
Compare
Use structlog _only_ for EmbedAPI v2/v3 for now. We will do a test in production to this and decide the migration path for the whole codebase.
3444dda
to
2dc1c94
Compare
Initial work to migrate our application to structlog for better logging, making them compatible with New Relic's integration. There are more work that can be done here to make it better. For example, more usage of `log.bind` to avoid repetition. Besides, rewriting some log message and reduce them to have more Canonical Log Lines (https://www.structlog.org/en/stable/logging-best-practices.html#canonical-log-lines) instead.
Logs coming from `logging.getLogger` (from other applications) have the same structure that the ones logged by us via `structlog`.
This seems like a good middle ground. I am finding the newrelic interface is harder to watch logs at, but really helpful if you know what you are looking for. It doesn't seem like the new relic UI or the new relic cli could really replace the simplicity of parsing logs with basic unix tools. So maintaining local logging for debugging and operations, alongside new relic logs for inspecting the data inside the logs, is probably about where we want to be. |
We can output a On the other hand, having these colors in the console's output is super handy while developing locally. Let me know if you have specific requests about the output formatting, and we can work together to output a I'd move forward by merging all the PRs that make usage of structlog all around our codebase and improve any particular thing that we found can be improved. |
I think the format you posted looks great. It's a bit easier to grep than our current format as the module name has clear delineation and it splits up the log text and parameters. I would have an easier time processing the log format you suggested compared to what we have now. I'd be curious how this looks after going through rsyslog to the central logging server. |
I already deployed an instance of web-extra as a test. You can see the logs by doing:
Note that they are colorized currently, which is something we may not want, but that's as simple as passing |
I just see a lot of lines like:
JSON is very handy for scanning if you are a robot, but alas, I am human and this is very hard to read |
@agjohnson I don't know where you got those lines. The file that I mentioned does not contain those lines. Which file on what instance contains those lines? |
OK! I found those lines in I updated the Now, the logs in
|
I made the last adjustments to use colors only locally and plain text in production. IMO, this is ready to be merged together with the other PRs that migrate our app logging to structlog. |
Yup, I was looking at
Looks good. If there is a way to remove the timestamp, it's duplicated in the message. Also, the current logs have:
|
Yes, we are adding our own timestamp. Ideally, it would be good to remove the timestamp added by rsyslog and control everything from structlog instead of having a hybrid.
We have this information in New Relic ( We can add or modify the log lines as we want, it's possible by adding more structlog processors. However, I want to move forward with all of these PRs instead of blocking them on these small differences. We can tweak these lines as we go once we have the big parts connected and working all together. |
Use a custom renderer to match the structure we want: ``` %programname[%processid] [%level] %message [%logger:%linenumber] %structureddata ``` By default, rsyslog will prepend ``` %timestamp %hostname ``` and it will look exactly as we want.
@agjohnson I wrote a custom structlog processor and renderer to add the process id and the line number in a similar way as it was. I'm leaving the timestamp and hostname to be added by rsyslog as it was. The result is:
Note that we have All these changes are done in the other PR that is based on this one #8705 and these examples are taken from the web-extra instance already deployed. |
structlog: migrate application code to better logging
Well, the duplicated timestamp is mostly an annoyance. If it's for some reason required from structlog, it's fine to keep it. It wasn't clear if this was the case though. It might be possible for rsyslog to control the log output per file, but if the only option is to adjust the rsyslog format at the server level, we'd lose important debugging information from all of the host services not using structlog.
We shouldn't be removing functionality from our logging though. I'm happy to include a secondary service to make log analysis easier for folks. But, there is a big cost to learning new tooling and shifting our processes. Personally speaking, log parsing was a solved problem and I'd much sooner use standard tools than buy into New Relic tooling. I don't want others to have to struggle with manual log parsing however, so the secondary tooling is a great optional addition.
Agreed, I'd like to see this merged. The best way forward is going to be affecting our current logging as little as possible. It sounded like @ericholscher echoed my concerns here. It seems like there was maybe some work here that could have been considered separate work from the project for metric collection, so there is a bit more friction to merging the work now.
Sorry going through everything sequentially here The format you landed on looks good 👍 I agree we can tweak later, and preserving existing functionality allows a secondary service to exist without interrupting our current processes. |
18a8d71
to
e39b3bb
Compare
I rebased to make history happy with #8705 merged. Edit: it is not happier. |
It wasn't clear that #8705 was merging here and the additional commits made review hard here. Rebasing made things worse. I opened #8729 to review just the commits that were originally in this PR. Edit: review looked good there. I returned this to the original commit before I rebased. This includes the #8705 merge into this branch. Everything now looks good to merge, pending tests are happy. |
e39b3bb
to
18a8d71
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Approved in #8729 👍
Log success requests using
django-structlog
and send them New Relic to knowwhat projects are using EmbedAPI, if they are using sphinx-hoverxref and what
version of it.
This is the minimum configuration required to start using structlog + New Relic.
If we are happy with the results we can migrate the other logs to structlog,
which should be simple, but a little tedious to do:
logging
bystructlog
key=value
from log messages to keyword attributes%s
is mixed with the message itself)log.bind
and context.In the future, we can also set up django-structlog to log Celery tasks as well (https://django-structlog.readthedocs.io/en/latest/celery.html) which will give us traceability since it logs the
task_id
automatically and other extra features.References