Skip to content
This repository was archived by the owner on Oct 3, 2023. It is now read-only.

Commit 6811634

Browse files
crdgonzalezcadraffensperger
authored andcommitted
User interaction example (#83)
1 parent 67ccdad commit 6811634

12 files changed

Lines changed: 15831 additions & 0 deletions

File tree

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
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).
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
This project was bootstrapped with [Create React App](https://github.com/facebook/create-react-app).
2+
3+
## Available Scripts
4+
5+
In the project directory, you can run:
6+
7+
### `npm start`
8+
9+
Runs the app in the development mode.<br>
10+
Open [http://localhost:3000](http://localhost:3000) to view it in the browser.
11+
12+
The page will reload if you make edits.<br>
13+
You will also see any lint errors in the console.
14+
15+
### `npm test`
16+
17+
Launches the test runner in the interactive watch mode.<br>
18+
See the section about [running tests](https://facebook.github.io/create-react-app/docs/running-tests) for more information.
19+
20+
### `npm run build`
21+
22+
Builds the app for production to the `build` folder.<br>
23+
It correctly bundles React in production mode and optimizes the build for the best performance.
24+
25+
The build is minified and the filenames include the hashes.<br>
26+
Your app is ready to be deployed!
27+
28+
See the section about [deployment](https://facebook.github.io/create-react-app/docs/deployment) for more information.

0 commit comments

Comments
 (0)