Skip to content

Commit

Permalink
Merge branch 'main' into fix-default-grpc-collector-url
Browse files Browse the repository at this point in the history
  • Loading branch information
brunoluiz committed Jun 30, 2021
2 parents 3aa9ff3 + d28ddaa commit a1e63de
Show file tree
Hide file tree
Showing 41 changed files with 616 additions and 362 deletions.
13 changes: 7 additions & 6 deletions .github/workflows/unit-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,18 @@ jobs:
strategy:
fail-fast: false
matrix:
container: ["node:8", "node:10", "node:12", "node:14", "node:16"]
node_version: ["8", "10", "12", "14", "16"]
runs-on: ubuntu-latest
container:
image: ${{ matrix.container }}
env:
NPM_CONFIG_UNSAFE_PERM: true
steps:
- name: Checkout
uses: actions/checkout@v1

- uses: actions/setup-node@v2
with:
node-version: ${{ matrix.node_version }}

- name: restore lock files
uses: actions/cache@master # must use unreleased master to cache multiple paths
id: cache
Expand All @@ -33,12 +35,11 @@ jobs:
metapackages/*/package-lock.json
packages/*/package-lock.json
integration-tests/*/package-lock.json
key: ${{ runner.os }}-unit_test-${{ matrix.container }}-${{ hashFiles('**/package.json') }}
key: ${{ runner.os }}-unit_test-${{ matrix.node_version }}-${{ hashFiles('**/package.json') }}
- name: Install and Build (cache miss) 🔧
if: steps.cache.outputs.cache-hit != 'true'
run: |
npm install --ignore-scripts
chown -R 1001:121 "/github/home/.npm" # fix npm cache permissions for npm v7
npx lerna bootstrap --no-ci
npm run compile
Expand All @@ -53,7 +54,7 @@ jobs:
run: npm run test
- name: Report Coverage
run: npm run codecov
if: ${{ matrix.container == 'node:14' }}
if: ${{ matrix.node_version == '14' }}
browser-tests:
runs-on: ubuntu-latest
container:
Expand Down
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
2 changes: 2 additions & 0 deletions examples/opentracing-shim/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@
"@opentelemetry/exporter-zipkin": "0.22.0",
"@opentelemetry/instrumentation": "0.22.0",
"@opentelemetry/node": "0.22.0",
"@opentelemetry/resources": "0.22.0",
"@opentelemetry/semantic-conventions": "0.22.0",
"@opentelemetry/shim-opentracing": "0.22.0",
"@opentelemetry/tracing": "0.22.0",
"opentracing": "^0.14.4"
Expand Down
2 changes: 1 addition & 1 deletion examples/opentracing-shim/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ async function handleRequest(req, res) {

res.writeHead(200, { 'Content-Type': 'application/json' });
res.write(
JSON.stringify({ status: 'OK', traceId: span.spanContext().toTraceId() }),
JSON.stringify({ status: 'OK', traceId: span.context().toTraceId() }),
);

res.end();
Expand Down
16 changes: 8 additions & 8 deletions examples/opentracing-shim/shim.js
Original file line number Diff line number Diff line change
@@ -1,33 +1,33 @@
'use strict';

const { registerInstrumentations } = require('@opentelemetry/instrumentation');
const { ResourceAttributes } = require('@opentelemetry/semantic-conventions');
const { Resource } = require('@opentelemetry/resources');
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 provider = new NodeTracerProvider();
const provider = new NodeTracerProvider({
resource: new Resource({ [ResourceAttributes.SERVICE_NAME]: serviceName }),
});

provider.addSpanProcessor(new SimpleSpanProcessor(getExporter(serviceName)));
// Initialize the OpenTelemetry APIs to use the NodeTracerProvider bindings
provider.register();

registerInstrumentations({
});

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

function getExporter(serviceName) {
function getExporter() {
const type = process.env.EXPORTER.toLowerCase() || 'jaeger';

if (type.startsWith('z')) {
return new ZipkinExporter({ serviceName });
return new ZipkinExporter();
}

return new JaegerExporter({ serviceName, flushInterval: 100 });
return new JaegerExporter();
}

exports.shim = shim;
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
14 changes: 10 additions & 4 deletions getting-started/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,11 @@ To create traces on NodeJS, you need `@opentelemetry/node`, `@opentelemetry/core

```sh
$ npm install \
@opentelemetry/core \
@opentelemetry/api \
@opentelemetry/node \
@opentelemetry/instrumentation-http \
@opentelemetry/instrumentation-express
@opentelemetry/instrumentation-express \
@opentelemetry/instrumentation-grpc
```

#### Initialize a global tracer
Expand Down Expand Up @@ -124,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
Loading

0 comments on commit a1e63de

Please sign in to comment.