The following recommendations can be applied to the BTT framework and application
traces. Most of the recommendations are not BTT specific, but can be applied
to any tracing implementation:
- Consider using Aspect Oriented Programming to de-clutter the application
and infrastructure code. In some cases, around half of the code might be trace
code that complicates its understanding and therefore its maintenance. Naming
conventions are important when using AOP since they help define clear AOP
rules.
- Avoid by all means tracing to the system console through System.out or
System.err. This cannot be switched off easily and therefore it will still
execute in the production environment.
- Add a check before each trace to verify if the traces are enabled for
the provided level and component ID, only trace if the check
returns true. Strictly speaking, this is required only if the message string
is generated by executing some concatenation or rendering code, in order to
avoid the useless execution of that code. If AOP is not used, the check might
be skipped when tracing simple predefined messages, in order to reduce code
clutter.
- Use the appropriate trace levels, and then review the high-severity messages.
A step of the quality review process can consist of reading the traces and
ensuring that no trace above the warning level is ever generated in otherwise
correctly working code. If a high severity trace is detected, it should be
fixed through one of the following actions:
- Either the code is really failing and needs to be fixed until no trace
is generated, or
- The trace level for that component is incorrect and needs to be lowered
down.
- In the production environment, disable all the trace levels except the
highest severity ones. Tracing can degrade performance: if required, use the
pre-production environment, which should have more traces to locate problems.
- Do not mistake technical-levle tracing, which should be used exclusively
by developers to pinpoint potential problems, with business level-logging.
If you need to keep an audit trail of the execution of the business function,
use a separate system, and implement it through a BTT service.