docker-selenium
docker-selenium copied to clipboard
[🚀 Feature]: how to config use Tracing with OpenTelemetry and Jaeger in Selenium Grid 4 with docker?
Feature and motivation
how to config use Tracing with OpenTelemetry and Jaeger in Selenium Grid 4 with docker?
Usage example
how to config use Tracing with OpenTelemetry and Jaeger in Selenium Grid 4 with docker?
ditto.. I can't get this working either. any clue?
I did some research into this and got it working in my setup. There may be a better way to do this more generically, so I'm offering my findings for consideration rather than as a PR.
I ended up changing the start-selenium-grid-hub.sh and similar scripts (e.g., start-selenium-node.sh) in other Docker images to add support for the --ext
parameter to be set before the command. In the following snippet, the ${EXT_OPT}
variable has been added before the hub
command.
java ${JAVA_OPTS:-$SE_JAVA_OPTS} -jar /opt/selenium/selenium-server.jar \
${EXT_OPT} \
hub \
--session-request-timeout ${SE_SESSION_REQUEST_TIMEOUT} \
--session-retry-interval ${SE_SESSION_RETRY_INTERVAL} \
--relax-checks ${SE_RELAX_CHECKS} \
--bind-host ${SE_BIND_HOST} \
${HOST_CONFIG} \
${PORT_CONFIG} \
${SE_OPTS}
In my local version of the images, I also added this code above the call to java. I found it more convenient to generate the classpath data to a file in the Dockerfile, then use the content of that file here instead of trying to set the environment variable in the Dockerfile. There might be a cleaner way to do this part.
if [ ! -z "$SE_EXT_OPT" ]; then
EXT_OPT="--ext $(cat ${SE_EXT_OPT})"
echo "Using Selenium EXT option: ${EXT_OPT})"
fi
Once the new --ext
option is available in the script, the jar files are needed in the image to support Jaeger and OpenTelemetry. I extended the existing Dockerfiles using the instructions from running java -jar selenium-server.jar info tracing
. Interestingly, I found that I had to use newer versions of the dependencies in order for it to work than the ones listed in the info output.
FROM selenium/hub:4.4.0-20220831
RUN sudo curl --fail --location -o /usr/local/bin/coursier https://github.com/coursier/launchers/raw/master/coursier \
&& sudo chmod +x /usr/local/bin/coursier \
&& coursier fetch -p \
io.opentelemetry:opentelemetry-exporter-jaeger:1.18.0 \
io.grpc:grpc-netty:1.49.0 >/opt/selenium/jaeger.classpath
COPY start-selenium-grid-hub.sh /opt/bin/
Finally, when deploying using the helm charts, I overrode the image and set the extra environment variables like so.
---
hub:
imageName: custom-selenium/hub-with-jaeger
extraEnvironmentVariables:
- name: SE_JAVA_OPTS
value: "-Dotel.traces.exporter=jaeger -Dotel.exporter.jaeger.endpoint=http://jaeger-collector:14250 -Dotel.resource.attributes=service.name=selenium-hub"
- name: SE_EXT_OPT
value: /opt/selenium/jaeger.classpath
chromeNode:
imageName: custom-selenium/node-chrome-with-jaeger
extraEnvironmentVariables:
- name: SE_JAVA_OPTS
value: "-Dotel.traces.exporter=jaeger -Dotel.exporter.jaeger.endpoint=http://jaeger-collector:14250 -Dotel.resource.attributes=service.name=selenium-node-chrome"
- name: SE_EXT_OPT
value: /opt/selenium/jaeger.classpath
The above configurations work when Jaeger is deployed to the same namespace. Change the configs if you do something different there.