Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: use a single eslintrc for all examples folders
Browse files Browse the repository at this point in the history
furthermore, override the strict rule that ships with airbnb
naseemkullah committed Dec 26, 2019
1 parent 3ca2df4 commit 350ccf2
Showing 38 changed files with 478 additions and 432 deletions.
3 changes: 3 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -171,6 +171,9 @@ jobs:
root: packages/opentelemetry-types/docs
paths:
- out
- run:
name: Lint examples
command: eslint examples/*/**.js
docs-deploy:
docker:
- image: node:12
12 changes: 12 additions & 0 deletions examples/.eslintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"env": {
"node": true
},
"parserOptions": {
"sourceType": "script"
},
"extends": "airbnb",
"rules": {
"strict": ["error", "global"]
}
}
6 changes: 3 additions & 3 deletions examples/basic-tracer-node/index.js
Original file line number Diff line number Diff line change
@@ -2,10 +2,10 @@ const opentelemetry = require('@opentelemetry/core');
const { BasicTracer, SimpleSpanProcessor } = require('@opentelemetry/tracing');
const { JaegerExporter } = require('@opentelemetry/exporter-jaeger');
const { ZipkinExporter } = require('@opentelemetry/exporter-zipkin');
const { CollectorExporter } = require('@opentelemetry/exporter-collector');
const { CollectorExporter } = require('@opentelemetry/exporter-collector');

const options = {
serviceName: 'basic-service'
serviceName: 'basic-service',
};

// Initialize an exporter depending on how we were started
@@ -43,7 +43,7 @@ function doWork(parent) {
// Start another span. In this example, the main method already started a
// span, so that'll be the parent span, and this will be a child span.
const span = opentelemetry.getTracer().startSpan('doWork', {
parent: parent
parent,
});

// simulate some random work.
10 changes: 5 additions & 5 deletions examples/basic-tracer-node/multi_exporter.js
Original file line number Diff line number Diff line change
@@ -2,20 +2,20 @@ const opentelemetry = require('@opentelemetry/core');
const { BasicTracer, BatchSpanProcessor, SimpleSpanProcessor } = require('@opentelemetry/tracing');
const { JaegerExporter } = require('@opentelemetry/exporter-jaeger');
const { ZipkinExporter } = require('@opentelemetry/exporter-zipkin');
const { CollectorExporter } = require('@opentelemetry/exporter-collector');
const { CollectorExporter } = require('@opentelemetry/exporter-collector');

const tracer = new BasicTracer();

const zipkinExporter = new ZipkinExporter({serviceName: 'basic-service'});
const zipkinExporter = new ZipkinExporter({ serviceName: 'basic-service' });
const jaegerExporter = new JaegerExporter({
serviceName: 'basic-service',
});
const collectorExporter = new CollectorExporter({serviceName: 'basic-service'});
const collectorExporter = new CollectorExporter({ serviceName: 'basic-service' });

// It is recommended to use this BatchSpanProcessor for better performance
// and optimization, especially in production.
tracer.addSpanProcessor(new BatchSpanProcessor(zipkinExporter, {
bufferSize: 10 // This is added for example, default size is 100.
bufferSize: 10, // This is added for example, default size is 100.
}));

// It is recommended to use SimpleSpanProcessor in case of Jaeger exporter as
@@ -44,7 +44,7 @@ function doWork(parent) {
// Start another span. In this example, the main method already started a
// span, so that'll be the parent span, and this will be a child span.
const span = opentelemetry.getTracer().startSpan('doWork', {
parent: parent
parent,
});

// simulate some random work.
45 changes: 23 additions & 22 deletions examples/dns/client.js
Original file line number Diff line number Diff line change
@@ -10,33 +10,34 @@ const config = require('./setup');
config.setupTracerAndExporters('dns-client-service');

const dns = require('dns').promises;

const tracer = opentelemetry.getTracer();

/** A function which makes a dns lookup and handles response. */
function makeLookup() {
// span corresponds to dns lookup. Here, we have manually created
// the span, which is created to track work that happens outside of the
// dns lookup query.
const span = tracer.startSpan('dnsLookup');
tracer.withSpan(span, async () => {
try {
await dns.lookup('montreal.ca');
} catch (error) {
span.setAttributes({
'error.name': error.name,
'error.message': error.message
});
}finally{
console.log(`traceid: ${span.context().traceId}`);
span.end();
}
});
// span corresponds to dns lookup. Here, we have manually created
// the span, which is created to track work that happens outside of the
// dns lookup query.
const span = tracer.startSpan('dnsLookup');
tracer.withSpan(span, async () => {
try {
await dns.lookup('montreal.ca');
} catch (error) {
span.setAttributes({
'error.name': error.name,
'error.message': error.message,
});
} finally {
console.log(`traceid: ${span.context().traceId}`);
span.end();
}
});

// The process must live for at least the interval past any traces that
// must be exported, or some risk being lost if they are recorded after the
// last export.
console.log('Sleeping 5 seconds before shutdown to ensure all records are flushed.')
setTimeout(() => { console.log('Completed.'); }, 5000);
// The process must live for at least the interval past any traces that
// must be exported, or some risk being lost if they are recorded after the
// last export.
console.log('Sleeping 5 seconds before shutdown to ensure all records are flushed.');
setTimeout(() => { console.log('Completed.'); }, 5000);
}

