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

Add logging API to the SDK #159

Merged
merged 8 commits into from
May 28, 2020
Merged

Add logging API to the SDK #159

merged 8 commits into from
May 28, 2020

Conversation

jkwatson
Copy link
Contributor

@jkwatson jkwatson commented May 8, 2020

This addition to the SDK will be useful for non-typical logging usages, such as reporting OpenTelemetry Span Events as log entries, in context. It's not intended as an API to be used to implement high-throughput logging systems. That use-case should be reserved for log forwarder implementations.

Copy link
Contributor

@jeffalder jeffalder left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Even though it's nice to have the symmetry for L as we do for M, E, and T, I don't think this is the right approach. It doesn't seem useful not being integrated with any logging framework, and I think it looks at "logs as telemetry" instead of "application logs as one set of logs in an application stack".

When we implemented logs-in-context, there was a lot of debate about whether the agent should just send the log messages or we should rely on something else to do it. Matt Culmone, one of the Log PMs, was adamant that the application should not be posting logs to an HTTP endpoint. There are existing solutions for this, like log forwarders, that do a far better job batching, scanning, rewinding, etc across multiple services and multiple sources than we ever could. If the user wants to consume any other type of logging, like access logs or nginx logs or non-Java logs, they would still need a log forwarder.

Before shipping this implementation, I'd encourage you to reach out to Matt or Rebecca Holzschuh to understand what they'd recommend.

gradle.properties Outdated Show resolved Hide resolved
logger.debug(
"Sending a log batch (number of logs: {}) to the New Relic log ingest endpoint)",
batch.size());
String json = marshaller.toJson(batch);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need to rethink the sender if we're going to implement this as-is. If the sender does literally any logging you could quickly drown yourself in recursive logs without careful configuration. Think about audit logging:

  1. There's an http post.
  2. There's a log message with the contents of the post.
  3. There's an http post with the log message with the contents of the post.
  4. There's a log message with the contents of the post with the log message with the contents of the post.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is no expectation that this code would be used as the API for a full-fledged logging implementation, so I don't think this is a concern.

@jkwatson
Copy link
Contributor Author

Even though it's nice to have the symmetry for L as we do for M, E, and T, I don't think this is the right approach. It doesn't seem useful not being integrated with any logging framework, and I think it looks at "logs as telemetry" instead of "application logs as one set of logs in an application stack".

When we implemented logs-in-context, there was a lot of debate about whether the agent should just send the log messages or we should rely on something else to do it. Matt Culmone, one of the Log PMs, was adamant that the application should not be posting logs to an HTTP endpoint. There are existing solutions for this, like log forwarders, that do a far better job batching, scanning, rewinding, etc across multiple services and multiple sources than we ever could. If the user wants to consume any other type of logging, like access logs or nginx logs or non-Java logs, they would still need a log forwarder.

Before shipping this implementation, I'd encourage you to reach out to Matt or Rebecca Holzschuh to understand what they'd recommend.

Hi Jeff. My use-case for this is not acting as the primary API for logging implementations. This is to support some log-like features of OpenTelemetry. In particular, the events that can be attached to Spans are being used to log information about the processing of a given span. I'd like to experiment with writing them as log entries using the logging API. I discussed this with Rebecca and she agreed.

@jeffalder jeffalder added this to In progress in Java Engineering Board May 13, 2020
@jkwatson jkwatson marked this pull request as ready for review May 20, 2020 20:29
@jkwatson
Copy link
Contributor Author

@jeffalder note, my use-case for this is supporting the "embedded" log model being discussed here: open-telemetry/opentelemetry-specification#622

Copy link

@justinfoote justinfoote left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall, I'm in favor of the concept. If we're providing an HTTP endpoint to send logs to, it only makes sense that we'd include functionality to use that endpoint in our telemetry SDKs.

Before we go through with this, I'd like to see the exporter specs and the telemetry SDK specs updated to match.

ByteArrayOutputStream bytes = new ByteArrayOutputStream();
e.printStackTrace(new PrintStream(bytes));
this.message = bytes.toString();
this.logType = "stackTrace";

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this a convention?

If so, it doesn't align with our other logging error semantics, here: https://github.com/newrelic/newrelic-exporter-specs/tree/master/logging#errors

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ooh! I totally forgot there were semantics already designed for some of this stuff. Will address!

@jkwatson
Copy link
Contributor Author

Before we go through with this, I'd like to see the exporter specs and the telemetry SDK specs updated to match.

Chicken and egg! I don't think we'd want to update the exporter specs until we've actually got an exporter using this and it's the officially sanctioned way to send span events (or whatever). Telemetry SDK, though, yes. Should we get this at least merged before we spend time writing specs for it, pre-release?

@jeffalder
Copy link
Contributor

jeffalder commented May 27, 2020

@jkwatson

Before it became real, much testing and documentation would need to be added.

I don't see any new tests here, and it looks like this is ready to merge.

There's so much code cloned from the span side because the API shapes are so similar. Can you explain why they're cloned?

@jkwatson
Copy link
Contributor Author

@jkwatson

Before it became real, much testing and documentation would need to be added.

I don't see any new tests here, and it looks like this is ready to merge.

There's so much code cloned from the span side because the API shapes are so similar. Can you explain why they're cloned?

I need to add tests; just realized that there are a lot missing still. I'll be doing that ASAP.

The code is cloned because I was moving fast to get something working. After this gets merged, I think that's definitely something to figure out how to unify.

@jkwatson
Copy link
Contributor Author

ok, added tests for json generation, and an integration test. Also got the attribute names in line with the exporter specs for logs.

@jeffalder
Copy link
Contributor

The code is cloned because I was moving fast to get something working. After this gets merged, I think that's definitely something to figure out how to unify.

We already have a backlog of 16 tickets. Are you suggesting just tacking on more to the backlog? That is an issue that will never get done because it's tedious housekeeping. I feel like this is how tech debt becomes overwhelming, and we have reactions like "if we had just done this at the time ..."

I feel we have a responsibility to maintain maximally clean code. Unless there's roadmap pressure to ship this that I'm not aware of?

@jkwatson
Copy link
Contributor Author

@jeffalder do you think that this PR should also include significant refactoring of unrelated code? Do you have specific examples of where you want things refactored? I feel like refactoring should happen in a separate PR from one that adds new functionality.

@jkwatson
Copy link
Contributor Author

Before we go through with this, I'd like to see the exporter specs and the telemetry SDK specs updated to match.

Chicken and egg! I don't think we'd want to update the exporter specs until we've actually got an exporter using this and it's the officially sanctioned way to send span events (or whatever). Telemetry SDK, though, yes. Should we get this at least merged before we spend time writing specs for it, pre-release?

@justinfoote newrelic/newrelic-telemetry-sdk-specs#16

@jeffalder jeffalder merged commit 9e07000 into master May 28, 2020
Java Engineering Board automation moved this from In progress to Done May 28, 2020
@jeffalder jeffalder deleted the add_logs branch May 28, 2020 16:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

None yet

3 participants