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

Don't write full stack trace to system console on exceptions while trying to send messages to IoT Hub #44

Closed
wants to merge 10 commits into from

Conversation

JMayrbaeurl
Copy link
Contributor

@JMayrbaeurl JMayrbaeurl commented Mar 10, 2017

Checklist

  • I have read the [contribution guidelines] (https://github.com/Azure/azure-iot-sdk-java/blob/master/.github/CONTRIBUTING.md).
  • I added or modified the existing tests to cover the change (we do not allow our test coverage to go down). No modification necessary
  • If this is a modification that impacts the behavior of a public API
    • I edited the corresponding document in the devdoc folder and added or modified requirements.
  • I submitted this PR against the correct branch:
    • This pull-request is submitted against the master branch.

Reference/Link to the issue solved with this PR (if any)

Description of the problem

Reported by Partner Bosch Rexroth: If there are exceptions on trying to send messages to IoT Hub with class IotHubSendTask, full stack traces will be written to the console. This causes problems on devices with few memory and disk space (when forwarding the console output to log files)

Description of the solution

Introduced new boolean class property 'verboseErrorMessaging' that defaults to false and is used in catch clause to determine if full stack traces should be written to the system console. This means that the default behavior of the class has been changed to NOT write full stack traces on exceptions.
iot-hub-exceptions

@msftclas
Copy link

@JMayrbaeurl,
Thanks for your contribution.
To ensure that the project team has proper rights to use your work, please complete the Contribution License Agreement at https://cla.microsoft.com.

It will cover your contributions to all Microsoft-managed open source projects.
Thanks,
Microsoft Pull Request Bot

@msftclas
Copy link

@JMayrbaeurl, thanks for signing the contribution license agreement. We will now validate the agreement and then the pull request.

Thanks, Microsoft Pull Request Bot

for (StackTraceElement el : e.getStackTrace())
{
// JMayrbaeurl 2017-03-10: Should be replaced with real logging setup
System.out.println(el);
Copy link
Member

Choose a reason for hiding this comment

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

I think we have logger use in this module and would recommend using logger here instead of println. So that interested users can debug it using log.
And if we go the route of logger you woudn't really need verboseErrMessaging anymore. By default you can always write fatal error message in this case.

@prmathur-microsoft
Copy link
Member

Thanks for your PR. Can you please address my comment and then we pull it in.

@JMayrbaeurl
Copy link
Contributor Author

Addressed your comment. Added slf4j logging to the classes that send and receive messages to and from the IoT Hub. Full stack traces are only written to the log when using debug level on logging

<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
</dependency>
Copy link
Member

Choose a reason for hiding this comment

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

Thank you for proving a sample. But for now we will investigate this option and add support to better logging in future. As of now if we let this change in then only part of the SDK will be supporting this method of logging and rest will still be dependent on log4j. So I will hold off on this change.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is no breaking change and I really don't like to make changes that introduce an old error once again. Transitioning to logging facades is no enhancement, but a bug fix and has to be done asap. It's probably better to change the CustomLogger or even better completely remove it/exchange it by using slf4j logging facades. This can be done in an hour! If you don't accept the PR this way, I will close it and will open an according issue for it.

Copy link
Member

Choose a reason for hiding this comment

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

Sounds good. If you are willing to provide a PR then please do so. I will be happy to review it.
Just to let you know we expect the following from the PR-

  1. Please remove any occurrences of log4J from requirement docs (https://github.com/Azure/azure-iot-sdk-java/tree/master/device/iot-device-client/devdoc/requirement_docs/com/microsoft/azure/iothub), unit tests(https://github.com/Azure/azure-iot-sdk-java/tree/master/device/iot-device-client/src/test/java/tests/unit/com/microsoft/azure/sdk/iot/device) and code.
  2. Provide an implementation, requirements and unit tests for new logging method for the entire SDK and replace the occurrence of log4j logger with your approach.
  3. Update github documents (https://github.com/Azure/azure-iot-sdk-java/tree/master/device/iot-device-samples#logging) and our send-receive sample (https://github.com/Azure/azure-iot-sdk-java/tree/master/device/iot-device-samples/send-receive-sample) with proper instructions for logging.

If you wish to it can be a separate PR as well.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I have done this in a separate PR #57 . I tried to follow the three steps described above as good as possible.

* Private logger for class
*/
final Logger logger = LoggerFactory.getLogger(IotHubReceiveTask.class);

Copy link
Member

Choose a reason for hiding this comment

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

Can this be changed to the logger (CustomLogger) in use currently until we address proper logging method.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No. Can't be changed to CustomLogger. See comment above.

@prmathur-microsoft
Copy link
Member

I'm very much interested in the original change that you mentioned is required by the customer related to printing stack trace and moving it to logger. If you can use custom logger at the moment until we address better logging across the SDK, I can pull this change in.

@JMayrbaeurl
Copy link
Contributor Author

Since this is a critical bug fix for our partner I have changed back the logger implementation to use the CustomLogger class instead of slf4j (still believe that this is the only way to do logging).

Merged 1.0.22 release changes

if (transport == null)
throw new IllegalArgumentException("Parameter 'transport' must not be null");

Copy link
Member

Choose a reason for hiding this comment

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

Move this check to line 22

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@prmathur-microsoft : With current setup constructors of IotHubSendTask and IotHubReceiveTask will write a wrong log error message when parameter 'transport' is not null. If it's null, no log message will be written, since the code is no longer reachable

public IotHubSendTask(IotHubTransport transport)
{
// Codes_SRS_IOTHUBSENDTASK_11_001: [The constructor shall save the transport.]
this.transport = transport;

if (transport == null)
throw new IllegalArgumentException("Parameter 'transport' must not be null");
Copy link
Member

Choose a reason for hiding this comment

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

Move this check to line 23

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@prmathur-microsoft : With current setup constructors of IotHubSendTask and IotHubReceiveTask will write a wrong log error message when parameter 'transport' is not null. If it's null, no log message will be written, since the code is no longer reachable

@prmathur-microsoft
Copy link
Member

This PR did not have the following :

  1. Did not address CR
  2. Went back and forth between log4j and slf4j without addressing the issue at hand which was blocking the customer.
  3. Author was unwilling to address any CR changes given in the past, hence I have addressed it myself to unblock the customer and taken it forward.
  4. PR was not split well between what was needed vs what is good to have.

Addressed all the above, squashed all the commits, pushed changes to unblock customer @commit d9cebc3

@JMayrbaeurl
Copy link
Contributor Author

Concerning @prmathur-microsoft latest comments:

  1. Did not address CR: First commit @commit fc925b3 in PR provided 18 days ago completely addressed CR and didn't introduce any kind of other changes.
  2. Went back and forth between log4j and slf4j without addressing the issue at hand which was blocking the customer: Introducing logging was proposed by @prmathur-microsoft and changed several times to fulfill non-standard logging approach required by reviewer.
  3. Author was unwilling to address any CR changes given in the past, hence I have addressed it myself to unblock the customer and taken it forward: Latest version of PR was done with CustomLogger usage according to CR of @prmathur-microsoft . No unblocking of the customer so far, since released versions of the SDKs still have this issue.
  4. PR was not split well between what was needed vs what is good to have: : First version of PR, provided 18 days ago, simply solved the customer's problem. Discussions about additional changes was started by @prmathur-microsoft

@JMayrbaeurl JMayrbaeurl deleted the bosch-dev branch March 28, 2017 18:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants