How to use newSpanAsChildOf method of org.openqa.selenium.remote.tracing.HttpTracing class

Best Selenium code snippet using org.openqa.selenium.remote.tracing.HttpTracing.newSpanAsChildOf

Source:SpanWrappedHttpHandler.java Github

copy

Full Screen

...25import java.util.UUID;26import java.util.function.Function;27import java.util.logging.Level;28import java.util.logging.Logger;29import static org.openqa.selenium.remote.tracing.HttpTracing.newSpanAsChildOf;30import static org.openqa.selenium.remote.tracing.Tags.EXCEPTION;31import static org.openqa.selenium.remote.tracing.Tags.HTTP_REQUEST_EVENT;32import static org.openqa.selenium.remote.tracing.Tags.HTTP_RESPONSE_EVENT;33import static org.openqa.selenium.remote.tracing.Tags.HTTP_REQUEST;34import static org.openqa.selenium.remote.tracing.Tags.HTTP_RESPONSE;35import static org.openqa.selenium.remote.tracing.Tags.KIND;36public class SpanWrappedHttpHandler implements HttpHandler {37 private static final Logger LOG = Logger.getLogger(SpanWrappedHttpHandler.class.getName());38 private final Tracer tracer;39 private final Function<HttpRequest, String> namer;40 private final HttpHandler delegate;41 public SpanWrappedHttpHandler(Tracer tracer, Function<HttpRequest, String> namer, HttpHandler delegate) {42 this.tracer = Require.nonNull("Tracer", tracer);43 this.namer = Require.nonNull("Naming function", namer);44 this.delegate = Require.nonNull("Actual handler", delegate);45 }46 @Override47 public HttpResponse execute(HttpRequest req) throws UncheckedIOException {48 // If there is already a span attached to this request, then do nothing.49 Object possibleSpan = req.getAttribute("selenium.tracing.span");50 Map<String, EventAttributeValue> attributeMap = new HashMap<>();51 attributeMap.put(AttributeKey.HTTP_HANDLER_CLASS.getKey(),52 EventAttribute.setValue(delegate.getClass().getName()));53 if (possibleSpan instanceof Span) {54 return delegate.execute(req);55 }56 String name = Require.state("Operation name", namer.apply(req)).nonNull("must be set for %s", req);57 TraceContext before = tracer.getCurrentContext();58 Span span = newSpanAsChildOf(tracer, req, name);59 try {60 TraceContext after = tracer.getCurrentContext();61 span.setAttribute("random.key", UUID.randomUUID().toString());62 req.setAttribute("selenium.tracing.span", span);63 if (!(after.getClass().getName().equals("org.openqa.selenium.remote.tracing.empty.NullContext"))) {64 LOG.fine(String.format("Wrapping request. Before %s and after %s", before, after));65 }66 KIND.accept(span, Span.Kind.SERVER);67 HTTP_REQUEST.accept(span, req);68 HTTP_REQUEST_EVENT.accept(attributeMap, req);69 HttpTracing.inject(tracer, span, req);70 HttpResponse res = delegate.execute(req);71 HTTP_RESPONSE.accept(span, res);72 HTTP_RESPONSE_EVENT.accept(attributeMap, res);...

Full Screen

Full Screen

Source:ReverseProxyHandler.java Github

copy

Full Screen

...29import java.io.UncheckedIOException;30import java.util.HashMap;31import java.util.Map;32import java.util.logging.Logger;33import static org.openqa.selenium.remote.tracing.HttpTracing.newSpanAsChildOf;34import static org.openqa.selenium.remote.tracing.Tags.HTTP_REQUEST;35import static org.openqa.selenium.remote.tracing.Tags.HTTP_REQUEST_EVENT;36import static org.openqa.selenium.remote.tracing.Tags.HTTP_RESPONSE;37import static org.openqa.selenium.remote.tracing.Tags.HTTP_RESPONSE_EVENT;38import static org.openqa.selenium.remote.tracing.Tags.KIND;39public class ReverseProxyHandler implements HttpHandler {40 private static final Logger LOG = Logger.getLogger(ReverseProxyHandler.class.getName());41 private static final ImmutableSet<String> IGNORED_REQ_HEADERS = ImmutableSet.<String>builder()42 .add("connection")43 .add("keep-alive")44 .add("proxy-authorization")45 .add("proxy-authenticate")46 .add("proxy-connection")47 .add("te")48 .add("trailer")49 .add("transfer-encoding")50 .add("upgrade")51 .build();52 private final Tracer tracer;53 private final HttpClient upstream;54 public ReverseProxyHandler(Tracer tracer, HttpClient httpClient) {55 this.tracer = Require.nonNull("Tracer", tracer);56 this.upstream = Require.nonNull("HTTP client", httpClient);57 }58 @Override59 public HttpResponse execute(HttpRequest req) throws UncheckedIOException {60 try (Span span = newSpanAsChildOf(tracer, req, "reverse_proxy")) {61 HTTP_REQUEST.accept(span, req);62 HttpRequest toUpstream = new HttpRequest(req.getMethod(), req.getUri());63 for (String name : req.getQueryParameterNames()) {64 for (String value : req.getQueryParameters(name)) {65 toUpstream.addQueryParameter(name, value);66 }67 }68 for (String name : req.getHeaderNames()) {69 if (IGNORED_REQ_HEADERS.contains(name.toLowerCase())) {70 continue;71 }72 for (String value : req.getHeaders(name)) {73 toUpstream.addHeader(name, value);74 }...

Full Screen

Full Screen

Source:TracedHttpClient.java Github

copy

Full Screen

...17package org.openqa.selenium.remote.tracing;18import static org.openqa.selenium.remote.tracing.Tags.HTTP_REQUEST;19import static org.openqa.selenium.remote.tracing.Tags.HTTP_REQUEST_EVENT;20import static org.openqa.selenium.remote.tracing.Tags.HTTP_RESPONSE;21import static org.openqa.selenium.remote.tracing.HttpTracing.newSpanAsChildOf;22import static org.openqa.selenium.remote.tracing.Tags.HTTP_RESPONSE_EVENT;23import static org.openqa.selenium.remote.tracing.Tags.KIND;24import org.openqa.selenium.internal.Require;25import org.openqa.selenium.remote.http.ClientConfig;26import org.openqa.selenium.remote.http.HttpClient;27import org.openqa.selenium.remote.http.HttpRequest;28import org.openqa.selenium.remote.http.HttpResponse;29import org.openqa.selenium.remote.http.WebSocket;30import java.net.URL;31import java.util.HashMap;32import java.util.Map;33public class TracedHttpClient implements HttpClient {34 private final Tracer tracer;35 private final HttpClient delegate;36 private TracedHttpClient(Tracer tracer, HttpClient delegate) {37 this.tracer = Require.nonNull("Tracer", tracer);38 this.delegate = Require.nonNull("Actual handler", delegate);39 }40 @Override41 public WebSocket openSocket(HttpRequest request, WebSocket.Listener listener) {42 return delegate.openSocket(request, listener);43 }44 @Override45 public HttpResponse execute(HttpRequest req) {46 try (Span span = newSpanAsChildOf(tracer, req, "httpclient.execute")) {47 KIND.accept(span, Span.Kind.CLIENT);48 HTTP_REQUEST.accept(span, req);49 tracer.getPropagator().inject(span, req, (r, key, value) -> r.setHeader(key, value));50 HttpResponse response = delegate.execute(req);51 HTTP_RESPONSE.accept(span, response);52 return response;53 }54 }55 public static class Factory implements HttpClient.Factory {56 private final Tracer tracer;57 private final HttpClient.Factory delegate;58 public Factory(Tracer tracer, HttpClient.Factory delegate) {59 this.tracer = Require.nonNull("Tracer", tracer);60 this.delegate = Require.nonNull("Actual handler", delegate);...

Full Screen

Full Screen

Source:AddBackToSessionQueue.java Github

copy

Full Screen

...15// specific language governing permissions and limitations16// under the License.17package org.openqa.selenium.grid.sessionqueue;18import static org.openqa.selenium.remote.http.Contents.asJson;19import static org.openqa.selenium.remote.tracing.HttpTracing.newSpanAsChildOf;20import static org.openqa.selenium.remote.tracing.Tags.HTTP_REQUEST;21import static org.openqa.selenium.remote.tracing.Tags.HTTP_RESPONSE;22import com.google.common.collect.ImmutableMap;23import org.openqa.selenium.grid.data.RequestId;24import org.openqa.selenium.internal.Require;25import org.openqa.selenium.remote.http.HttpHandler;26import org.openqa.selenium.remote.http.HttpRequest;27import org.openqa.selenium.remote.http.HttpResponse;28import org.openqa.selenium.remote.tracing.AttributeKey;29import org.openqa.selenium.remote.tracing.Span;30import org.openqa.selenium.remote.tracing.Tracer;31import java.util.UUID;32class AddBackToSessionQueue implements HttpHandler {33 private final Tracer tracer;34 private final NewSessionQueuer newSessionQueuer;35 private final RequestId id;36 AddBackToSessionQueue(Tracer tracer, NewSessionQueuer newSessionQueuer, RequestId id) {37 this.tracer = Require.nonNull("Tracer", tracer);38 this.newSessionQueuer = Require.nonNull("New Session Queuer", newSessionQueuer);39 this.id = id;40 }41 @Override42 public HttpResponse execute(HttpRequest req) {43 try (Span span = newSpanAsChildOf(tracer, req, "sessionqueuer.retry")) {44 HTTP_REQUEST.accept(span, req);45 span.setAttribute(AttributeKey.REQUEST_ID.getKey(), id.toString());46 boolean value = newSessionQueuer.retryAddToQueue(req, id);47 span.setAttribute("request.retry", value);48 HttpResponse response = new HttpResponse().setContent(49 asJson(ImmutableMap.of("value", value)));50 HTTP_RESPONSE.accept(span, response);51 return response;52 }53 }54}...

Full Screen

Full Screen

Source:RemoveFromSessionQueue.java Github

copy

Full Screen

...15// specific language governing permissions and limitations16// under the License.17package org.openqa.selenium.grid.sessionqueue;18import static java.net.HttpURLConnection.HTTP_NO_CONTENT;19import static org.openqa.selenium.remote.tracing.HttpTracing.newSpanAsChildOf;20import static org.openqa.selenium.remote.tracing.Tags.HTTP_REQUEST;21import static org.openqa.selenium.remote.tracing.Tags.HTTP_RESPONSE;22import org.openqa.selenium.internal.Require;23import org.openqa.selenium.remote.http.HttpHandler;24import org.openqa.selenium.remote.http.HttpRequest;25import org.openqa.selenium.remote.http.HttpResponse;26import org.openqa.selenium.remote.tracing.Span;27import org.openqa.selenium.remote.tracing.Tracer;28import java.util.Optional;29public class RemoveFromSessionQueue implements HttpHandler {30 private final Tracer tracer;31 private final NewSessionQueuer newSessionQueuer;32 RemoveFromSessionQueue(Tracer tracer, NewSessionQueuer newSessionQueuer) {33 this.tracer = Require.nonNull("Tracer", tracer);34 this.newSessionQueuer = Require.nonNull("New Session Queuer", newSessionQueuer);35 }36 @Override37 public HttpResponse execute(HttpRequest req) {38 try (Span span = newSpanAsChildOf(tracer, req, "sessionqueuer.remove")) {39 HTTP_REQUEST.accept(span, req);40 Optional<HttpRequest> sessionRequest = newSessionQueuer.remove();41 HttpResponse response = new HttpResponse();42 if (sessionRequest.isPresent()) {43 HttpRequest request = sessionRequest.get();44 response.setContent(request.getContent());45 response.setHeader(NewSessionQueue.SESSIONREQUEST_TIMESTAMP_HEADER,46 request.getHeader(NewSessionQueue.SESSIONREQUEST_TIMESTAMP_HEADER));47 } else {48 response.setStatus(HTTP_NO_CONTENT);49 }50 HTTP_RESPONSE.accept(span, response);51 return response;52 }...

Full Screen

Full Screen

Source:GetSessionQueue.java Github

copy

Full Screen

...22import org.openqa.selenium.remote.tracing.Span;23import org.openqa.selenium.remote.tracing.Tracer;24import java.util.Collections;25import static org.openqa.selenium.remote.http.Contents.asJson;26import static org.openqa.selenium.remote.tracing.HttpTracing.newSpanAsChildOf;27import static org.openqa.selenium.remote.tracing.Tags.HTTP_REQUEST;28import static org.openqa.selenium.remote.tracing.Tags.HTTP_RESPONSE;29class GetSessionQueue implements HttpHandler {30 private final Tracer tracer;31 private final NewSessionQueue newSessionQueue;32 GetSessionQueue(Tracer tracer, NewSessionQueue newSessionQueue) {33 this.tracer = Require.nonNull("Tracer", tracer);34 this.newSessionQueue = Require.nonNull("New Session Queue", newSessionQueue);35 }36 @Override37 public HttpResponse execute(HttpRequest req) {38 try (Span span = newSpanAsChildOf(tracer, req, "sessionqueue.contents")) {39 HTTP_REQUEST.accept(span, req);40 HttpResponse response = new HttpResponse()41 .setContent(asJson(Collections.singletonMap(42 "value", newSessionQueue.getQueueContents())));43 HTTP_RESPONSE.accept(span, response);44 return response;45 }46 }47}...

Full Screen

Full Screen

Source:RemoveFromSession.java Github

copy

Full Screen

...23import org.openqa.selenium.remote.tracing.Span;24import org.openqa.selenium.remote.tracing.Tracer;25import static org.openqa.selenium.remote.RemoteTags.SESSION_ID;26import static org.openqa.selenium.remote.tracing.Tags.HTTP_REQUEST;27import static org.openqa.selenium.remote.tracing.HttpTracing.newSpanAsChildOf;28class RemoveFromSession implements HttpHandler {29 private final Tracer tracer;30 private final SessionMap sessions;31 private final SessionId id;32 RemoveFromSession(Tracer tracer, SessionMap sessions, SessionId id) {33 this.tracer = Require.nonNull("Tracer", tracer);34 this.sessions = Require.nonNull("Session map", sessions);35 this.id = Require.nonNull("Session id", id);36 }37 @Override38 public HttpResponse execute(HttpRequest req) {39 try (Span span = newSpanAsChildOf(tracer, req, "sessions.remove_session")) {40 HTTP_REQUEST.accept(span, req);41 SESSION_ID.accept(span, id);42 sessions.remove(id);43 return new HttpResponse();44 }45 }46}...

Full Screen

Full Screen

Source:AddToSessionQueue.java Github

copy

Full Screen

...14// KIND, either express or implied. See the License for the15// specific language governing permissions and limitations16// under the License.17package org.openqa.selenium.grid.sessionqueue;18import static org.openqa.selenium.remote.tracing.HttpTracing.newSpanAsChildOf;19import static org.openqa.selenium.remote.tracing.Tags.HTTP_REQUEST;20import static org.openqa.selenium.remote.tracing.Tags.HTTP_RESPONSE;21import org.openqa.selenium.internal.Require;22import org.openqa.selenium.remote.http.HttpHandler;23import org.openqa.selenium.remote.http.HttpRequest;24import org.openqa.selenium.remote.http.HttpResponse;25import org.openqa.selenium.remote.tracing.Span;26import org.openqa.selenium.remote.tracing.Tracer;27class AddToSessionQueue implements HttpHandler {28 private final Tracer tracer;29 private final NewSessionQueuer newSessionQueuer;30 AddToSessionQueue(Tracer tracer, NewSessionQueuer newSessionQueuer) {31 this.tracer = Require.nonNull("Tracer", tracer);32 this.newSessionQueuer = Require.nonNull("New Session Queuer", newSessionQueuer);33 }34 @Override35 public HttpResponse execute(HttpRequest req) {36 try (Span span = newSpanAsChildOf(tracer, req, "sessionqueuer.add")) {37 HTTP_REQUEST.accept(span, req);38 HttpResponse response = newSessionQueuer.addToQueue(req);39 HTTP_RESPONSE.accept(span, response);40 return response;41 }42 }43}...

Full Screen

Full Screen

newSpanAsChildOf

Using AI Code Generation

copy

Full Screen

1import org.openqa.selenium.remote.tracing.HttpTracing;2import org.openqa.selenium.remote.tracing.Tracer;3import org.openqa.selenium.remote.tracing.Span;4import org.openqa.selenium.remote.tracing.Span.Kind;5public class TracingTest {6 public static void main(String[] args) {7 Tracer tracer = HttpTracing.newTracer();8 Span span = tracer.getCurrentContext().createSpan("testSpan", Kind.CLIENT);9 Span span2 = tracer.newSpanAsChildOf("testSpan2", span);10 }11}

Full Screen

Full Screen

newSpanAsChildOf

Using AI Code Generation

copy

Full Screen

1import org.openqa.selenium.remote.tracing.HttpTracing;2import org.openqa.selenium.remote.tracing.Span;3import org.openqa.selenium.remote.tracing.Tracer;4public class NewSpanAsChildOfExample {5 public static void main(String[] args) {6 Span span = tracer.getCurrentContext().createSpan("span1");7 Span newSpan = tracer.newSpanAsChildOf(span, "span2");8 newSpan.finish();9 span.finish();10 }11}

Full Screen

Full Screen

newSpanAsChildOf

Using AI Code Generation

copy

Full Screen

1span = httpTracing.newSpanAsChildOf("newSpanAsChildOf", span);2span.finish();3span = httpTracing.newSpanAsChildOf("newSpanAsChildOf", span);4span.finish();5span = httpTracing.newSpan("newSpan");6span.finish();7span = httpTracing.newSpanAsChildOf("newSpanAsChildOf", span);8span.finish();9span = httpTracing.newSpan("newSpan");10span.finish();11span = httpTracing.newSpanAsChildOf("newSpanAsChildOf", span);12span.finish();13span = httpTracing.newSpan("newSpan");14span.finish();15span = httpTracing.newSpanAsChildOf("newSpanAsChildOf", span);16span.finish();17span = httpTracing.newSpan("newSpan");18span.finish();

Full Screen

Full Screen

Selenium 4 Tutorial:

LambdaTest’s Selenium 4 tutorial is covering every aspects of Selenium 4 testing with examples and best practices. Here you will learn basics, such as how to upgrade from Selenium 3 to Selenium 4, to some advanced concepts, such as Relative locators and Selenium Grid 4 for Distributed testing. Also will learn new features of Selenium 4, such as capturing screenshots of specific elements, opening a new tab or window on the browser, and new protocol adoptions.

Chapters:

  1. Upgrading From Selenium 3 To Selenium 4?: In this chapter, learn in detail how to update Selenium 3 to Selenium 4 for Java binding. Also, learn how to upgrade while using different build tools such as Maven or Gradle and get comprehensive guidance for upgrading Selenium.

  2. What’s New In Selenium 4 & What’s Being Deprecated? : Get all information about new implementations in Selenium 4, such as W3S protocol adaption, Optimized Selenium Grid, and Enhanced Selenium IDE. Also, learn what is deprecated for Selenium 4, such as DesiredCapabilites and FindsBy methods, etc.

  3. Selenium 4 With Python: Selenium supports all major languages, such as Python, C#, Ruby, and JavaScript. In this chapter, learn how to install Selenium 4 for Python and the features of Python in Selenium 4, such as Relative locators, Browser manipulation, and Chrom DevTool protocol.

  4. Selenium 4 Is Now W3C Compliant: JSON Wireframe protocol is retiring from Selenium 4, and they are adopting W3C protocol to learn in detail about the advantages and impact of these changes.

  5. How To Use Selenium 4 Relative Locator? : Selenium 4 came with new features such as Relative Locators that allow constructing locators with reference and easily located constructors nearby. Get to know its different use cases with examples.

  6. Selenium Grid 4 Tutorial For Distributed Testing: Selenium Grid 4 allows you to perform tests over different browsers, OS, and device combinations. It also enables parallel execution browser testing, reads up on various features of Selenium Grid 4 and how to download it, and runs a test on Selenium Grid 4 with best practices.

  7. Selenium Video Tutorials: Binge on video tutorials on Selenium by industry experts to get step-by-step direction from automating basic to complex test scenarios with Selenium.

Selenium 101 certifications:

LambdaTest also provides certification for Selenium testing to accelerate your career in Selenium automation testing.

Run Selenium automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Most used method in HttpTracing

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful