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

Commit 667d31a

Browse files
Add manual examples for Stackdriver and Zipkin and add license on files
1 parent 842d112 commit 667d31a

5 files changed

Lines changed: 140 additions & 55 deletions

File tree

examples/stackdriver/automatic.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,19 @@
1+
/**
2+
* Copyright 2018 Google Inc. All Rights Reserved.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
117
var fs = require('fs');
218
var tracing = require('opencensus-nodejs').addStackdriver('project-id').start();
319

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
/**
2+
* Copyright 2018 Google Inc. All Rights Reserved.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
var opencensus = require('opencensus-nodejs');
18+
var http = require('http');
19+
var fs = require('fs');
20+
21+
// Register trace exporters to export the collected data.
22+
var tracing = require('opencensus-nodejs').addStackdriver('project-id').start();
23+
var tracer = tracing.Tracer;
24+
25+
var options = {
26+
name: 'fs.writeFileSync'
27+
};
28+
29+
// Create root span for GET request
30+
tracer.startRootSpan(options, (span) => {
31+
http.get('http://httpbin.org/image/jpeg', function (response) {
32+
33+
var data = [];
34+
35+
response.on('data', (chunk) => {
36+
data.push(chunk);
37+
});
38+
39+
response.on('end', () => {
40+
var filename = 'file';
41+
// Create a child span for file writing operation
42+
var childSpan = tracer.startSpan(filename);
43+
var buffer = Buffer.concat(data);
44+
fs.writeFileSync(filename + '.jpeg', buffer, 'utf-8');
45+
46+
// Finish both root span and child span, since the operations
47+
// has ended.
48+
childSpan.end();
49+
span.end();
50+
});
51+
console.log('No more data in response.');
52+
});
53+
});

examples/zipkin/automatic.ts

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,23 @@
1+
/**
2+
* Copyright 2018 Google Inc. All Rights Reserved.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
117
var fs = require('fs');
2-
var tracing = require('opencensus-nodejs').addZipkin('http://localhost:9411/api/v2/spans', 'automatic_service');
18+
var tracing = require('opencensus-nodejs').addZipkin('http://localhost:9411/api/v2/spans', 'service_name');
319
tracing.start();
420

5-
621
var http = require('http');
722
http.createServer(function (req, res) {
823
res.writeHead(200, { 'Content-Type': 'text/html' });

examples/zipkin/custom_tracing.ts

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
/**
2+
* Copyright 2018 Google Inc. All Rights Reserved.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
var opencensus = require('opencensus-nodejs');
18+
var http = require('http');
19+
var fs = require('fs');
20+
21+
// Register trace exporters to export the collected data.
22+
var tracing = opencensus.addZipkin('http://localhost:9411/api/v2/spans', 'service_name').start();
23+
var tracer = tracing.Tracer;
24+
25+
var options = {
26+
name: 'fs.writeFileSync'
27+
};
28+
29+
// Create root span for GET request
30+
tracer.startRootSpan(options, (span) => {
31+
http.get('http://httpbin.org/image/jpeg', function (response) {
32+
33+
var data = [];
34+
35+
response.on('data', (chunk) => {
36+
data.push(chunk);
37+
});
38+
39+
response.on('end', () => {
40+
var filename = 'file';
41+
// Create a child span for file writing operation
42+
var childSpan = tracer.startSpan(filename);
43+
var buffer = Buffer.concat(data);
44+
fs.writeFileSync(filename + '.jpeg', buffer, 'utf-8');
45+
46+
// Finish both root span and child span, since the operations
47+
// has ended.
48+
childSpan.end();
49+
span.end();
50+
});
51+
console.log('No more data in response.');
52+
});
53+
});
54+

examples/zipkin/manual.ts

Lines changed: 0 additions & 53 deletions
This file was deleted.

0 commit comments

Comments
 (0)