Skip to content

Commit

Permalink
update examples and getting started for provider and api package (#750)
Browse files Browse the repository at this point in the history
* chore: rename provider in examples and getting started

* chore: update examples, bench, and getting started for api

* chore: update examples for latest changes

* chore: lint examples
  • Loading branch information
dyladan authored Feb 5, 2020
1 parent 470fc62 commit c5bc438
Show file tree
Hide file tree
Showing 40 changed files with 181 additions and 179 deletions.
7 changes: 4 additions & 3 deletions benchmark/tracer.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
'use strict';

const benchmark = require('./benchmark');
const opentelemetry = require('../packages/opentelemetry-core');
const opentelemetry = require('../packages/opentelemetry-api');
const { NoopLogger } = require('../packages/opentelemetry-core');
const { BasicTracerProvider, BatchSpanProcessor, InMemorySpanExporter, SimpleSpanProcessor } = require('../packages/opentelemetry-tracing');

const logger = new opentelemetry.NoopLogger();
const logger = new NoopLogger();

const setups = [
{
name: 'NoopTracerProvider',
provider: opentelemetry.getTracerProvider()
provider: new opentelemetry.NoopTracerProvider()
},
{
name: 'BasicTracerProvider',
Expand Down
14 changes: 7 additions & 7 deletions examples/basic-tracer-node/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'use strict';

const opentelemetry = require('@opentelemetry/core');
const { BasicTracerRegistry, SimpleSpanProcessor } = require('@opentelemetry/tracing');
const opentelemetry = require('@opentelemetry/api');
const { BasicTracerProvider, SimpleSpanProcessor } = require('@opentelemetry/tracing');
const { JaegerExporter } = require('@opentelemetry/exporter-jaeger');
const { ZipkinExporter } = require('@opentelemetry/exporter-zipkin');
const { CollectorExporter } = require('@opentelemetry/exporter-collector');
Expand All @@ -22,14 +22,14 @@ if (EXPORTER.toLowerCase().startsWith('z')) {
exporter = new CollectorExporter(options);
}

const registry = new BasicTracerRegistry();
const provider = new BasicTracerProvider();

// Configure span processor to send spans to the provided exporter
registry.addSpanProcessor(new SimpleSpanProcessor(exporter));
provider.addSpanProcessor(new SimpleSpanProcessor(exporter));

// Initialize the OpenTelemetry APIs to use the BasicTracerRegistry bindings
opentelemetry.initGlobalTracerRegistry(registry);
const tracer = opentelemetry.getTracer('example-basic-tracer-node');
// Initialize the OpenTelemetry APIs to use the BasicTracerProvider bindings
opentelemetry.trace.initGlobalTracerProvider(provider);
const tracer = opentelemetry.trace.getTracer('example-basic-tracer-node');

// Create a span. A span must be closed.
const parentSpan = tracer.startSpan('main');
Expand Down
16 changes: 8 additions & 8 deletions examples/basic-tracer-node/multi_exporter.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
'use strict';

const opentelemetry = require('@opentelemetry/core');
const { BasicTracerRegistry, BatchSpanProcessor, SimpleSpanProcessor } = require('@opentelemetry/tracing');
const opentelemetry = require('@opentelemetry/api');
const { BasicTracerProvider, BatchSpanProcessor, SimpleSpanProcessor } = require('@opentelemetry/tracing');
const { JaegerExporter } = require('@opentelemetry/exporter-jaeger');
const { ZipkinExporter } = require('@opentelemetry/exporter-zipkin');
const { CollectorExporter } = require('@opentelemetry/exporter-collector');

const registry = new BasicTracerRegistry();
const provider = new BasicTracerProvider();

const zipkinExporter = new ZipkinExporter({ serviceName: 'basic-service' });
const jaegerExporter = new JaegerExporter({
Expand All @@ -16,21 +16,21 @@ const collectorExporter = new CollectorExporter({ serviceName: 'basic-service' }

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

const tracer = opentelemetry.getTracer('default');
const tracer = opentelemetry.trace.getTracer('default');

tracer.addSpanProcessor(new BatchSpanProcessor(jaegerExporter), {
bufferSize: 10,
});

registry.addSpanProcessor(new SimpleSpanProcessor(collectorExporter));
provider.addSpanProcessor(new SimpleSpanProcessor(collectorExporter));

// Initialize the OpenTelemetry APIs to use the BasicTracerRegistry bindings
opentelemetry.initGlobalTracerRegistry(registry);
// Initialize the OpenTelemetry APIs to use the BasicTracerProvider bindings
opentelemetry.trace.initGlobalTracerProvider(provider);

// Create a span. A span must be closed.
const parentSpan = tracer.startSpan('main');
Expand Down
2 changes: 1 addition & 1 deletion examples/basic-tracer-node/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
"url": "https://github.com/open-telemetry/opentelemetry-js/issues"
},
"dependencies": {
"@opentelemetry/core": "^0.3.3",
"@opentelemetry/api": "^0.3.3",
"@opentelemetry/exporter-collector": "^0.3.3",
"@opentelemetry/exporter-jaeger": "^0.3.3",
"@opentelemetry/exporter-zipkin": "^0.3.3",
Expand Down
2 changes: 1 addition & 1 deletion examples/dns/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
"url": "https://github.com/open-telemetry/opentelemetry-js/issues"
},
"dependencies": {
"@opentelemetry/core": "^0.3.3",
"@opentelemetry/api": "^0.3.3",
"@opentelemetry/exporter-jaeger": "^0.3.3",
"@opentelemetry/exporter-zipkin": "^0.3.3",
"@opentelemetry/node": "^0.3.3",
Expand Down
14 changes: 7 additions & 7 deletions examples/dns/tracer.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
'use strict';

const opentelemetry = require('@opentelemetry/core');
const { NodeTracerRegistry } = require('@opentelemetry/node');
const opentelemetry = require('@opentelemetry/api');
const { NodeTracerProvider } = 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 || '';

module.exports = (serviceName) => {
const registry = new NodeTracerRegistry({
const provider = new NodeTracerProvider({
plugins: {
dns: {
enabled: true,
Expand All @@ -31,10 +31,10 @@ module.exports = (serviceName) => {
});
}

registry.addSpanProcessor(new SimpleSpanProcessor(exporter));
provider.addSpanProcessor(new SimpleSpanProcessor(exporter));

// Initialize the OpenTelemetry APIs to use the BasicTracerRegistry bindings
opentelemetry.initGlobalTracerRegistry(registry);
// Initialize the OpenTelemetry APIs to use the BasicTracerProvider bindings
opentelemetry.trace.initGlobalTracerProvider(provider);

return opentelemetry.getTracer();
return opentelemetry.trace.getTracer('dns-example');
};
2 changes: 1 addition & 1 deletion examples/grpc/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
"url": "https://github.com/open-telemetry/opentelemetry-js/issues"
},
"dependencies": {
"@opentelemetry/core": "^0.3.3",
"@opentelemetry/api": "^0.3.3",
"@opentelemetry/exporter-jaeger": "^0.3.3",
"@opentelemetry/exporter-zipkin": "^0.3.3",
"@opentelemetry/node": "^0.3.3",
Expand Down
14 changes: 7 additions & 7 deletions examples/grpc/tracer.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
'use strict';

const opentelemetry = require('@opentelemetry/core');
const { NodeTracerRegistry } = require('@opentelemetry/node');
const opentelemetry = require('@opentelemetry/api');
const { NodeTracerProvider } = 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 || '';

module.exports = (serviceName) => {
const registry = new NodeTracerRegistry({
const provider = new NodeTracerProvider({
plugins: {
grpc: {
enabled: true,
Expand All @@ -29,10 +29,10 @@ module.exports = (serviceName) => {
});
}

registry.addSpanProcessor(new SimpleSpanProcessor(exporter));
provider.addSpanProcessor(new SimpleSpanProcessor(exporter));

// Initialize the OpenTelemetry APIs to use the BasicTracerRegistry bindings
opentelemetry.initGlobalTracerRegistry(registry);
// Initialize the OpenTelemetry APIs to use the BasicTracerProvider bindings
opentelemetry.trace.initGlobalTracerProvider(provider);

return opentelemetry.getTracer();
return opentelemetry.trace.getTracer('grpc-example');
};
2 changes: 1 addition & 1 deletion examples/grpc_dynamic_codegen/capitalize_server.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

// eslint-disable-next-line import/order
const tracer = require('./tracer')('example-grpc-capitalize-server');
const { SpanKind } = require('@opentelemetry/types');
const { SpanKind } = require('@opentelemetry/api');
const path = require('path');
const grpc = require('grpc');
const protoLoader = require('@grpc/proto-loader');
Expand Down
4 changes: 2 additions & 2 deletions examples/grpc_dynamic_codegen/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,13 @@
},
"dependencies": {
"@grpc/proto-loader": "^0.4.0",
"@opentelemetry/core": "^0.3.3",
"@opentelemetry/api": "^0.3.3",
"@opentelemetry/exporter-jaeger": "^0.3.3",
"@opentelemetry/exporter-zipkin": "^0.3.3",
"@opentelemetry/node": "^0.3.3",
"@opentelemetry/plugin-grpc": "^0.3.3",
"@opentelemetry/tracing": "^0.3.3",
"@opentelemetry/types": "^0.3.3",
"@opentelemetry/api": "^0.3.3",
"grpc": "^1.23.3",
"node-pre-gyp": "0.12.0"
},
Expand Down
14 changes: 7 additions & 7 deletions examples/grpc_dynamic_codegen/tracer.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
'use strict';

const opentelemetry = require('@opentelemetry/core');
const { NodeTracerRegistry } = require('@opentelemetry/node');
const opentelemetry = require('@opentelemetry/api');
const { NodeTracerProvider } = 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 || '';

module.exports = (serviceName) => {
const registry = new NodeTracerRegistry({
const provider = new NodeTracerProvider({
plugins: {
grpc: {
enabled: true,
Expand All @@ -32,10 +32,10 @@ module.exports = (serviceName) => {

// It is recommended to use this `BatchSpanProcessor` for better performance
// and optimization, especially in production.
registry.addSpanProcessor(new SimpleSpanProcessor(exporter));
provider.addSpanProcessor(new SimpleSpanProcessor(exporter));

// Initialize the OpenTelemetry APIs to use the BasicTracerRegistry bindings
opentelemetry.initGlobalTracerRegistry(registry);
// Initialize the OpenTelemetry APIs to use the BasicTracerProvider bindings
opentelemetry.trace.initGlobalTracerProvider(provider);

return opentelemetry.getTracer();
return opentelemetry.trace.getTracer('grpc-dynamic-codegen-example');
};
2 changes: 1 addition & 1 deletion examples/http/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
"url": "https://github.com/open-telemetry/opentelemetry-js/issues"
},
"dependencies": {
"@opentelemetry/core": "^0.3.3",
"@opentelemetry/api": "^0.3.3",
"@opentelemetry/exporter-jaeger": "^0.3.3",
"@opentelemetry/exporter-zipkin": "^0.3.3",
"@opentelemetry/node": "^0.3.3",
Expand Down
14 changes: 7 additions & 7 deletions examples/http/tracer.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
'use strict';

const opentelemetry = require('@opentelemetry/core');
const { NodeTracerRegistry } = require('@opentelemetry/node');
const opentelemetry = require('@opentelemetry/api');
const { NodeTracerProvider } = 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 || '';

module.exports = (serviceName) => {
const registry = new NodeTracerRegistry();
const provider = new NodeTracerProvider();

let exporter;
if (EXPORTER.toLowerCase().startsWith('z')) {
Expand All @@ -22,10 +22,10 @@ module.exports = (serviceName) => {
});
}

registry.addSpanProcessor(new SimpleSpanProcessor(exporter));
provider.addSpanProcessor(new SimpleSpanProcessor(exporter));

// Initialize the OpenTelemetry APIs to use the BasicTracerRegistry bindings
opentelemetry.initGlobalTracerRegistry(registry);
// Initialize the OpenTelemetry APIs to use the BasicTracerProvider bindings
opentelemetry.trace.initGlobalTracerProvider(provider);

return opentelemetry.getTracer();
return opentelemetry.trace.getTracer('http-example');
};
2 changes: 1 addition & 1 deletion examples/https/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
"url": "https://github.com/open-telemetry/opentelemetry-js/issues"
},
"dependencies": {
"@opentelemetry/core": "^0.3.3",
"@opentelemetry/api": "^0.3.3",
"@opentelemetry/exporter-jaeger": "^0.3.3",
"@opentelemetry/exporter-zipkin": "^0.3.3",
"@opentelemetry/node": "^0.3.3",
Expand Down
14 changes: 7 additions & 7 deletions examples/https/tracer.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'use strict';

const opentelemetry = require('@opentelemetry/core');
const { NodeTracerRegistry } = require('@opentelemetry/node');
const opentelemetry = require('@opentelemetry/api');
const { NodeTracerProvider } = require('@opentelemetry/node');
const { SimpleSpanProcessor } = require('@opentelemetry/tracing');
const { JaegerExporter } = require('@opentelemetry/exporter-jaeger');
const { ZipkinExporter } = require('@opentelemetry/exporter-zipkin');
Expand All @@ -11,7 +11,7 @@ process.env.NODE_TLS_REJECT_UNAUTHORIZED = '0';

module.exports = (serviceName) => {
let exporter;
const registry = new NodeTracerRegistry();
const provider = new NodeTracerProvider();

if (EXPORTER.toLowerCase().startsWith('z')) {
exporter = new ZipkinExporter({
Expand All @@ -23,10 +23,10 @@ module.exports = (serviceName) => {
});
}

registry.addSpanProcessor(new SimpleSpanProcessor(exporter));
provider.addSpanProcessor(new SimpleSpanProcessor(exporter));

// Initialize the OpenTelemetry APIs to use the BasicTracerRegistry bindings
opentelemetry.initGlobalTracerRegistry(registry);
// Initialize the OpenTelemetry APIs to use the BasicTracerProvider bindings
opentelemetry.trace.initGlobalTracerProvider(provider);

return opentelemetry.getTracer();
return opentelemetry.trace.getTracer('https-example');
};
2 changes: 1 addition & 1 deletion examples/ioredis/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
"url": "https://github.com/open-telemetry/opentelemetry-js/issues"
},
"dependencies": {
"@opentelemetry/core": "^0.3.3",
"@opentelemetry/api": "^0.3.3",
"@opentelemetry/exporter-jaeger": "^0.3.3",
"@opentelemetry/node": "^0.3.3",
"@opentelemetry/plugin-ioredis": "^0.3.3",
Expand Down
12 changes: 6 additions & 6 deletions examples/ioredis/tracer.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
'use strict';

const opentelemetry = require('@opentelemetry/core');
const { NodeTracerRegistry } = require('@opentelemetry/node');
const opentelemetry = require('@opentelemetry/api');
const { NodeTracerProvider } = require('@opentelemetry/node');
const { SimpleSpanProcessor } = require('@opentelemetry/tracing');
const { JaegerExporter } = require('@opentelemetry/exporter-jaeger');

const tracerRegistry = new NodeTracerRegistry();
const provider = new NodeTracerProvider();

const exporter = new JaegerExporter({ serviceName: 'ioredis-example' });

tracerRegistry.addSpanProcessor(new SimpleSpanProcessor(exporter));
provider.addSpanProcessor(new SimpleSpanProcessor(exporter));

// Initialize the OpenTelemetry APIs to use the BasicTracer bindings
opentelemetry.initGlobalTracerRegistry(tracerRegistry);
opentelemetry.trace.initGlobalTracerProvider(provider);

module.exports = opentelemetry.getTracer();
module.exports = opentelemetry.trace.getTracer('ioredis-example');
2 changes: 1 addition & 1 deletion examples/mysql/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
"url": "https://github.com/open-telemetry/opentelemetry-js/issues"
},
"dependencies": {
"@opentelemetry/core": "^0.3.3",
"@opentelemetry/api": "^0.3.3",
"@opentelemetry/exporter-jaeger": "^0.3.3",
"@opentelemetry/exporter-zipkin": "^0.3.3",
"@opentelemetry/node": "^0.3.3",
Expand Down
Loading

0 comments on commit c5bc438

Please sign in to comment.