public interface NetworkTracer
Observes every ConnectionRequest the NetworkManager runs, so a tracer can time
each one and put trace context on it.
Installed with NetworkManager.setNetworkTracer(NetworkTracer). The one
implementation is com.codename1.telemetry.Telemetry’s, and it is reached only
from the bootstrap the build generates for a project that enables it – so an app
that does not trace carries this interface and nothing else.
This is a separate slot from NetworkGuard on purpose. The guard is a security
decision: it seals on first install and can veto a request. A tracer observes and
decorates, never refuses, and must not have to compete with the guard for the one
slot the guard deliberately makes unreplaceable.
Every callback is guarded by the caller: an exception thrown from one is logged and the request carries on untraced.
Methods
public abstract Object requestQueued(ConnectionRequest request) | A request is being queued, on the thread that queued it – the EDT, for most requests. |
public abstract Object beforeRequest(ConnectionRequest request, Object parent) | An attempt is about to connect, on the network thread, before the request’s headers are written. |
public abstract void afterRequest(ConnectionRequest request, Object attempt, int responseCode, Throwable error) | An attempt beforeRequest started has ended, on the network thread. |
Method details
requestQueued
public abstract Object requestQueued(ConnectionRequest request)beforeRequest, which is
how a request records the span that was current when the app ASKED for it,
rather than whatever is current on the network thread later.Returns
beforeRequest
public abstract Object beforeRequest(ConnectionRequest request, Object parent)ConnectionRequest.addRequestHeader(String, String) are sent. Called again
for every retry and redirect, each of which is its own attempt.Parameters
requestConnectionRequest- the request
parentObject- what
requestQueuedreturned for it – or, for a retry or redirect of a request queued with no parent, the attempt before it (what this method returned then), so that the attempts share one trace
Returns
afterRequest, or null to not trace itafterRequest
public abstract void afterRequest(ConnectionRequest request, Object attempt, int responseCode, Throwable error)beforeRequest started has ended, on the network thread.Parameters
requestConnectionRequest- the request
attemptObject- what
beforeRequestreturned responseCodeint- the HTTP status, or a value below 100 when none arrived
errorThrowable- what failed the attempt, or null