Skip to content

Commit

Permalink
fix: service.name resource attribute (#2290)
Browse files Browse the repository at this point in the history
Co-authored-by: Daniel Dyla <[email protected]>
  • Loading branch information
OmkarKirpan and dyladan authored Jun 25, 2021
1 parent 6fb4fd1 commit de6cee9
Show file tree
Hide file tree
Showing 15 changed files with 86 additions and 48 deletions.
9 changes: 7 additions & 2 deletions examples/basic-tracer-node/index.js
Original file line number Diff line number Diff line change
@@ -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));
Expand Down
6 changes: 5 additions & 1 deletion examples/collector-exporter-node/metrics.js
Original file line number Diff line number Diff line change
Expand Up @@ -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', {
Expand Down
9 changes: 7 additions & 2 deletions examples/collector-exporter-node/tracing.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
const opentelemetry = require('@opentelemetry/api');
const { BasicTracerProvider, ConsoleSpanExporter, SimpleSpanProcessor } = require('@opentelemetry/tracing');
const { CollectorTraceExporter } = require('@opentelemetry/exporter-collector');
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');

Expand All @@ -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();
Expand Down
16 changes: 9 additions & 7 deletions examples/grpc-js/tracer.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand All @@ -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));
Expand Down
16 changes: 9 additions & 7 deletions examples/grpc/tracer.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand All @@ -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));
Expand Down
16 changes: 9 additions & 7 deletions examples/http/tracer.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand All @@ -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));
Expand Down
16 changes: 9 additions & 7 deletions examples/https/tracer.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand All @@ -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));
Expand Down
9 changes: 6 additions & 3 deletions examples/tracer-web/examples/metrics/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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', {
Expand Down
9 changes: 7 additions & 2 deletions getting-started/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
9 changes: 7 additions & 2 deletions getting-started/traced-example/tracing.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
4 changes: 3 additions & 1 deletion getting-started/ts-example/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -134,14 +134,16 @@ import { HttpInstrumentation } from '@opentelemetry/instrumentation-http';

const provider: NodeTracerProvider = new NodeTracerProvider({
logLevel: LogLevel.ERROR,
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.
Expand Down
9 changes: 7 additions & 2 deletions getting-started/ts-example/traced-example/tracing.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -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.
Expand Down
1 change: 0 additions & 1 deletion packages/opentelemetry-exporter-jaeger/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 0 additions & 1 deletion packages/opentelemetry-exporter-zipkin/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ const options = {
'my-header': 'header-value',
},
url: 'your-zipkin-url',
serviceName: 'your-application-name',
// optional interceptor
getExportRequestHeaders: () => {
return {
Expand Down
4 changes: 1 addition & 3 deletions packages/opentelemetry-sdk-node/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand Down

0 comments on commit de6cee9

Please sign in to comment.