makeLookup();
19 changes: 10 additions & 9 deletions examples/dns/setup.js
Original file line number Diff line number Diff line change
@@ -5,19 +5,20 @@ const { NodeTracer } = require('@opentelemetry/node');
const { SimpleSpanProcessor } = require('@opentelemetry/tracing');
const { JaegerExporter } = require('@opentelemetry/exporter-jaeger');
const { ZipkinExporter } = require('@opentelemetry/exporter-zipkin');

const EXPORTER = process.env.EXPORTER || '';

function setupTracerAndExporters(service) {
const tracer = new NodeTracer({
      plugins{
          dns{
            enabledtrue,
            path'@opentelemetry/plugin-dns',
// Avoid dns lookup loop with http zipkin calls
ignoreHostnames: ['localhost']
        }
      }
  });
plugins{
dns{
enabledtrue,
path'@opentelemetry/plugin-dns',
// Avoid dns lookup loop with http zipkin calls
ignoreHostnames: ['localhost'],
},
},
});

let exporter;
if (EXPORTER.toLowerCase().startsWith('z')) {
7 changes: 4 additions & 3 deletions examples/grpc/client.js
Original file line number Diff line number Diff line change
@@ -13,6 +13,7 @@ const grpc = require('grpc');

const messages = require('./helloworld_pb');
const services = require('./helloworld_grpc_pb');

const PORT = 50051;
const tracer = opentelemetry.getTracer();

@@ -26,7 +27,7 @@ function main() {
console.log('Client traceId ', span.context().traceId);
const client = new services.GreeterClient(
`localhost:${PORT}`,
grpc.credentials.createInsecure()
grpc.credentials.createInsecure(),
);
const request = new messages.HelloRequest();
let user;
@@ -36,7 +37,7 @@ function main() {
user = 'world';
}
request.setName(user);
client.sayHello(request, function(err, response) {
client.sayHello(request, (err, response) => {
span.end();
if (err) throw err;
console.log('Greeting:', response.getMessage());
@@ -46,7 +47,7 @@ function main() {
// The process must live for at least the interval past any traces that
// must be exported, or some risk being lost if they are recorded after the
// last export.
console.log('Sleeping 5 seconds before shutdown to ensure all records are flushed.')
console.log('Sleeping 5 seconds before shutdown to ensure all records are flushed.');
setTimeout(() => { console.log('Completed.'); }, 5000);
}

14 changes: 8 additions & 6 deletions examples/grpc/helloworld_grpc_pb.js
Original file line number Diff line number Diff line change
@@ -15,9 +15,11 @@
// See the License for the specific language governing permissions and
// limitations under the License.
//

'use strict';
var grpc = require('grpc');
var helloworld_pb = require('./helloworld_pb.js');

const grpc = require('grpc');
const helloworld_pb = require('./helloworld_pb.js');

function serialize_HelloReply(arg) {
if (!(arg instanceof helloworld_pb.HelloReply)) {
@@ -39,12 +41,12 @@ function serialize_HelloRequest(arg) {

function deserialize_HelloRequest(buffer_arg) {
return helloworld_pb.HelloRequest.deserializeBinary(
new Uint8Array(buffer_arg)
new Uint8Array(buffer_arg),
);
}

// The greeting service definition.
var GreeterService = (exports.GreeterService = {
const GreeterService = (exports.GreeterService = {
// Sends a greeting
sayHello: {
path: '/helloworld.Greeter/SayHello',
@@ -55,8 +57,8 @@ var GreeterService = (exports.GreeterService = {
requestSerialize: serialize_HelloRequest,
requestDeserialize: deserialize_HelloRequest,
responseSerialize: serialize_HelloReply,
responseDeserialize: deserialize_HelloReply
}
responseDeserialize: deserialize_HelloReply,
},
});

exports.GreeterClient = grpc.makeGenericClientConstructor(GreeterService);
Loading

0 comments on commit 350ccf2

Please sign in to comment.