This example shows how to use the X-Ray plugin for httpx 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.
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.
- 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/normal
$ go install github.com/gogama/aws-xray-httpx/example/normal
The above will download the example source code and build an executable program
named normal
(or normal.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.