Skip to content

Commit

Permalink
Collector split (#1446)
Browse files Browse the repository at this point in the history
* chore: removing submodule protos from exporter-collector

* chore: adding submodule opentelemetry-proto to exporter collector

* chore: fixing submodule path

* chore: updating proto to version v0.4.0

* chore: splitting exporter collector into 3 packages - depending on transport layer, updated examples, fixed the metrics collector for proto, fixed bug for label

* chore: fixing bug with controller when shutting down

* chore: ignored files

* chore: fixing submodule links

* chore: lint fixes - seems like some latest updates forcing extend to be in new line

* chore: lint space

* chore: fixing test when waiting to load proto files
  • Loading branch information
obecny authored Aug 24, 2020
1 parent 2a8555f commit fb06b5b
Show file tree
Hide file tree
Showing 101 changed files with 4,172 additions and 1,789 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -78,3 +78,7 @@ package.json.lerna_backup

# VsCode configs
.vscode/

#IDEA
.idea
*.iml
7 changes: 5 additions & 2 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
[submodule "packages/opentelemetry-exporter-collector/src/platform/node/protos"]
path = packages/opentelemetry-exporter-collector/src/platform/node/protos
[submodule "packages/opentelemetry-exporter-collector-grpc/protos"]
path = packages/opentelemetry-exporter-collector-grpc/protos
url = /~https://github.com/open-telemetry/opentelemetry-proto.git
[submodule "packages/opentelemetry-exporter-collector-proto/protos"]
path = packages/opentelemetry-exporter-collector-proto/protos
url = /~https://github.com/open-telemetry/opentelemetry-proto.git
8 changes: 6 additions & 2 deletions examples/collector-exporter-node/metrics.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,21 @@
'use strict';

const { ConsoleLogger, LogLevel } = require('@opentelemetry/core');
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 metricExporter = new CollectorMetricExporter({
serviceName: 'basic-metric-service',
// logger: new ConsoleLogger(LogLevel.DEBUG),
// url: 'http://localhost:55681/v1/metrics',
logger: new ConsoleLogger(LogLevel.DEBUG),
});

const meter = new MeterProvider({
exporter: metricExporter,
interval: 1000,
}).getMeter('example-prometheus');
}).getMeter('example-exporter-collector');

