Skip to content
This repository was archived by the owner on Aug 4, 2023. It is now read-only.

Conversation

watson
Copy link
Contributor

@watson watson commented Aug 6, 2018

No description provided.

@watson
Copy link
Contributor Author

watson commented Aug 7, 2018

@Qard The codecov tests are failing. I don't think it's that relevant to add tests for this debug option, but I can do it if you like. Otherwise we'll either just merge or add a codecov.yml file to lower the failure limits. What do you think?

README.md Outdated
## Debugging

To see what data is being sent to the APM Server, use the environment
variable `ELASTIC_APM_PAYLOAD_LOG` to speicfy a log file, e.g:
Copy link
Contributor

Choose a reason for hiding this comment

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

specify*

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed

@Qard
Copy link
Contributor

Qard commented Aug 7, 2018

Any reason not to just do this as a regular config option, like everything else?

@watson
Copy link
Contributor Author

watson commented Aug 7, 2018

@Qard hmm maybe not... I was just doing it like this because this is how it was done previously with the DEBUG_PAYLOAD environment variable. The idea was that this would never be something you'd actually do in production, but meant as a debug setting you could enable on the fly when debugging a problem with the agent without having to edit the code. At least that's how I've always used it. So I didn't see a need for a config option. Do you think we need it outside of working on the agent it self?

@Qard
Copy link
Contributor

Qard commented Aug 7, 2018

My thinking was that:

  1. The http client currently doesn't use process.env anywhere, so this is a new configuration mechanism to think about supporting.
  2. The fact that the environment variable matches the pattern of the other agent environment variables might lead one to think that it goes through the same config system and therefore would have an equivalent object field name.

I'm good with this PR as-is, if you feel it's better to just have the environment variable reading here, rather than as a config input.

@watson watson changed the title feat: add ELASTIC_APM_PAYLOAD_LOG debug option feat: add payloadLogFile debug option Aug 8, 2018
@watson
Copy link
Contributor Author

watson commented Aug 8, 2018

@Qard good points... I converted it into a config option, refactored it a bit to include the metadata, added tests, and rebased with the base branch. So had to force push

index.js Outdated
if (!client._payloadLogFile) {
client._payloadLogFile = require('fs').createWriteStream(opts.payloadLogFile, {flags: 'a'})
}
pump(stream, client._payloadLogFile)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@Qard hmm pump might actually close the file once stream ends. I'll just investigate if this works for more than one request

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed

index.js Outdated
@@ -220,6 +220,15 @@ function onStream (opts, client, onerror) {
next()
})

if (opts.payloadLogFile) {
if (!client._payloadLogFile) {
client._payloadLogFile = require('fs').createWriteStream(opts.payloadLogFile, {flags: 'a'})
Copy link
Contributor Author

@watson watson Aug 8, 2018

Choose a reason for hiding this comment

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

@Qard This will leave the file open forever. We could also just close it every time stream closed and then reopen it again at the next request. Is there a downside of just leaving it open like this?

Copy link
Contributor

Choose a reason for hiding this comment

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

Since it's intended just for debugging purposes, I don't think it matters much. I think it's fine to leave it as-is.

index.js Outdated
}
stream.on('data', function (chunk) {
client._payloadLogFile.write(chunk)
})
Copy link
Contributor

Choose a reason for hiding this comment

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

Is there a reason you don't use pipe/pump?

Copy link
Contributor Author

@watson watson Aug 9, 2018

Choose a reason for hiding this comment

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

If I used pipe/pump it would close the file when stream ended. That's not an issue as such, but then I couldn't re-use the file handle and would have to open it again for each stream that was opened

Copy link
Contributor Author

Choose a reason for hiding this comment

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

But maybe that's cleaner? Even though there's an overhead of re-opening the file for each stream. As it's just for debug purposes, I'm not that concerned with the performance.

Copy link
Contributor

Choose a reason for hiding this comment

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

Didn't think about the closing issue. In that case, we just leave it as-is.

Copy link
Contributor

@Qard Qard left a comment

Choose a reason for hiding this comment

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

I'm fine with it as it is. 👍

@watson watson merged commit fca57a6 into elastic:api-v2 Aug 10, 2018
@watson watson deleted the debug branch August 10, 2018 08:15
watson added a commit that referenced this pull request Nov 8, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants