Locations of visitors to this page

Tracing

There are two types of tracing in this library. Either trace all methods of a composite, or only trace methods marked for tracing.

Trace All


To enable tracing of all methods, you only need to add the TraceAllConcern to the Composite declaration (or one of the super types).
public interface My
{
    void doSomething();

    void doSomethingElse();
}

@Concerns( { SomeOtherConcern.class, TraceAllConcern.class } )
@Mixins( MyMixin.class )
public interface MyComposite extends My, Composite
{
}

In the above example, the TraceAllConcern will intercept all methods, i.e. doSomething() and doSomethingElse(), and track the time of entry, duration, which thread and a few other things, and send that to a TraceService. If there is no TraceService available, the tracing is disabled.

Trace Method


It is possible to instead mark which methods that should be traced. This is done via the @Trace annotation and the Qi4j AppliesTo feature.

If we only want to trace the doSomethingElse() method in the above example, we do like this instead;

public interface My
{
    void doSomething();

    @Trace
    void doSomethingElse();
}

@Concerns( { SomeOtherConcern.class, TraceConcern.class } )
@Mixins( MyMixin.class )
public interface MyComposite extends My, Composite
{
}

Note that the TraceAllConcern has been changed to the TraceConcern instead.

The Trace annotation can also take a "level" argument. It means that only if the TraceService traceLevel() property is set lower than or equal that of the "level" in the Trace annotation, there will be a trace record produced.

TraceService


For tracing to be active at all, a TraceService must be present and visible to the composite where the TraceConcern is located.

The TraceService interface is fairly simple;

public interface TraceService
{
    int traceLevel();

    void traceSuccess( Class compositeType, Composite object,
                       Method method, Object[] args,
                       Object result,
                       long entryTime, long durationNano );

    void traceException( Class compositeType, Composite object,
                         Method method, Object[] args,
                         Throwable t,
                         long entryTime, long durationNano );

}


Qi4j and the Qi4j logo are trademarks of Richard Öberg, Niclas Hedhman and the members of the Qi4j Core Team. See Qi4j licensing for more information.
Powered by SiteVisionexternal link.