This example shows how to use the X-Ray plugin for httpx, in racing mode, in an executable running on a host.
This example provides an executable program demonstrating how the
httpx plugin (httpxxray
) produces X-Ray
traces when run on an ordinary host computer, and parallel request racing is
enabled.
When you run the example program, it starts a "local" HTTPS server executes a
simple GET request to the server using an httpx.Client
with the X-Ray plugin
installed. The first 4 attempts cause various errors necessitating retry; the
fifth attempt succeeds. The final X-Ray trace thus shows one execution with 5
attempts as shown below.
Because racing is enabled, the third request attempt starts while the second request attempt is still blocked waiting on the request headers; similarly, the fifth request attempt starts while the fourth attempt is still reading the response body.
- Install and start the X-Ray daemon.
- Build the example program.
- Run the example program.
- View the generated trace in the AWS X-Ray console.
This example requires that you have the AWS X-Ray daemon installed and running on the host on default port (2000).
For instructions on installing and running the daemon, please see the official AWS X-Ray daemon documentation.
Build the example program using the below commands:
$ go get github.com/gogama/aws-xray-httpx/example/racing
$ go install github.com/gogama/aws-xray-httpx/example/racing
The above will download the example source code and build an executable program
named racing
(or racing.exe
on Windows) in the directory GOBIN
. (If your
$ go env GOBIN
is empty then it will be built to the directory
$(go env GOPATH)/bin
.)
Run the example program!
It should print output similar to:
2021-03-31T15:46:13Z [INFO] X-Ray proxy using address : 127.0.0.1:2000
2021-03-31T15:46:13Z [INFO] Successfully fetched sampling rules
Status: 200
Body: Success!
2021-03-31T15:46:13Z [INFO] Emitter using address: 127.0.0.1:2000
In the AWS console, navigate to AWS X-Ray.
Select Traces and view the most recent trace.