Search in sources :

Example 1 with HttpResponse

use of com.android.volley.toolbox.HttpResponse in project splunk-otel-android by signalfx.

the class VolleyResponseAttributesExtractorTest method spanDecoration_noLinkingHeader.

@Test
public void spanDecoration_noLinkingHeader() {
    ServerTimingHeaderParser headerParser = mock(ServerTimingHeaderParser.class);
    when(headerParser.parse(null)).thenReturn(new String[0]);
    RequestWrapper fakeRequest = new RequestWrapper(mock(Request.class), Collections.emptyMap());
    HttpResponse response = new HttpResponse(200, Collections.emptyList(), "hello".getBytes());
    VolleyResponseAttributesExtractor attributesExtractor = new VolleyResponseAttributesExtractor(headerParser);
    AttributesBuilder attributesBuilder = Attributes.builder();
    attributesExtractor.onEnd(attributesBuilder, null, fakeRequest, response, null);
    attributesExtractor.onStart(attributesBuilder, null, fakeRequest);
    Attributes attributes = attributesBuilder.build();
    assertEquals("http", attributes.get(SplunkRum.COMPONENT_KEY));
    assertNull(attributes.get(SplunkRum.LINK_TRACE_ID_KEY));
    assertNull(attributes.get(SplunkRum.LINK_SPAN_ID_KEY));
}
Also used : Request(com.android.volley.Request) SemanticAttributes(io.opentelemetry.semconv.trace.attributes.SemanticAttributes) Attributes(io.opentelemetry.api.common.Attributes) HttpResponse(com.android.volley.toolbox.HttpResponse) AttributesBuilder(io.opentelemetry.api.common.AttributesBuilder) Test(org.junit.Test)

Example 2 with HttpResponse

use of com.android.volley.toolbox.HttpResponse in project Hentoid by avluis.

the class VolleyOkHttp3Stack method executeRequest.

@Override
public HttpResponse executeRequest(Request<?> request, Map<String, String> additionalHeaders) throws IOException, AuthFailureError {
    okhttp3.Request.Builder okHttpRequestBuilder = new okhttp3.Request.Builder();
    okHttpRequestBuilder.url(request.getUrl());
    Map<String, String> headers = request.getHeaders();
    for (Map.Entry<String, String> entry : headers.entrySet()) {
        String value = (null == entry.getValue()) ? "" : entry.getValue();
        okHttpRequestBuilder.addHeader(entry.getKey(), value);
    }
    for (Map.Entry<String, String> entry : additionalHeaders.entrySet()) {
        String value = (null == entry.getValue()) ? "" : entry.getValue();
        okHttpRequestBuilder.addHeader(entry.getKey(), value);
    }
    setConnectionParametersForRequest(okHttpRequestBuilder, request);
    okhttp3.Request okHttpRequest = okHttpRequestBuilder.build();
    Call okHttpCall = client.newCall(okHttpRequest);
    Response okHttpResponse = okHttpCall.execute();
    int code = okHttpResponse.code();
    ResponseBody body = okHttpResponse.body();
    InputStream content = body == null ? null : body.byteStream();
    int contentLength = body == null ? 0 : (int) body.contentLength();
    List<Header> responseHeaders = mapHeaders(okHttpResponse.headers());
    return new HttpResponse(code, responseHeaders, contentLength, content);
}
Also used : Call(okhttp3.Call) InputStream(java.io.InputStream) Request(com.android.volley.Request) HttpResponse(com.android.volley.toolbox.HttpResponse) ResponseBody(okhttp3.ResponseBody) HttpResponse(com.android.volley.toolbox.HttpResponse) Response(okhttp3.Response) Header(com.android.volley.Header) Map(java.util.Map)

Example 3 with HttpResponse

use of com.android.volley.toolbox.HttpResponse in project splunk-otel-android by signalfx.

the class TracingHurlStack method executeRequest.

@Override
public HttpResponse executeRequest(Request<?> request, Map<String, String> additionalHeaders) throws IOException, AuthFailureError {
    HttpResponse response = null;
    Throwable throwable = null;
    RequestWrapper requestWrapper = new RequestWrapper(request, additionalHeaders);
    currentRequestWrapper.set(requestWrapper);
    Context parentContext = Context.current();
    Context context = null;
    Scope scope = null;
    if (instrumenter.shouldStart(parentContext, requestWrapper)) {
        context = instrumenter.start(parentContext, requestWrapper);
        scope = context.makeCurrent();
    }
    try {
        response = super.executeRequest(request, requestWrapper.getAdditionalHeaders());
    } catch (Throwable t) {
        throwable = t;
        throw t;
    } finally {
        if (scope != null) {
            scope.close();
            instrumenter.end(context, requestWrapper, response, throwable);
        }
        currentRequestWrapper.remove();
    }
    return response;
}
Also used : Context(io.opentelemetry.context.Context) Scope(io.opentelemetry.context.Scope) HttpResponse(com.android.volley.toolbox.HttpResponse)

Example 4 with HttpResponse

use of com.android.volley.toolbox.HttpResponse in project splunk-otel-android by signalfx.

the class VolleyResponseAttributesExtractorTest method spanDecoration.

@Test
public void spanDecoration() {
    ServerTimingHeaderParser headerParser = mock(ServerTimingHeaderParser.class);
    when(headerParser.parse("headerValue")).thenReturn(new String[] { "9499195c502eb217c448a68bfe0f967c", "fe16eca542cd5d86" });
    List<Header> responseHeaders = Collections.singletonList(new Header("Server-Timing", "headerValue"));
    RequestWrapper fakeRequest = new RequestWrapper(mock(Request.class), Collections.emptyMap());
    HttpResponse response = new HttpResponse(200, responseHeaders, "hello".getBytes());
    VolleyResponseAttributesExtractor attributesExtractor = new VolleyResponseAttributesExtractor(headerParser);
    AttributesBuilder attributesBuilder = Attributes.builder();
    attributesExtractor.onStart(attributesBuilder, null, fakeRequest);
    attributesExtractor.onEnd(attributesBuilder, null, fakeRequest, response, null);
    Attributes attributes = attributesBuilder.build();
    assertEquals("http", attributes.get(SplunkRum.COMPONENT_KEY));
    assertEquals("9499195c502eb217c448a68bfe0f967c", attributes.get(SplunkRum.LINK_TRACE_ID_KEY));
    assertEquals("fe16eca542cd5d86", attributes.get(SplunkRum.LINK_SPAN_ID_KEY));
}
Also used : Header(com.android.volley.Header) Request(com.android.volley.Request) SemanticAttributes(io.opentelemetry.semconv.trace.attributes.SemanticAttributes) Attributes(io.opentelemetry.api.common.Attributes) HttpResponse(com.android.volley.toolbox.HttpResponse) AttributesBuilder(io.opentelemetry.api.common.AttributesBuilder) Test(org.junit.Test)

Aggregations

HttpResponse (com.android.volley.toolbox.HttpResponse)4 Request (com.android.volley.Request)3 Header (com.android.volley.Header)2 Attributes (io.opentelemetry.api.common.Attributes)2 AttributesBuilder (io.opentelemetry.api.common.AttributesBuilder)2 SemanticAttributes (io.opentelemetry.semconv.trace.attributes.SemanticAttributes)2 Test (org.junit.Test)2 Context (io.opentelemetry.context.Context)1 Scope (io.opentelemetry.context.Scope)1 InputStream (java.io.InputStream)1 Map (java.util.Map)1 Call (okhttp3.Call)1 Response (okhttp3.Response)1 ResponseBody (okhttp3.ResponseBody)1