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

Commit d9515fd

Browse files
crdgonzalezcadraffensperger
authored andcommitted
Update documentation with new version and small fix on interaction tracker (#158)
1 parent d55678e commit d9515fd

File tree

5 files changed

+108
-75
lines changed

5 files changed

+108
-75
lines changed

README.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@ trace sample rate via an `ocSampleRate` global variable as well.
215215
// By default this is set to sample 1/10000 requests.
216216
ocSampleRate = 1.0;
217217
</script>
218-
<script src="https://unpkg.com/@opencensus/web-scripts@0.0.3/dist/initial-load-all.js"
218+
<script src="https://unpkg.com/@opencensus/web-scripts@0.0.4/dist/initial-load-all.js"
219219
integrity="sha384-VPY9XX7tiXeLekDPFXkfO2AqNpLTCNOzfXxVghzoVP05PXrG+wtHOW2kOP2ggO9o"
220220
async crossorigin="anonymous">
221221
</script>
@@ -248,7 +248,7 @@ trace sample rate via an `ocSampleRate` global variable as well.
248248
(e.g. React, etc.):
249249
```html
250250
...
251-
<script src="https://unpkg.com/@opencensus/web-scripts@0.0.3/dist/tracing-all-with-zone.js"
251+
<script src="https://unpkg.com/@opencensus/web-scripts@0.0.4/dist/tracing-all-with-zone.js"
252252
integrity="sha384-VPY9XX7tiXeLekDPFXkfO2AqNpLTCNOzfXxVghzoVP05PXrG+wtHOW2kOP2ggO9o"
253253
async crossorigin="anonymous">
254254
</script>
@@ -258,7 +258,7 @@ trace sample rate via an `ocSampleRate` global variable as well.
258258
- If your application uses the `Zone.js` library, the case for `Angular` apps:
259259
```html
260260
...
261-
<script src="https://unpkg.com/@opencensus/web-scripts@0.0.3/dist/tracing-all-with-zone-peer-dep.js"
261+
<script src="https://unpkg.com/@opencensus/web-scripts@0.0.4/dist/tracing-all-with-zone-peer-dep.js"
262262
integrity="sha384-VPY9XX7tiXeLekDPFXkfO2AqNpLTCNOzfXxVghzoVP05PXrG+wtHOW2kOP2ggO9o"
263263
async crossorigin="anonymous">
264264
</script>
@@ -334,7 +334,7 @@ variable. The `traceparent` variable should be in the
334334
// We don't need to specify `ocSampleRate` since the trace sampling decision
335335
// is coming from the `traceparent` global variable instead.
336336
</script>
337-
<script src="https://unpkg.com/@opencensus/web-scripts@0.0.3/dist/initial-load-all.js"
337+
<script src="https://unpkg.com/@opencensus/web-scripts@0.0.4/dist/initial-load-all.js"
338338
integrity="sha384-VPY9XX7tiXeLekDPFXkfO2AqNpLTCNOzfXxVghzoVP05PXrG+wtHOW2kOP2ggO9o"
339339
async crossorigin="anonymous">
340340
</script>
@@ -356,7 +356,7 @@ In case you want to use trace user interactions:
356356
// We don't need to specify `ocSampleRate` since the trace sampling decision
357357
// is coming from the `traceparent` global variable instead.
358358
</script>
359-
<script src="https://unpkg.com/@opencensus/web-scripts@0.0.3/dist/tracing-all-with-zone.js"
359+
<script src="https://unpkg.com/@opencensus/web-scripts@0.0.4/dist/tracing-all-with-zone.js"
360360
integrity="sha384-VPY9XX7tiXeLekDPFXkfO2AqNpLTCNOzfXxVghzoVP05PXrG+wtHOW2kOP2ggO9o"
361361
async crossorigin="anonymous">
362362
</script>

examples/user_interaction/client/package-lock.json

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

examples/user_interaction/client/public/index.html

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,6 @@ <h1>OpenCensus Web User Interaction Tracing!</h1>
2929
naming approach.
3030
</p>
3131
<div id="root"></div>
32-
<script src="http://localhost:8080/tracing-all-with-zone.js"
33-
async>
3432
</script>
3533
</body>
3634

examples/user_interaction/server/server.js

Lines changed: 7 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ const tracer = setupTracerAndExporters();
2828
const http = require('http');
2929
const url = require('url');
3030
const sleep = require('sleep');
31-
let fs = require('fs');
3231

3332
/** Starts a HTTP server that receives requests on sample server port. */
3433
function startServer(port) {
@@ -96,50 +95,22 @@ function handleRequest(request, response) {
9695
sleep.sleep(2);
9796
result = { time: Date.now() - time, value: "" };
9897
console.log("Finished.")
99-
request.on('end', () => {
100-
span.end();
101-
response.statusCode = code;
102-
response.end(JSON.stringify(result));
103-
});
10498
} else if (url.parse(request.url).pathname === '/prime_numbers') {
10599
console.log("Calculate prime numbers...")
106100
const time = Date.now();
107101
const prime_numbers = JSON.stringify(calculatePrimeNumbers());
108102
result = { time: Date.now() - time, value: prime_numbers };
109103
console.log("Finished.")
110-
request.on('end', () => {
111-
span.end();
112-
response.statusCode = code;
113-
response.end(JSON.stringify(result));
114-
});
115-
} else if (url.parse(request.url).pathname === '/'){
116-
fs.readFile('../client/build/index.html', null, function (error, data) {
117-
if (error) {
118-
response.writeHead(404);
119-
response.write('Whoops! File not found!');
120-
} else {
121-
response.write(data);
122-
}
123-
response.end();
124-
});
104+
} else {
125105
result = { time: 0, value: "unknown url" };
126106
code = 404;
127-
return;
128-
} else if(url.parse(request.url).pathname.startsWith('/static')){
129-
console.log(request.url)
130-
fs.readFile('../client/build/' + url.parse(request.url).pathname, null, function (error, data) {
131-
if (error) {
132-
response.writeHead(404);
133-
response.write('Whoops! File not found!');
134-
} else {
135-
response.write(data);
136-
}
137-
response.end();
138-
});
139-
result = { time: 0, value: "unknown url" };
140-
code = 404;
141-
return
142107
}
108+
109+
request.on('end', () => {
110+
span.end();
111+
response.statusCode = code;
112+
response.end(JSON.stringify(result));
113+
});
143114
} catch (err) {
144115
console.log(err);
145116
span.end();

packages/opencensus-web-instrumentation-zone-peer-dep/src/interaction-tracker.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,9 +129,11 @@ export class InteractionTracker {
129129
private patchZoneCancelTask() {
130130
const cancelTask = Zone.prototype.cancelTask;
131131
Zone.prototype.cancelTask = (task: AsyncTask) => {
132-
const currentZone = Zone.current;
132+
let currentZone = Zone.current;
133133
if (isTracingZone(currentZone)) {
134134
task._zone = currentZone;
135+
} else if (isTracingZone(task.zone)) {
136+
currentZone = task.zone;
135137
}
136138

137139
try {

0 commit comments

Comments
 (0)