Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update examples and getting started for provider and api package #750

Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
10 changes: 5 additions & 5 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 { 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,13 +22,13 @@ 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);
// Initialize the OpenTelemetry APIs to use the BasicTracerProvider bindings
opentelemetry.initGlobalTracerProvider(provider);
dyladan marked this conversation as resolved.
Show resolved Hide resolved
const tracer = opentelemetry.getTracer('example-basic-tracer-node');
dyladan marked this conversation as resolved.
Show resolved Hide resolved

// Create a span. A span must be closed.
Expand Down
12 changes: 6 additions & 6 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 { 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,7 +16,7 @@ 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,
}));
Expand All @@ -27,10 +27,10 @@ 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.initGlobalTracerProvider(provider);

// Create a span. A span must be closed.
const parentSpan = tracer.startSpan('main');
Expand Down
10 changes: 5 additions & 5 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 { 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.initGlobalTracerProvider(provider);

return opentelemetry.getTracer();
};
10 changes: 5 additions & 5 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 { 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.initGlobalTracerProvider(provider);

return opentelemetry.getTracer();
};
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
2 changes: 1 addition & 1 deletion examples/grpc_dynamic_codegen/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
"@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
10 changes: 5 additions & 5 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 { 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.initGlobalTracerProvider(provider);

return opentelemetry.getTracer();
};
10 changes: 5 additions & 5 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 { 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.initGlobalTracerProvider(provider);

return opentelemetry.getTracer();
};
10 changes: 5 additions & 5 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 { 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.initGlobalTracerProvider(provider);

return opentelemetry.getTracer();
};
8 changes: 4 additions & 4 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 { NodeTracerProvider } = require('@opentelemetry/node');
const { SimpleSpanProcessor } = require('@opentelemetry/tracing');
const { JaegerExporter } = require('@opentelemetry/exporter-jaeger');

const tracerRegistry = new NodeTracerRegistry();
const tracerProvider = new NodeTracerProvider();
dyladan marked this conversation as resolved.
Show resolved Hide resolved

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

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

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

module.exports = opentelemetry.getTracer();
12 changes: 6 additions & 6 deletions examples/mysql/tracer.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
'use strict';

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

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

registry.addSpanProcessor(new SimpleSpanProcessor(new ZipkinExporter({
provider.addSpanProcessor(new SimpleSpanProcessor(new ZipkinExporter({
serviceName,
})));
registry.addSpanProcessor(new SimpleSpanProcessor(new JaegerExporter({
provider.addSpanProcessor(new SimpleSpanProcessor(new JaegerExporter({
serviceName,
})));

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

return opentelemetry.getTracer();
};
8 changes: 4 additions & 4 deletions examples/opentracing-shim/shim.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
'use strict';

const { NodeTracerRegistry } = require('@opentelemetry/node');
const { NodeTracerProvider } = require('@opentelemetry/node');
const { SimpleSpanProcessor } = require('@opentelemetry/tracing');
const { JaegerExporter } = require('@opentelemetry/exporter-jaeger');
const { ZipkinExporter } = require('@opentelemetry/exporter-zipkin');
const { TracerShim } = require('@opentelemetry/shim-opentracing');

function shim(serviceName) {
const registry = new NodeTracerRegistry();
const provider = new NodeTracerProvider();

registry.addSpanProcessor(new SimpleSpanProcessor(getExporter(serviceName)));
provider.addSpanProcessor(new SimpleSpanProcessor(getExporter(serviceName)));

return new TracerShim(registry.getTracer('opentracing-shim'));
return new TracerShim(provider.getTracer('opentracing-shim'));
}

function getExporter(serviceName) {
Expand Down
2 changes: 1 addition & 1 deletion examples/postgres/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
"@opentelemetry/plugin-pg": "^0.3.3",
"@opentelemetry/plugin-pg-pool": "^0.3.3",
"@opentelemetry/tracing": "^0.3.3",
"@opentelemetry/types": "^0.3.3",
"@opentelemetry/api": "^0.3.3",
"express": "^4.17.1",
"pg": "^7.12.1"
},
Expand Down
2 changes: 1 addition & 1 deletion examples/postgres/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')('postgres-server-service');
const { SpanKind, CanonicalCode } = require('@opentelemetry/types');
const { SpanKind, CanonicalCode } = require('@opentelemetry/api');
const express = require('express');
const setupPg = require('./setupPsql');

Expand Down
12 changes: 6 additions & 6 deletions examples/postgres/tracer.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
'use strict';

const opentelemetry = require('@opentelemetry/core');
const { NodeTracer } = require('@opentelemetry/node');
const opentelemetry = require('@opentelemetry/api');
const { NodeTracerRegistry } = 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 tracer = new NodeTracer({
const registry = new NodeTracerRegistry({
plugins: {
pg: {
enabled: true,
Expand Down Expand Up @@ -43,10 +43,10 @@ module.exports = (serviceName) => {
});
}

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

// Initialize the OpenTelemetry APIs to use the BasicTracer bindings
opentelemetry.initGlobalTracer(tracer);
opentelemetry.trace.initGlobalTracerRegistry(registry);

return opentelemetry.getTracer();
return opentelemetry.trace.getTracer();
};
Loading