const requestCounter = meter.createCounter('requests', {
description: 'Example of a Counter',
Expand Down
2 changes: 2 additions & 0 deletions examples/collector-exporter-node/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@
"@opentelemetry/api": "^0.10.2",
"@opentelemetry/core": "^0.10.2",
"@opentelemetry/exporter-collector": "^0.10.2",
"@opentelemetry/exporter-collector-grpc": "^0.10.2",
"@opentelemetry/exporter-collector-proto": "^0.10.2",
"@opentelemetry/metrics": "^0.10.2",
"@opentelemetry/tracing": "^0.10.2"
},
Expand Down
6 changes: 3 additions & 3 deletions examples/collector-exporter-node/tracing.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,16 @@
const opentelemetry = require('@opentelemetry/api');
// const { ConsoleLogger, LogLevel} = require('@opentelemetry/core');
const { BasicTracerProvider, ConsoleSpanExporter, SimpleSpanProcessor } = require('@opentelemetry/tracing');
const { CollectorTraceExporter, CollectorProtocolNode } = require('@opentelemetry/exporter-collector');
const { CollectorTraceExporter } = require('@opentelemetry/exporter-collector');
// const { CollectorTraceExporter } = require('@opentelemetry/exporter-collector-grpc');
// const { CollectorTraceExporter } = require('@opentelemetry/exporter-collector-proto');

const exporter = new CollectorTraceExporter({
serviceName: 'basic-service',
// logger: new ConsoleLogger(LogLevel.DEBUG),
// headers: {
// foo: 'bar'
// },
protocolNode: CollectorProtocolNode.HTTP_PROTO,
// protocolNode: CollectorProtocolNode.HTTP_JSON,
});

const provider = new BasicTracerProvider();
Expand Down
36 changes: 36 additions & 0 deletions examples/tracer-web/examples/metrics/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<!DOCTYPE html>
<html lang="en">

<head>
<meta charset="utf-8">
<title>Metrics Example</title>
<base href="/">

<!--
https://www.w3.org/TR/trace-context/
Set the `traceparent` in the server's HTML template code. It should be
dynamically generated server side to have the server's request trace Id,
a parent span Id that was set on the server's request span, and the trace
flags to indicate the server's sampling decision
(01 = sampled, 00 = notsampled).
'{version}-{traceId}-{spanId}-{sampleDecision}'
-->
<!-- <meta name="traceparent" content="00-ab42124a3c573678d4d8b21ba52df3bf-d21f7bc17caa5aba-01">-->

<meta name="viewport" content="width=device-width, initial-scale=1">
</head>

<body>
Example of using metrics with Collector Exporter
<script type="text/javascript" src="metrics.js"></script>
<br/>
<button id="startBtn">Start metrics</button>
<button id="stopBtn">Stop metrics</button>
<br/>

If you run the collector from example "opentelemetry-exporter-collector" you should see traces at: <br/>
<a href="http://localhost:9090/graph?g0.range_input=1m&g0.expr=requests&g0.tab=0/" target="_blank">http://localhost:9090/</a>

</body>

</html>
51 changes: 51 additions & 0 deletions examples/tracer-web/examples/metrics/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
'use strict';

const { ConsoleLogger, LogLevel } = require('@opentelemetry/core');
const { CollectorMetricExporter } = require('@opentelemetry/exporter-collector');
const { MeterProvider } = require('@opentelemetry/metrics');

const metricExporter = new CollectorMetricExporter({
serviceName: 'basic-metric-service',
logger: new ConsoleLogger(LogLevel.DEBUG),
});

let interval;
let meter;

function stopMetrics() {
console.log('STOPPING METRICS');
clearInterval(interval);
meter.shutdown();
}

function startMetrics() {
console.log('STARTING METRICS');
meter = new MeterProvider({
exporter: metricExporter,
interval: 1000,
}).getMeter('example-exporter-collector');

const requestCounter = meter.createCounter('requests', {
description: 'Example of a Counter',
});

const upDownCounter = meter.createUpDownCounter('test_up_down_counter', {
description: 'Example of a UpDownCounter',
});

const labels = { pid: process.pid, environment: 'staging' };

interval = setInterval(() => {
requestCounter.bind(labels).add(1);
upDownCounter.bind(labels).add(Math.random() > 0.5 ? 1 : -1);
}, 1000);
}

const addClickEvents = () => {
const startBtn = document.getElementById('startBtn');
const stopBtn = document.getElementById('stopBtn');
startBtn.addEventListener('click', startMetrics);
stopBtn.addEventListener('click', stopMetrics);
};

window.addEventListener('load', addClickEvents);
5 changes: 3 additions & 2 deletions examples/tracer-web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,10 @@
"@opentelemetry/context-zone": "^0.10.2",
"@opentelemetry/core": "^0.10.2",
"@opentelemetry/exporter-collector": "^0.10.2",
"@opentelemetry/plugin-document-load": "^0.6.1",
"@opentelemetry/metrics": "^0.10.2",
"@opentelemetry/plugin-document-load": "^0.9.0",
"@opentelemetry/plugin-fetch": "^0.10.2",
"@opentelemetry/plugin-user-interaction": "^0.6.1",
"@opentelemetry/plugin-user-interaction": "^0.9.0",
"@opentelemetry/plugin-xml-http-request": "^0.10.2",
"@opentelemetry/tracing": "^0.10.2",
"@opentelemetry/web": "^0.10.2"
Expand Down
1 change: 1 addition & 0 deletions examples/tracer-web/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ const common = {
mode: 'development',
entry: {
'document-load': 'examples/document-load/index.js',
metrics: 'examples/metrics/index.js',
fetch: 'examples/fetch/index.js',
'xml-http-request': 'examples/xml-http-request/index.js',
'user-interaction': 'examples/user-interaction/index.js',
Expand Down
12 changes: 8 additions & 4 deletions packages/opentelemetry-api/src/metrics/NoopMeter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -131,14 +131,16 @@ export class NoopMetric<T> implements UnboundMetric<T> {
}
}

export class NoopCounterMetric extends NoopMetric<BoundCounter>
export class NoopCounterMetric
extends NoopMetric<BoundCounter>
implements Counter {
add(value: number, labels: Labels) {
this.bind(labels).add(value);
}
}

export class NoopValueRecorderMetric extends NoopMetric<BoundValueRecorder>
export class NoopValueRecorderMetric
extends NoopMetric<BoundValueRecorder>
implements ValueRecorder {
record(
value: number,
Expand All @@ -156,7 +158,8 @@ export class NoopValueRecorderMetric extends NoopMetric<BoundValueRecorder>
}
}

export class NoopBaseObserverMetric extends NoopMetric<BoundBaseObserver>
export class NoopBaseObserverMetric
extends NoopMetric<BoundBaseObserver>
implements BaseObserver {
observation() {
return {
Expand All @@ -166,7 +169,8 @@ export class NoopBaseObserverMetric extends NoopMetric<BoundBaseObserver>
}
}

export class NoopBatchObserverMetric extends NoopMetric<void>
export class NoopBatchObserverMetric
extends NoopMetric<void>
implements BatchObserver {}

export class NoopBoundCounter implements BoundCounter {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ import {
import { BaseAbstractPlugin } from '../BaseAbstractPlugin';

/** This class represent the base to patch plugin. */
export abstract class BasePlugin<T> extends BaseAbstractPlugin<T>
export abstract class BasePlugin<T>
extends BaseAbstractPlugin<T>
implements Plugin<T> {
enable(
moduleExports: T,
Expand Down
3 changes: 2 additions & 1 deletion packages/opentelemetry-core/src/platform/node/BasePlugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ import * as path from 'path';
import { BaseAbstractPlugin } from '../BaseAbstractPlugin';

/** This class represent the base to patch plugin. */
export abstract class BasePlugin<T> extends BaseAbstractPlugin<T>
export abstract class BasePlugin<T>
extends BaseAbstractPlugin<T>
implements Plugin<T> {
enable(
moduleExports: T,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
build
8 changes: 8 additions & 0 deletions packages/opentelemetry-exporter-collector-grpc/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
module.exports = {
"env": {
"mocha": true,
"commonjs": true,
"node": true,
},
...require('../../eslint.config.js')
}
4 changes: 4 additions & 0 deletions packages/opentelemetry-exporter-collector-grpc/.npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
/bin
/coverage
/doc
/test
Loading

0 comments on commit fb06b5b

Please sign in to comment.