TL;DR: A simple project to showcase Selenium 4's Tracing capability using OpenTelemetry APIs(Jaeger) with Selenium Grid.
It is a measure of how well internal states of a system can be inferred from knowledge of its external outputs. It helps bring visibility into systems. – Wikipedia
Tracing is one of the important pillars for measuring observability along with logs and metrics. It's a way of thinking about the system, a way of being able to ask the system questions, that you need the answer to when you didn't know the questions beforehand. On the other hand, alerting is a way of asking questions when you do know the question beforehand.
Distributed Tracing can be quite helpful in answering questions for your distributed system like,
- Root cause analysis
- Performance optimisation
- dependency analysis of services
It has number of new exciting features and one such is a cleaner code for Selenium Grid along with support for distributed tracing via OpenTelemetry APIs. This is pretty exciting and important feature for the admins and devops engineers to trace the flow of control through the Grid for each and every command.
Distributed tracing has two parts:
-
Code instrumentation: Adding instrumentation code in your application to produce traces. The major instrumentation parts are done neatly by the developers of Selenium project, which leaves us to consume it by using Selenium Grid start-up command along with Jaeger.
-
Collection of data and providing meaning over it, Jaeger has a UI which allows us to view traces visually well.
Steps to start tracing your tests,
-
Start Jaeger via docker(as its easy)
-
Instrument your Selenium Grid start-up command with Jaeger tracing as in start-grid-distributed.sh and start-grid-standalone.sh for standalone mode.
-
Now execute your tests tests, and navigate to
http://localhost:16686/
to view the outputs.
Assuming you have java and docker running on your machine,
- Install Jaeger via docker
- Selenium-server.jar refers to the latest alpha version of selenium releases (Tested with Alpha 5)
- Download from here: https://github.com/SeleniumHQ/selenium/releases/latest
- Put jar in the repo root directory
- Rename to
selenium-server.jar
The simplest way to start the all-in-one is to use the pre-built image published to DockerHub (a single command line).
$ docker run --rm -it --name jaeger \
-p 16686:16686 \
-p 14250:14250 \
jaegertracing/all-in-one:1.17
You can then navigate to http://localhost:16686 to access the Jaeger UI.
The startup scripts use maven to download opentelemetry-exporter-otlp
and transitive dependencies to ./target/dependency
.
This folder is added to Selenium Server's classpath. When started this way the selenium server will inform you that it has found a tracer on stdout.
Refer start-grid-distributed.sh if you want to start Grid in distributed mode.
curl http://localhost:4444/status
to check if your grid deployment is ready
./mvnw test
This will execute the SeleniumGridTest Class. Navigate to http://localhost:16686/ to view the resulting traces in Jaeger.
Under services look up for selenium-router
and notice actions for each call made by your tests. An example below
References:
A special thanks to ever helpful Simon Stewart for being patience in answering my dumb questions.