|
| 1 | +# OpenCensus Web example server for user interaction tracing |
| 2 | + |
| 3 | +This example server renders a simple hello page and writes both the server-side |
| 4 | +and client side spans for the initial page load to the [OpenCensus agent](https://github.com/census-instrumentation/opencensus-service). |
| 5 | + |
| 6 | +Also, add a button in order to test user interactions, this button triggers network requests to the provided node server when it is clicked. |
| 7 | +These requests sleep the server for a while and calculate prime numbers until 100000. After this, the frontend calculates PI. |
| 8 | +The idea of these calls is to trace the click on the button and see calculations in server and client side. |
| 9 | + |
| 10 | +## Running locally |
| 11 | + |
| 12 | +### Step 1: Install and run the OpenCensus agent |
| 13 | + |
| 14 | +To run this example in local development mode, you will need to run the [OpenCensus |
| 15 | +agent](https://github.com/census-instrumentation/opencensus-service). |
| 16 | + |
| 17 | +First set your `GOPATH` environment variable and then install the agent by |
| 18 | +running: |
| 19 | + |
| 20 | +```bash |
| 21 | +go get -d github.com/census-instrumentation/opencensus-service |
| 22 | +``` |
| 23 | + |
| 24 | +Then create a `config.yaml` file following the |
| 25 | +[Configuration](https://github.com/census-instrumentation/opencensus-service#config) instructions for the agent. You will need to have the `opencensus` receiver set up on the default port of `55678`, and you will need at least one exporter so you can see the traces that are generated. For example, your config file could look like this: |
| 26 | + |
| 27 | +```yaml |
| 28 | +receivers: |
| 29 | + opencensus: |
| 30 | + address: "127.0.0.1:55678" |
| 31 | + cors_allowed_origins: |
| 32 | + - http://localhost:* |
| 33 | +exporters: |
| 34 | + # Pick and configure an exporter e.g. stackdriver, zipkin, aws-xray, honeycomb |
| 35 | +``` |
| 36 | +Then in the same folder as your `config.yaml` run the agent with this command: |
| 37 | + |
| 38 | +```bash |
| 39 | +go run github.com/census-instrumentation/opencensus-service/cmd/ocagent |
| 40 | +``` |
| 41 | + |
| 42 | +### Step 2: Run the client (React application) |
| 43 | + |
| 44 | +Then within your the `client` folder install all dependencies and run locally the application. |
| 45 | + |
| 46 | +```bash |
| 47 | +cd client/ |
| 48 | +npm install |
| 49 | +npm start |
| 50 | +``` |
| 51 | + |
| 52 | +That will start the react application on `localhost:3000`. |
| 53 | + |
| 54 | +### Step 3: Run this example server |
| 55 | + |
| 56 | +Now you can run this example server with the following commands from within your |
| 57 | +`opencensus-web` folder: |
| 58 | + |
| 59 | +```bash |
| 60 | +cd examples/user_interaction/server/ |
| 61 | +node server.js |
| 62 | +``` |
| 63 | + |
| 64 | +Now visit http://localhost:3000/ in your browser to see the hello |
| 65 | +world page render. If you look in the browser developer tools network tab, you |
| 66 | +should see an XHR that writes trace spans to the OpenCensus agent. Then go to |
| 67 | +the trace viewer for the exporter you set up and view the trace of your initial |
| 68 | +page load. It will be named `Nav./index.html` (or just `Nav./` if you left off |
| 69 | +the actual `index.html` part when you visited the URL). |
0 commit comments