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

Commit 9f2c2a8

Browse files
crdgonzalezcadraffensperger
authored andcommitted
Update documentation (#152)
* Update documentation * Change * Fix docs
1 parent b5503f5 commit 9f2c2a8

File tree

23 files changed

+522
-113
lines changed

23 files changed

+522
-113
lines changed

README.md

Lines changed: 252 additions & 38 deletions
Large diffs are not rendered by default.

examples/initial_load/README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ exporters:
3232
Then in the same folder as your `config.yaml` run the agent with this command:
3333

3434
```bash
35-
go run github.com/census-instrumentation/opencensus-service/cmd/ocagent
35+
GO111MODULE=on go run github.com/census-instrumentation/opencensus-service/cmd/ocagent
3636
```
3737

3838
### Step 2: Run the local webpack server
@@ -105,7 +105,7 @@ following the
105105
[OpenCensus Agent](https://github.com/census-instrumentation/opencensus-service#opencensus-agent)
106106
docs.
107107

108-
### 5. Build the demo application container
108+
### 4. Build the demo application container
109109

110110
First build the OpenCensus Web scripts that will be deployed with the
111111
application:
@@ -123,7 +123,7 @@ docker build . -t gcr.io/$PROJECT_ID/oc-web-initial-load:latest
123123
gcloud docker -- push gcr.io/$PROJECT_ID/oc-web-initial-load:latest
124124
```
125125

126-
### 4. Deploy the demo application
126+
### 5. Deploy the demo application
127127

128128
Run the command `kubectl get svc oc-agent-service` to check if the
129129
`EXTERNAL-IP` column has been filled in. If it is still pending, then wait a bit

examples/user_interaction/README.md

Lines changed: 40 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,41 @@
11
# OpenCensus Web example server for user interaction tracing
22

33
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).
4+
and client side spans for the initial page load and user interactions to the
5+
[OpenCensus agent][opencensus-agent].
56

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.
7+
The main purpose of this example is to show the user interaction tracing.
8+
For that, a `React JS` client is instrumented with the npm `@opencensus/web-instrumentation-zone` package to
9+
start tracing the user interactions. Additionally, a `Node JS` server is instrumented with
10+
`@opencensus/nodejs` library to send spans by default to [Zipkin][zipkin]
11+
12+
The app has two buttons with the same click handler but one button has the `data-ocweb-id`
13+
attribute to show this naming aproach, and the other button has an `id` to show the CSS
14+
selector naming approach. When one button is clicked, a new interaction is started, it first tracks
15+
a `Promise` which will run a `setTimeout` of 1000 ms, once this is done, an HTTP
16+
request is sent to the server which sleeps for 2 seconds and then sends the response.
17+
Once the request has finished, another HTTP request is done to do some calculations in the server
18+
side, then the client will calculate PI to show a long span.
19+
After all of those tasks, the interaction finishes and is sent to the OC Agent.
20+
21+
Additionally, the client provides some route transitions to show the *Navigation* naming approach.
922

1023
## Running locally
1124

1225
### Step 1: Install and run the OpenCensus agent
1326

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).
27+
To run this example in local development mode, you will need to run the [OpenCensus agent][opencensus-agent].
1628

17-
First set your `GOPATH` environment variable and then install the agent by
18-
running:
29+
First set your `GOPATH` environment variable and then install the agent by running:
1930

2031
```bash
2132
go get -d github.com/census-instrumentation/opencensus-service
2233
```
2334

2435
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:
36+
[Configuration][opencensus-servie-config] instructions for the agent. You will need to have the
37+
`opencensus` receiver set up on the default port of `55678`, and you will need at least one exporter
38+
so you can see the traces that are generated. For example, your config file could look like this:
2639

2740
```yaml
2841
receivers:
@@ -36,12 +49,12 @@ exporters:
3649
Then in the same folder as your `config.yaml` run the agent with this command:
3750

3851
```bash
39-
go run github.com/census-instrumentation/opencensus-service/cmd/ocagent
52+
GO111MODULE=on go run github.com/census-instrumentation/opencensus-service/cmd/ocagent
4053
```
4154

4255
### Step 2: Run the client (React application)
4356

44-
Then within your the `client` folder install all dependencies and run locally the application.
57+
Then within the `client` folder install all dependencies and run locally the application.
4558

4659
```bash
4760
cd client/
@@ -51,19 +64,27 @@ npm start
5164

5265
That will start the react application on `localhost:3000`.
5366

54-
### Step 3: Run this example server
67+
### Step 3: Run the server
5568

56-
Now you can run this example server with the following commands from within your
69+
Now you can run the example server with the following commands from within your
5770
`opencensus-web` folder:
5871

5972
```bash
60-
cd examples/user_interaction/server/
73+
cd server/
6174
node server.js
6275
```
6376

6477
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).
78+
world page render. If you click on the button or navigate to another page
79+
in the browser developer tools network tab, you should see an XHR that writes
80+
trace spans to the OpenCensus agent.
81+
82+
Then go to the trace viewer for the exporter you set up and view the trace of your initial
83+
page load plus the different user interaction traces. Notice they will be named as
84+
*Trace user interaction*, *button#trace_interaction click* or *Navigation /second_page*
85+
for this example. Then, in every trace you will see several spans associated to the interaction.
86+
87+
88+
[opencensus-agent]: (https://github.com/census-instrumentation/opencensus-service)
89+
[zipkin]: (https://opencensus.io/codelabs/zipkin/)
90+
[opencensus-servie-config]: (https://github.com/census-instrumentation/opencensus-service#config)

examples/user_interaction/client/README.md

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,6 @@ Open [http://localhost:3000](http://localhost:3000) to view it in the browser.
1212
The page will reload if you make edits.<br>
1313
You will also see any lint errors in the console.
1414

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-
2015
### `npm run build`
2116

2217
Builds the app for production to the `build` folder.<br>

examples/user_interaction/client/package.json

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,7 @@
2020
},
2121
"scripts": {
2222
"start": "react-scripts start",
23-
"build": "react-scripts build",
24-
"test": "react-scripts test",
25-
"eject": "react-scripts eject"
23+
"build": "react-scripts build"
2624
},
2725
"eslintConfig": {
2826
"extends": "react-app"

examples/user_interaction/client/public/index.html

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,7 @@
66
<meta charset="utf-8" />
77
<meta name="viewport" content="width=device-width, initial-scale=1" />
88
<meta name="theme-color" content="#000000" />
9-
<!--
10-
manifest.json provides metadata used when your web app is installed on a
11-
user's mobile device or desktop. See https://developers.google.com/web/fundamentals/web-app-manifest/
12-
-->
9+
1310
<link rel="manifest" href="%PUBLIC_URL%/manifest.json" />
1411
<!-- Load bootstrap to see a resource load span -->
1512
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.1/css/bootstrap.min.css" rel="stylesheet"
@@ -32,6 +29,9 @@ <h1>OpenCensus Web User Interaction Tracing!</h1>
3229
naming approach.
3330
</p>
3431
<div id="root"></div>
32+
<script src="http://localhost:8080/tracing-all-with-zone.js"
33+
async>
34+
</script>
3535
</body>
3636

3737
</html>

examples/user_interaction/client/src/App.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,9 +108,11 @@ class App extends React.Component {
108108
<div>
109109
<p>This example makes some calculations like calculate Pi using the series from
110110
and calculate the amount of prime numbers in between 1 and 100000. These
111-
calculations are done using slow methods in order to measure the traces.</p>
111+
calculations are done using slow methods in order to show long spans.</p>
112112

113-
<button id='trace_interaction' data-ocweb-id='Trace user interaction' onClick={this.handleClick}>Trace user interaction</button>
113+
<button data-ocweb-id='Trace user interaction' onClick={this.handleClick}>Trace user interaction</button>
114+
<br></br><br></br>
115+
<button id='trace_interaction' onClick={this.handleClick}>Trace user interaction 2</button>
114116

115117
<p>The value of Pi is: <code>{this.state.pi.value}</code> and it took
116118
<code> {this.state.pi.time} ms </code> to compute this.</p>

examples/user_interaction/client/src/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ const routing = (
4141

4242
ReactDOM.render(routing, document.getElementById('root'));
4343

44-
window.ocAgent = 'http://localhost:55678';
44+
window.ocAgent = 'http://104.196.170.62';
4545
// For the purpose of this example, send trace header to all hosts.
4646
window.ocTraceHeaderHostRegex = /.*/;
4747
window.ocSampleRate = 1.0; // Sample at 100% for test only. Default is 1/10000.

examples/user_interaction/server/package-lock.json

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

examples/user_interaction/server/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
"@opencensus/exporter-zipkin": "^0.0.14",
2525
"@opencensus/nodejs": "^0.0.14",
2626
"@opencensus/propagation-tracecontext": "^0.0.14",
27+
"fs": "*",
2728
"http": "*",
2829
"sleep": "^6.1.0"
2930
},

0 commit comments

Comments
 (0)