use of com.google.firebase.perf.metrics.NetworkRequestMetricBuilder in project firebase-android-sdk by firebase.
the class FirebasePerfHttpClient method execute.
/**
* Send network metric for Apache HttpClient.execute(HttpHost target, HttpRequest request,
* ResponseHandler<? extends T> responseHandler)
*
* @return <T> T
* @throws IOException if unable to execute request or receive response
*/
static <T> T execute(final HttpClient client, final HttpHost target, final HttpRequest request, final ResponseHandler<? extends T> responseHandler, final Timer timer, final TransportManager transportManager) throws IOException {
NetworkRequestMetricBuilder builder = NetworkRequestMetricBuilder.builder(transportManager);
try {
builder.setUrl(target.toURI() + request.getRequestLine().getUri()).setHttpMethod(request.getRequestLine().getMethod());
Long requestContentLength = NetworkRequestMetricBuilderUtil.getApacheHttpMessageContentLength(request);
if (requestContentLength != null) {
builder.setRequestPayloadBytes(requestContentLength);
}
// Execute network Request
timer.reset();
builder.setRequestStartTimeMicros(timer.getMicros());
return client.execute(target, request, new InstrumentApacheHttpResponseHandler<T>(responseHandler, timer, builder));
} catch (IOException e) {
builder.setTimeToResponseCompletedMicros(timer.getDurationMicros());
NetworkRequestMetricBuilderUtil.logError(builder);
throw e;
}
}
use of com.google.firebase.perf.metrics.NetworkRequestMetricBuilder in project firebase-android-sdk by firebase.
the class FirebasePerfHttpClient method execute.
/**
* Send network metric for Apache HttpClient.execute(HttpUriRequest request, ResponseHandler<?
* extends T> responseHandler, HttpContext context)
*
* @return <T> T
* @throws IOException if unable to execute request or receive response
*/
static <T> T execute(final HttpClient client, final HttpUriRequest request, final ResponseHandler<T> responseHandler, final HttpContext context, final Timer timer, final TransportManager transportManager) throws IOException {
NetworkRequestMetricBuilder builder = NetworkRequestMetricBuilder.builder(transportManager);
try {
builder.setUrl(request.getURI().toString()).setHttpMethod(request.getMethod());
Long requestContentLength = NetworkRequestMetricBuilderUtil.getApacheHttpMessageContentLength(request);
if (requestContentLength != null) {
builder.setRequestPayloadBytes(requestContentLength);
}
// Execute network Request
timer.reset();
builder.setRequestStartTimeMicros(timer.getMicros());
return client.execute(request, new InstrumentApacheHttpResponseHandler<T>(responseHandler, timer, builder), context);
} catch (IOException e) {
builder.setTimeToResponseCompletedMicros(timer.getDurationMicros());
NetworkRequestMetricBuilderUtil.logError(builder);
throw e;
}
}
use of com.google.firebase.perf.metrics.NetworkRequestMetricBuilder in project firebase-android-sdk by firebase.
the class FirebasePerfHttpClient method execute.
/**
* Send network metric for Apache HttpClient.execute(HttpHost target, HttpRequest request,
* HttpContext context)
*
* @return HttpResponse from executing request
* @throws IOException if unable to execute request or receive response
*/
static HttpResponse execute(final HttpClient client, final HttpHost target, final HttpRequest request, final HttpContext context, final Timer timer, final TransportManager transportManager) throws IOException {
HttpResponse response = null;
NetworkRequestMetricBuilder builder = NetworkRequestMetricBuilder.builder(transportManager);
try {
builder.setUrl(target.toURI() + request.getRequestLine().getUri()).setHttpMethod(request.getRequestLine().getMethod());
Long requestContentLength = NetworkRequestMetricBuilderUtil.getApacheHttpMessageContentLength(request);
if (requestContentLength != null) {
builder.setRequestPayloadBytes(requestContentLength);
}
// Execute network Request
timer.reset();
builder.setRequestStartTimeMicros(timer.getMicros());
response = client.execute(target, request, context);
builder.setTimeToResponseCompletedMicros(timer.getDurationMicros());
builder.setHttpResponseCode(response.getStatusLine().getStatusCode());
Long responseContentLength = NetworkRequestMetricBuilderUtil.getApacheHttpMessageContentLength(response);
if (responseContentLength != null) {
builder.setResponsePayloadBytes(responseContentLength);
}
String contentType = NetworkRequestMetricBuilderUtil.getApacheHttpResponseContentType(response);
if (contentType != null) {
builder.setResponseContentType(contentType);
}
builder.build();
} catch (IOException e) {
builder.setTimeToResponseCompletedMicros(timer.getDurationMicros());
NetworkRequestMetricBuilderUtil.logError(builder);
throw e;
}
return response;
}
use of com.google.firebase.perf.metrics.NetworkRequestMetricBuilder in project firebase-android-sdk by firebase.
the class FirebasePerfUrlConnection method openStream.
// Functions to collect information for the Network Request Metric
/**
* Send network request metric for UrlConnection.getInputStream()
*
* @return InputStream the input stream from the url connection
* @throws IOException if there is a problem with opening the connection or using the connection
* to open a stream
*/
static InputStream openStream(URLWrapper wrapper, TransportManager transportManager, Timer timer) throws IOException {
timer.reset();
long startTime = timer.getMicros();
NetworkRequestMetricBuilder builder = NetworkRequestMetricBuilder.builder(transportManager);
try {
URLConnection connection = wrapper.openConnection();
if (connection instanceof HttpsURLConnection) {
return new InstrHttpsURLConnection((HttpsURLConnection) connection, timer, builder).getInputStream();
} else if (connection instanceof HttpURLConnection) {
return new InstrHttpURLConnection((HttpURLConnection) connection, timer, builder).getInputStream();
}
return connection.getInputStream();
} catch (IOException e) {
builder.setRequestStartTimeMicros(startTime);
builder.setTimeToResponseCompletedMicros(timer.getDurationMicros());
builder.setUrl(wrapper.toString());
NetworkRequestMetricBuilderUtil.logError(builder);
throw e;
}
}
use of com.google.firebase.perf.metrics.NetworkRequestMetricBuilder in project firebase-android-sdk by firebase.
the class FirebasePerfUrlConnection method getContent.
/**
* Send network request metric for UrlConnection.getContent(classes)
*
* @return the object fetched
* @throws IOException if there is a problem with opening the connection or using the connection
* to get the content
*/
static Object getContent(final URLWrapper wrapper, @SuppressWarnings("rawtypes") final Class[] types, TransportManager transportManager, Timer timer) throws IOException {
timer.reset();
long startTime = timer.getMicros();
NetworkRequestMetricBuilder builder = NetworkRequestMetricBuilder.builder(transportManager);
try {
URLConnection connection = wrapper.openConnection();
if (connection instanceof HttpsURLConnection) {
return new InstrHttpsURLConnection((HttpsURLConnection) connection, timer, builder).getContent(types);
} else if (connection instanceof HttpURLConnection) {
return new InstrHttpURLConnection((HttpURLConnection) connection, timer, builder).getContent(types);
}
return connection.getContent(types);
} catch (IOException e) {
builder.setRequestStartTimeMicros(startTime);
builder.setTimeToResponseCompletedMicros(timer.getDurationMicros());
builder.setUrl(wrapper.toString());
NetworkRequestMetricBuilderUtil.logError(builder);
throw e;
}
}
Aggregations