Compare traces of two build records
In this step, you will learn how to generate and compare OpenTelemetry traces from two different Docker build records. Comparing traces can be useful for identifying performance differences between builds, especially after making changes to your Dockerfile
or build environment.
First, ensure you are in the ~/project
directory.
cd ~/project
We already have a trace.json
file from the previous build. Let's rename it to trace1.json
to keep it.
mv trace.json trace1.json
Now, let's make a small change to our Dockerfile
and build the image again, generating a second trace file. We will add a simple LABEL
instruction to the Dockerfile
.
Open the Dockerfile
for editing.
nano Dockerfile
Add the following line after the CMD
instruction:
LABEL version="1.0"
The updated Dockerfile
should look like this:
FROM ubuntu:latest
RUN apt-get update && apt-get install -y --no-install-recommends fortune-mod
CMD ["/usr/games/fortune"]
LABEL version="1.0"
Save the file and exit nano
.
Now, build the image again, generating a new trace file named trace2.json
.
BUILDKIT_TRACE=trace2.json docker build --progress=plain -t my-fortune-image .
After the build completes, you will have two trace files: trace1.json
and trace2.json
.
While directly comparing the raw JSON files can be challenging, these files are designed to be consumed by OpenTelemetry tracing backends. In a real-world scenario, you would import both trace1.json
and trace2.json
into a tracing visualization tool (like Jaeger). This tool would allow you to visually compare the timelines and spans of the two builds, making it easy to spot differences in execution time and identify which steps were affected by your changes.
For example, if you were to view these traces in Jaeger, you would see the individual steps of the Docker build (like FROM
, RUN
, CMD
, LABEL
) as spans. You could then compare the duration of these spans between the two traces to see if adding the LABEL
instruction had any measurable impact on the build time.
Since we don't have a tracing backend set up in this lab, we will simply verify that both trace files exist.