From 3987ef61b226ede40e50fb8329aff1a2619bdb21 Mon Sep 17 00:00:00 2001 From: Omkar Kirpan Date: Thu, 17 Jun 2021 14:40:45 +0530 Subject: [PATCH 1/5] fix: service.name Resource attribute Since the 0.20.0 release and the pull request #2227 it seems that serviceName is deprecated and we should use service.name instead. I havn't easily found this information in the changelog, it did require some digging to understand why the service name was now a very long unknown_service:/path/to/node. Documentation says use service.name Resource attribute instead. but it wasn't about replacing serviceName: 'yourServiceName' by service: { name: 'yourServiceName'}. --- examples/grpc-js/tracer.js | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/examples/grpc-js/tracer.js b/examples/grpc-js/tracer.js index 7710dff1d8..23c680754a 100644 --- a/examples/grpc-js/tracer.js +++ b/examples/grpc-js/tracer.js @@ -7,11 +7,17 @@ const { SimpleSpanProcessor } = require('@opentelemetry/tracing'); const { JaegerExporter } = require('@opentelemetry/exporter-jaeger'); const { ZipkinExporter } = require('@opentelemetry/exporter-zipkin'); const { GrpcInstrumentation } = require('@opentelemetry/instrumentation-grpc'); +const { ResourceAttributes } = require("@opentelemetry/semantic-conventions"); +const { Resource } = require("@opentelemetry/resources"); const EXPORTER = process.env.EXPORTER || ''; module.exports = (serviceName) => { - const provider = new NodeTracerProvider(); + const provider = new NodeTracerProvider({ + resource: new Resource({ + [ResourceAttributes.SERVICE_NAME]: serviceName, + }), + }); let exporter; if (EXPORTER.toLowerCase().startsWith('z')) { From 82ae64dfec0a66e8ee2e044889f2262a3c9804e3 Mon Sep 17 00:00:00 2001 From: Omkar Kirpan Date: Thu, 17 Jun 2021 15:39:52 +0530 Subject: [PATCH 2/5] chore: remove service name option removes service name option passed in exporter --- examples/grpc-js/tracer.js | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/examples/grpc-js/tracer.js b/examples/grpc-js/tracer.js index 23c680754a..acab8cb306 100644 --- a/examples/grpc-js/tracer.js +++ b/examples/grpc-js/tracer.js @@ -21,13 +21,9 @@ module.exports = (serviceName) => { let exporter; if (EXPORTER.toLowerCase().startsWith('z')) { - exporter = new ZipkinExporter({ - serviceName, - }); + exporter = new ZipkinExporter(); } else { - exporter = new JaegerExporter({ - serviceName, - }); + exporter = new JaegerExporter(); } provider.addSpanProcessor(new SimpleSpanProcessor(exporter)); From ef6363d35fb14546b6c6c41acf13b620a7c86e6d Mon Sep 17 00:00:00 2001 From: Omkar Kirpan Date: Fri, 18 Jun 2021 00:42:49 +0530 Subject: [PATCH 3/5] style: fix lint errors --- examples/grpc-js/tracer.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/examples/grpc-js/tracer.js b/examples/grpc-js/tracer.js index acab8cb306..e0c1a48194 100644 --- a/examples/grpc-js/tracer.js +++ b/examples/grpc-js/tracer.js @@ -7,8 +7,8 @@ const { SimpleSpanProcessor } = require('@opentelemetry/tracing'); const { JaegerExporter } = require('@opentelemetry/exporter-jaeger'); const { ZipkinExporter } = require('@opentelemetry/exporter-zipkin'); const { GrpcInstrumentation } = require('@opentelemetry/instrumentation-grpc'); -const { ResourceAttributes } = require("@opentelemetry/semantic-conventions"); -const { Resource } = require("@opentelemetry/resources"); +const { ResourceAttributes } = require('@opentelemetry/semantic-conventions'); +const { Resource } = require('@opentelemetry/resources'); const EXPORTER = process.env.EXPORTER || ''; From 38c9b2417ecc77f26ba17d6cc336c97bbcb46e5b Mon Sep 17 00:00:00 2001 From: Omkar Kirpan Date: Thu, 24 Jun 2021 15:03:31 +0530 Subject: [PATCH 4/5] chore: update all examples --- examples/basic-tracer-node/index.js | 9 +++++++-- examples/collector-exporter-node/metrics.js | 6 +++++- examples/collector-exporter-node/tracing.js | 9 +++++++-- examples/grpc-js/tracer.js | 4 ++-- examples/grpc/tracer.js | 16 +++++++++------- examples/http/tracer.js | 16 +++++++++------- examples/https/tracer.js | 16 +++++++++------- examples/tracer-web/examples/metrics/index.js | 9 ++++++--- getting-started/README.md | 9 +++++++-- getting-started/traced-example/tracing.js | 9 +++++++-- getting-started/ts-example/README.md | 4 +++- .../ts-example/traced-example/tracing.ts | 9 +++++++-- packages/opentelemetry-exporter-jaeger/README.md | 1 - packages/opentelemetry-exporter-zipkin/README.md | 1 - packages/opentelemetry-sdk-node/README.md | 4 +--- 15 files changed, 79 insertions(+), 43 deletions(-) diff --git a/examples/basic-tracer-node/index.js b/examples/basic-tracer-node/index.js index c43657e96e..839f8a2744 100644 --- a/examples/basic-tracer-node/index.js +++ b/examples/basic-tracer-node/index.js @@ -1,14 +1,19 @@ 'use strict'; const opentelemetry = require('@opentelemetry/api'); +const { Resource } = require('@opentelemetry/resources'); +const { ResourceAttributes } = require('@opentelemetry/semantic-conventions'); const { BasicTracerProvider, ConsoleSpanExporter, SimpleSpanProcessor } = require('@opentelemetry/tracing'); const { JaegerExporter } = require('@opentelemetry/exporter-jaeger'); -const provider = new BasicTracerProvider(); +const provider = new BasicTracerProvider({ + resource: new Resource({ + [ResourceAttributes.SERVICE_NAME]: 'basic-service', + }), +}); // Configure span processor to send spans to the exporter const exporter = new JaegerExporter({ - serviceName: 'basic-service', endpoint: 'http://localhost:14268/api/traces', }); provider.addSpanProcessor(new SimpleSpanProcessor(exporter)); diff --git a/examples/collector-exporter-node/metrics.js b/examples/collector-exporter-node/metrics.js index 36182a54ce..bcd5b886c2 100644 --- a/examples/collector-exporter-node/metrics.js +++ b/examples/collector-exporter-node/metrics.js @@ -5,18 +5,22 @@ const { CollectorMetricExporter } = require('@opentelemetry/exporter-collector') // const { CollectorMetricExporter } = require('@opentelemetry/exporter-collector-grpc'); // const { CollectorMetricExporter } = require('@opentelemetry/exporter-collector-proto'); const { MeterProvider } = require('@opentelemetry/metrics'); +const { Resource } = require('@opentelemetry/resources'); +const { ResourceAttributes } = require('@opentelemetry/semantic-conventions'); // Optional and only needed to see the internal diagnostic logging (during development) diag.setLogger(new DiagConsoleLogger(), DiagLogLevel.DEBUG); const metricExporter = new CollectorMetricExporter({ - serviceName: 'basic-metric-service', // url: 'http://localhost:55681/v1/metrics', }); const meter = new MeterProvider({ exporter: metricExporter, interval: 1000, + resource: new Resource({ + [ResourceAttributes.SERVICE_NAME]: 'basic-metric-service', + }), }).getMeter('example-exporter-collector'); const requestCounter = meter.createCounter('requests', { diff --git a/examples/collector-exporter-node/tracing.js b/examples/collector-exporter-node/tracing.js index 5f0bd39e17..73718925e6 100644 --- a/examples/collector-exporter-node/tracing.js +++ b/examples/collector-exporter-node/tracing.js @@ -3,6 +3,8 @@ const opentelemetry = require('@opentelemetry/api'); const { BasicTracerProvider, ConsoleSpanExporter, SimpleSpanProcessor } = require('@opentelemetry/tracing'); const { CollectorTraceExporter } = require('@opentelemetry/exporter-collector'); +import { Resource } from '@opentelemetry/resources'; +import { ResourceAttributes } from '@opentelemetry/semantic-conventions'; // const { CollectorTraceExporter } = require('@opentelemetry/exporter-collector-grpc'); // const { CollectorTraceExporter } = require('@opentelemetry/exporter-collector-proto'); @@ -12,13 +14,16 @@ const { CollectorTraceExporter } = require('@opentelemetry/exporter-collector'); // ); const exporter = new CollectorTraceExporter({ - serviceName: 'basic-service', // headers: { // foo: 'bar' // }, }); -const provider = new BasicTracerProvider(); +const provider = new BasicTracerProvider({ + resource: new Resource({ + [ResourceAttributes.SERVICE_NAME]: 'basic-service', + }), +}); provider.addSpanProcessor(new SimpleSpanProcessor(exporter)); provider.addSpanProcessor(new SimpleSpanProcessor(new ConsoleSpanExporter())); provider.register(); diff --git a/examples/grpc-js/tracer.js b/examples/grpc-js/tracer.js index e0c1a48194..b42f510973 100644 --- a/examples/grpc-js/tracer.js +++ b/examples/grpc-js/tracer.js @@ -3,12 +3,12 @@ const opentelemetry = require('@opentelemetry/api'); const { registerInstrumentations } = require('@opentelemetry/instrumentation'); const { NodeTracerProvider } = require('@opentelemetry/node'); +const { Resource } = require('@opentelemetry/resources'); +const { ResourceAttributes } = require('@opentelemetry/semantic-conventions'); const { SimpleSpanProcessor } = require('@opentelemetry/tracing'); const { JaegerExporter } = require('@opentelemetry/exporter-jaeger'); const { ZipkinExporter } = require('@opentelemetry/exporter-zipkin'); const { GrpcInstrumentation } = require('@opentelemetry/instrumentation-grpc'); -const { ResourceAttributes } = require('@opentelemetry/semantic-conventions'); -const { Resource } = require('@opentelemetry/resources'); const EXPORTER = process.env.EXPORTER || ''; diff --git a/examples/grpc/tracer.js b/examples/grpc/tracer.js index 5c108de48d..e2cbf08e4a 100644 --- a/examples/grpc/tracer.js +++ b/examples/grpc/tracer.js @@ -3,6 +3,8 @@ const opentelemetry = require('@opentelemetry/api'); const { registerInstrumentations } = require('@opentelemetry/instrumentation'); const { NodeTracerProvider } = require('@opentelemetry/node'); +const { Resource } = require('@opentelemetry/resources'); +const { ResourceAttributes } = require('@opentelemetry/semantic-conventions'); const { SimpleSpanProcessor } = require('@opentelemetry/tracing'); const { JaegerExporter } = require('@opentelemetry/exporter-jaeger'); const { ZipkinExporter } = require('@opentelemetry/exporter-zipkin'); @@ -11,17 +13,17 @@ const { GrpcInstrumentation } = require('@opentelemetry/instrumentation-grpc'); const EXPORTER = process.env.EXPORTER || ''; module.exports = (serviceName) => { - const provider = new NodeTracerProvider(); + const provider = new NodeTracerProvider({ + resource: new Resource({ + [ResourceAttributes.SERVICE_NAME]: serviceName, + }), + }); let exporter; if (EXPORTER.toLowerCase().startsWith('z')) { - exporter = new ZipkinExporter({ - serviceName, - }); + exporter = new ZipkinExporter(); } else { - exporter = new JaegerExporter({ - serviceName, - }); + exporter = new JaegerExporter(); } provider.addSpanProcessor(new SimpleSpanProcessor(exporter)); diff --git a/examples/http/tracer.js b/examples/http/tracer.js index 25e97ccc06..d73db897c2 100644 --- a/examples/http/tracer.js +++ b/examples/http/tracer.js @@ -3,6 +3,8 @@ const opentelemetry = require('@opentelemetry/api'); const { registerInstrumentations } = require('@opentelemetry/instrumentation'); const { NodeTracerProvider } = require('@opentelemetry/node'); +const { Resource } = require('@opentelemetry/resources'); +const { ResourceAttributes } = require('@opentelemetry/semantic-conventions'); const { SimpleSpanProcessor } = require('@opentelemetry/tracing'); const { JaegerExporter } = require('@opentelemetry/exporter-jaeger'); const { ZipkinExporter } = require('@opentelemetry/exporter-zipkin'); @@ -11,17 +13,17 @@ const { HttpInstrumentation } = require('@opentelemetry/instrumentation-http'); const EXPORTER = process.env.EXPORTER || ''; module.exports = (serviceName) => { - const provider = new NodeTracerProvider(); + const provider = new NodeTracerProvider({ + resource: new Resource({ + [ResourceAttributes.SERVICE_NAME]: serviceName, + }), + }); let exporter; if (EXPORTER.toLowerCase().startsWith('z')) { - exporter = new ZipkinExporter({ - serviceName, - }); + exporter = new ZipkinExporter(); } else { - exporter = new JaegerExporter({ - serviceName, - }); + exporter = new JaegerExporter(); } provider.addSpanProcessor(new SimpleSpanProcessor(exporter)); diff --git a/examples/https/tracer.js b/examples/https/tracer.js index dbee05b099..1f7be3fb10 100644 --- a/examples/https/tracer.js +++ b/examples/https/tracer.js @@ -3,6 +3,8 @@ const opentelemetry = require('@opentelemetry/api'); const { registerInstrumentations } = require('@opentelemetry/instrumentation'); const { NodeTracerProvider } = require('@opentelemetry/node'); +const { Resource } = require('@opentelemetry/resources'); +const { ResourceAttributes } = require('@opentelemetry/semantic-conventions'); const { SimpleSpanProcessor } = require('@opentelemetry/tracing'); const { JaegerExporter } = require('@opentelemetry/exporter-jaeger'); const { ZipkinExporter } = require('@opentelemetry/exporter-zipkin'); @@ -13,16 +15,16 @@ process.env.NODE_TLS_REJECT_UNAUTHORIZED = '0'; module.exports = (serviceName) => { let exporter; - const provider = new NodeTracerProvider(); + const provider = new NodeTracerProvider({ + resource: new Resource({ + [ResourceAttributes.SERVICE_NAME]: serviceName, + }), + }); if (EXPORTER.toLowerCase().startsWith('z')) { - exporter = new ZipkinExporter({ - serviceName, - }); + exporter = new ZipkinExporter(); } else { - exporter = new JaegerExporter({ - serviceName, - }); + exporter = new JaegerExporter(); } provider.addSpanProcessor(new SimpleSpanProcessor(exporter)); diff --git a/examples/tracer-web/examples/metrics/index.js b/examples/tracer-web/examples/metrics/index.js index 3e546ac3fd..91c8fe4610 100644 --- a/examples/tracer-web/examples/metrics/index.js +++ b/examples/tracer-web/examples/metrics/index.js @@ -3,13 +3,13 @@ const { DiagConsoleLogger, DiagLogLevel, diag } = require('@opentelemetry/api'); const { CollectorMetricExporter } = require('@opentelemetry/exporter-collector'); const { MeterProvider } = require('@opentelemetry/metrics'); +const { Resource } = require('@opentelemetry/resources'); +const { ResourceAttributes } = require('@opentelemetry/semantic-conventions'); // Optional and only needed to see the internal diagnostic logging (during development) diag.setLogger(new DiagConsoleLogger(), DiagLogLevel.DEBUG); -const metricExporter = new CollectorMetricExporter({ - serviceName: 'basic-metric-service', -}); +const metricExporter = new CollectorMetricExporter(); let interval; let meter; @@ -25,6 +25,9 @@ function startMetrics() { meter = new MeterProvider({ exporter: metricExporter, interval: 1000, + resource: new Resource({ + [ResourceAttributes.SERVICE_NAME]: 'basic-metric-service', + }), }).getMeter('example-exporter-collector'); const requestCounter = meter.createCounter('requests', { diff --git a/getting-started/README.md b/getting-started/README.md index 6a4cc827f3..1e88a2e593 100644 --- a/getting-started/README.md +++ b/getting-started/README.md @@ -125,20 +125,25 @@ After you install these dependencies, initialize and register them. Modify `trac const { diag, DiagConsoleLogger, DiagLogLevel } = require("@opentelemetry/api"); const { NodeTracerProvider } = require("@opentelemetry/node"); +const { Resource } = require('@opentelemetry/resources'); +const { ResourceAttributes } = require('@opentelemetry/semantic-conventions'); const { SimpleSpanProcessor } = require("@opentelemetry/tracing"); const { ZipkinExporter } = require("@opentelemetry/exporter-zipkin"); const { registerInstrumentations } = require("@opentelemetry/instrumentation"); const { HttpInstrumentation } = require("@opentelemetry/instrumentation-http"); const { GrpcInstrumentation } = require("@opentelemetry/instrumentation-grpc"); -const provider = new NodeTracerProvider(); +const provider = new NodeTracerProvider({ + resource: new Resource({ + [ResourceAttributes.SERVICE_NAME]: "getting-started", + }) +}); diag.setLogger(new DiagConsoleLogger(), DiagLogLevel.ALL); provider.addSpanProcessor( new SimpleSpanProcessor( new ZipkinExporter({ - serviceName: "getting-started", // If you are running your tracing backend on another host, // you can point to it using the `url` parameter of the // exporter config. diff --git a/getting-started/traced-example/tracing.js b/getting-started/traced-example/tracing.js index 5c3172682d..e1ac8b3264 100644 --- a/getting-started/traced-example/tracing.js +++ b/getting-started/traced-example/tracing.js @@ -2,17 +2,22 @@ const { NodeTracerProvider } = require("@opentelemetry/node"); const { SimpleSpanProcessor } = require("@opentelemetry/tracing"); +const { Resource } = require('@opentelemetry/resources'); +const { ResourceAttributes } = require('@opentelemetry/semantic-conventions'); const { ZipkinExporter } = require("@opentelemetry/exporter-zipkin"); const { registerInstrumentations } = require('@opentelemetry/instrumentation'); const { ExpressInstrumentation } = require('@opentelemetry/instrumentation-express'); const { HttpInstrumentation } = require('@opentelemetry/instrumentation-http'); -const provider = new NodeTracerProvider(); +const provider = new NodeTracerProvider({ + resource: new Resource({ + [ResourceAttributes.SERVICE_NAME]: "getting-started", + }) +}); provider.addSpanProcessor( new SimpleSpanProcessor( new ZipkinExporter({ - serviceName: "getting-started" // If you are running your tracing backend on another host, // you can point to it using the `url` parameter of the // exporter config. diff --git a/getting-started/ts-example/README.md b/getting-started/ts-example/README.md index 7c2b28d8f4..b4c75a5407 100644 --- a/getting-started/ts-example/README.md +++ b/getting-started/ts-example/README.md @@ -134,6 +134,9 @@ import { HttpInstrumentation } from '@opentelemetry/instrumentation-http'; const provider: NodeTracerProvider = new NodeTracerProvider({ logLevel: LogLevel.ERROR, + resource: new Resource({ + [ResourceAttributes.SERVICE_NAME]: 'getting-started', + }), }); provider.addSpanProcessor( @@ -141,7 +144,6 @@ provider.addSpanProcessor( new ZipkinExporter({ // For Jaeger, use the following line instead: // new JaegerExporter({ - serviceName: 'getting-started', // If you are running your tracing backend on another host, // you can point to it using the `url` parameter of the // exporter config. diff --git a/getting-started/ts-example/traced-example/tracing.ts b/getting-started/ts-example/traced-example/tracing.ts index 4598578ef2..1d0f400fe4 100644 --- a/getting-started/ts-example/traced-example/tracing.ts +++ b/getting-started/ts-example/traced-example/tracing.ts @@ -1,4 +1,6 @@ import { NodeTracerProvider } from '@opentelemetry/node'; +const { Resource } = require('@opentelemetry/resources'); +const { ResourceAttributes } = require('@opentelemetry/semantic-conventions'); import { SimpleSpanProcessor } from '@opentelemetry/tracing'; import { ZipkinExporter } from '@opentelemetry/exporter-zipkin'; @@ -9,13 +11,16 @@ const { registerInstrumentations } = require('@opentelemetry/instrumentation'); const { ExpressInstrumentation } = require('@opentelemetry/instrumentation-express'); const { HttpInstrumentation } = require('@opentelemetry/instrumentation-http'); -const provider: NodeTracerProvider = new NodeTracerProvider(); +const provider: NodeTracerProvider = new NodeTracerProvider({ + resource: new Resource({ + [ResourceAttributes.SERVICE_NAME]: 'getting-started', + }), +}); provider.addSpanProcessor( new SimpleSpanProcessor( new ZipkinExporter({ // For Jaeger, use the following line instead: // new JaegerExporter({ - serviceName: 'getting-started', // If you are running your tracing backend on another host, // you can point to it using the `url` parameter of the // exporter config. diff --git a/packages/opentelemetry-exporter-jaeger/README.md b/packages/opentelemetry-exporter-jaeger/README.md index 575689d9af..1c8bd0886a 100644 --- a/packages/opentelemetry-exporter-jaeger/README.md +++ b/packages/opentelemetry-exporter-jaeger/README.md @@ -64,7 +64,6 @@ set, the value set by the option in code is authoritative. import { JaegerExporter } from '@opentelemetry/exporter-jaeger'; const options = { - serviceName: 'my-service', tags: [], // optional // You can use the default UDPSender host: 'localhost', // optional diff --git a/packages/opentelemetry-exporter-zipkin/README.md b/packages/opentelemetry-exporter-zipkin/README.md index b5f8d58a85..91e321eb8a 100644 --- a/packages/opentelemetry-exporter-zipkin/README.md +++ b/packages/opentelemetry-exporter-zipkin/README.md @@ -30,7 +30,6 @@ const options = { 'my-header': 'header-value', }, url: 'your-zipkin-url', - serviceName: 'your-application-name', // optional interceptor getExportRequestHeaders: () => { return { diff --git a/packages/opentelemetry-sdk-node/README.md b/packages/opentelemetry-sdk-node/README.md index 81a3bacc4a..e9c57e0332 100644 --- a/packages/opentelemetry-sdk-node/README.md +++ b/packages/opentelemetry-sdk-node/README.md @@ -45,9 +45,7 @@ const { getNodeAutoInstrumentations, } = require("@opentelemetry/auto-instrumentations-node"); -const jaegerExporter = new JaegerExporter({ - serviceName: 'my-service', -}); +const jaegerExporter = new JaegerExporter(); const prometheusExporter = new PrometheusExporter({ startServer: true }); const sdk = new opentelemetry.NodeSDK({ From e488608ab11b7b310ebde8595c4086be3c09a995 Mon Sep 17 00:00:00 2001 From: Omkar Kirpan Date: Fri, 25 Jun 2021 15:31:42 +0530 Subject: [PATCH 5/5] style: fix lint errors --- examples/collector-exporter-node/tracing.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/examples/collector-exporter-node/tracing.js b/examples/collector-exporter-node/tracing.js index 73718925e6..03b968407e 100644 --- a/examples/collector-exporter-node/tracing.js +++ b/examples/collector-exporter-node/tracing.js @@ -3,8 +3,8 @@ const opentelemetry = require('@opentelemetry/api'); const { BasicTracerProvider, ConsoleSpanExporter, SimpleSpanProcessor } = require('@opentelemetry/tracing'); const { CollectorTraceExporter } = require('@opentelemetry/exporter-collector'); -import { Resource } from '@opentelemetry/resources'; -import { ResourceAttributes } from '@opentelemetry/semantic-conventions'; +const { Resource } = require('@opentelemetry/resources'); +const { ResourceAttributes } = require('@opentelemetry/semantic-conventions'); // const { CollectorTraceExporter } = require('@opentelemetry/exporter-collector-grpc'); // const { CollectorTraceExporter } = require('@opentelemetry/exporter-collector-proto');