Skip to content

Commit

Permalink
Merge branch 'main' into fix/4130
Browse files Browse the repository at this point in the history
  • Loading branch information
pichlermarc authored Sep 21, 2023
2 parents 10d585a + f2fc0d8 commit edc402d
Show file tree
Hide file tree
Showing 19 changed files with 249 additions and 22 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ For experimental package changes, see the [experimental CHANGELOG](experimental/

### :bug: (Bug Fix)

* fix(sdk-metrics): allow instrument names to contain '/' [#4155](https://github.com/open-telemetry/opentelemetry-js/pull/4155)
* fix(sdk-metrics): do not report empty scopes and metrics [#4135](https://github.com/open-telemetry/opentelemetry-js/pull/4135) @pichlermarc
* Instruments that were created, but did not have measurements will not be exported anymore
* Meters (Scopes) that were created, but did not have any instruments with measurements under them will not be exported anymore.
Expand All @@ -21,6 +22,8 @@ For experimental package changes, see the [experimental CHANGELOG](experimental/

### :house: (Internal)

* test: added a performance benchmark test for span creation [#4105](https://github.com/open-telemetry/opentelemetry-js/pull/4105)

## 1.17.0

### :bug: (Bug Fix)
Expand Down
8 changes: 6 additions & 2 deletions experimental/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,15 @@ All notable changes to experimental packages in this project will be documented
### :boom: Breaking Change

* fix(exporter-logs-otlp-proto): change OTLPLogExporter to OTLPLogExporter [#4140](https://github.com/open-telemetry/opentelemetry-js/pull/4140) @Vunovati
* fix(sdk-node): remove explicit dependency on @opentelemetry/exporter-jaeger
* '@opentelemetry/exporter-jaeger' is no longer be a dependency of this package. To continue using '@opentelemetry/exporter-jaeger', please install it manually.
* NOTE: `@opentelemetry/exporter-jaeger` is deprecated, consider switching to one of the alternatives described [here](https://www.npmjs.com/package/@opentelemetry/exporter-jaeger)

### :rocket: (Enhancement)

* feat(exporter-metrics-otlp-proto): add esm build [#4099](https://github.com/open-telemetry/opentelemetry-js/pull/4099) @pichlermarc
* feat(opencensus-shim): implement OpenCensus metric producer [#4066](https://github.com/open-telemetry/opentelemetry-js/pull/4066) @aabmass

### :bug: (Bug Fix)

### :books: (Refine Doc)
Expand Down Expand Up @@ -44,12 +50,10 @@ All notable changes to experimental packages in this project will be documented
### :rocket: (Enhancement)

* feat: update PeriodicExportingMetricReader and PrometheusExporter to accept optional metric producers [#4077](https://github.com/open-telemetry/opentelemetry-js/pull/4077) @aabmass
* feat(opencensus-shim): implement OpenCensus metric producer [#4066](https://github.com/open-telemetry/opentelemetry-js/pull/4066) @aabmass

### :bug: (Bug Fix)

* fix(exporter-logs-otlp-http): add @opentelemetry/api-logs as dependency
* fix(sdk-node): remove explicit dependency on @opentelemetry/exporter-jaeger.

## 0.41.2

Expand Down
10 changes: 10 additions & 0 deletions experimental/examples/opencensus-shim/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ The example has:
- Root Spans (on client), instrumented with OpenCensus's HTTP instrumentation
- Child Span from a remote parent (on server), instrumented with OpenCensus's HTTP instrumentation
- Another Child Span created in the server representing some work being done, instrumented manually with OpenTelemetry.
- Server metrics coming from OpenCensus's HTTP instrumentation, available through the
OpenTelemetry's Prometheus exporter.

## Installation

Expand Down Expand Up @@ -64,6 +66,14 @@ Go to Jaeger with your browser <http://localhost:16686/> and click on the "Servi

<p align="center"><img src="./images/jaeger-trace.png"/></p>

## Check the Prometheus metrics

Load the Prometheus metrics endpoint of the server at <http://localhost:9464/metrics> in your
browser. You should see the `opencensus_io_http_server_*` related metrics in
the output.

<p align="center"><img src="./images/prom-metrics.png"/></p>

## Useful links

- For more information on OpenTelemetry, visit: <https://opentelemetry.io/>
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions experimental/examples/opencensus-shim/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,13 @@
},
"dependencies": {
"@opencensus/core": "0.1.0",
"@opencensus/instrumentation-http": "0.1.0",
"@opencensus/nodejs-base": "0.1.0",
"@opentelemetry/api": "1.6.0",
"@opentelemetry/exporter-prometheus": "0.43.0",
"@opentelemetry/exporter-trace-otlp-grpc": "0.43.0",
"@opentelemetry/resources": "1.17.0",
"@opentelemetry/sdk-metrics": "1.17.0",
"@opentelemetry/sdk-trace-node": "1.17.0",
"@opentelemetry/semantic-conventions": "1.17.0",
"@opentelemetry/shim-opencensus": "0.43.0"
Expand Down
2 changes: 2 additions & 0 deletions experimental/examples/opencensus-shim/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ const setup = require('./setup');
const utils = require('./utils');
const { trace } = require('@opentelemetry/api');

const oc = require('@opencensus/core');

setup('opencensus-shim-example-server');
const http = require('http');

Expand Down
49 changes: 38 additions & 11 deletions experimental/examples/opencensus-shim/setup.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,37 +15,64 @@
*/
'use strict';

const { DiagConsoleLogger, diag, DiagLogLevel } = require('@opentelemetry/api');
const { diag, metrics } = require('@opentelemetry/api');
const {
NodeTracerProvider,
BatchSpanProcessor,
} = require('@opentelemetry/sdk-trace-node');
const { MeterProvider } = require('@opentelemetry/sdk-metrics');
const {
OTLPTraceExporter,
} = require('@opentelemetry/exporter-trace-otlp-grpc');
const { PrometheusExporter } = require('@opentelemetry/exporter-prometheus');
const { Resource } = require('@opentelemetry/resources');
const {
SemanticResourceAttributes,
} = require('@opentelemetry/semantic-conventions');
const { OpenCensusMetricProducer } = require('@opentelemetry/shim-opencensus');
const instrumentationHttp = require('@opencensus/instrumentation-http');
const { TracingBase } = require('@opencensus/nodejs-base');
const oc = require('@opencensus/core');

module.exports = function setup(serviceName) {
const tracing = require('@opencensus/nodejs-base');
/**
* You can alternatively just use the @opentelemetry/nodejs package directly:
*
* ```js
* const tracing = require('@opencensus/nodejs');
* ```
*/
const tracing = new TracingBase(['http']);
tracing.tracer = new oc.CoreTracer();

diag.setLogger(new DiagConsoleLogger(), { logLevel: DiagLogLevel.ALL });
const provider = new NodeTracerProvider({
resource: new Resource({
[SemanticResourceAttributes.SERVICE_NAME]: serviceName,
}),
const resource = new Resource({
[SemanticResourceAttributes.SERVICE_NAME]: serviceName,
});
provider.addSpanProcessor(
const tracerProvider = new NodeTracerProvider({ resource });
tracerProvider.addSpanProcessor(
new BatchSpanProcessor(new OTLPTraceExporter(), {
scheduledDelayMillis: 5000,
})
);
provider.register();
tracerProvider.register();

const meterProvider = new MeterProvider({ resource });
meterProvider.addMetricReader(
new PrometheusExporter({
metricProducers: [
new OpenCensusMetricProducer({
openCensusMetricProducerManager:
oc.Metrics.getMetricProducerManager(),
}),
],
})
);
metrics.setGlobalMeterProvider(meterProvider);

// Start OpenCensus tracing
tracing.start({ samplingRate: 1, logger: diag });
tracing.start({ samplingRate: 1, logger: diag, stats: oc.globalStats });
// Register OpenCensus HTTP stats views
instrumentationHttp.registerAllViews(oc.globalStats);

return provider;
return tracerProvider;
};
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,20 @@
"version": "0.43.0",
"description": "OpenTelemetry Collector Metrics Exporter allows user to send collected metrics to the OpenTelemetry Collector using protobuf over HTTP",
"main": "build/src/index.js",
"module": "build/esm/index.js",
"esnext": "build/esnext/index.js",
"types": "build/src/index.d.ts",
"repository": "open-telemetry/opentelemetry-js",
"scripts": {
"prepublishOnly": "npm run compile",
"compile": "tsc --build",
"clean": "tsc --build --clean",
"compile": "tsc --build tsconfig.json tsconfig.esm.json tsconfig.esnext.json",
"clean": "tsc --build --clean tsconfig.json tsconfig.esm.json tsconfig.esnext.json",
"lint": "eslint . --ext .ts",
"lint:fix": "eslint . --ext .ts --fix",
"tdd": "npm run test -- --watch-extensions ts --watch",
"test": "nyc ts-mocha -p tsconfig.json 'test/**/*.test.ts'",
"test": "nyc ts-mocha -p tsconfig.json 'test/**/*.test.ts' --exclude 'test/browser/**/*.ts'",
"version": "node ../../../scripts/version-update.js",
"watch": "tsc -w",
"watch": "tsc --build --watch tsconfig.json tsconfig.esm.json tsconfig.esnext.json",
"precompile": "cross-var lerna run version --scope $npm_package_name --include-dependencies",
"prewatch": "npm run precompile",
"peer-api-check": "node ../../../scripts/peer-api-check.js",
Expand All @@ -35,6 +37,12 @@
"node": ">=14"
},
"files": [
"build/esm/**/*.js",
"build/esm/**/*.js.map",
"build/esm/**/*.d.ts",
"build/esnext/**/*.js",
"build/esnext/**/*.js.map",
"build/esnext/**/*.d.ts",
"build/src/**/*.js",
"build/src/**/*.js.map",
"build/src/**/*.d.ts",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
{
"extends": "../../../tsconfig.base.esm.json",
"compilerOptions": {
"outDir": "build/esm",
"rootDir": "src",
"tsBuildInfoFile": "build/esm/tsconfig.esm.tsbuildinfo"
},
"include": [
"src/**/*.ts"
],
"references": [
{
"path": "../../../api"
},
{
"path": "../../../packages/opentelemetry-core"
},
{
"path": "../../../packages/opentelemetry-resources"
},
{
"path": "../../../packages/sdk-metrics"
},
{
"path": "../opentelemetry-exporter-metrics-otlp-http"
},
{
"path": "../otlp-exporter-base"
},
{
"path": "../otlp-proto-exporter-base"
},
{
"path": "../otlp-transformer"
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
{
"extends": "../../../tsconfig.base.esnext.json",
"compilerOptions": {
"outDir": "build/esnext",
"rootDir": "src",
"tsBuildInfoFile": "build/esnext/tsconfig.esnext.tsbuildinfo"
},
"include": [
"src/**/*.ts"
],
"references": [
{
"path": "../../../api"
},
{
"path": "../../../packages/opentelemetry-core"
},
{
"path": "../../../packages/opentelemetry-resources"
},
{
"path": "../../../packages/sdk-metrics"
},
{
"path": "../opentelemetry-exporter-metrics-otlp-http"
},
{
"path": "../otlp-exporter-base"
},
{
"path": "../otlp-proto-exporter-base"
},
{
"path": "../otlp-transformer"
}
]
}
23 changes: 21 additions & 2 deletions experimental/packages/shim-opencensus/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@ More details are available in the [OpenCensus Compatibility Specification](https
npm install --save @opentelemetry/shim-opencensus
```

## Usage
## Tracing usage

### Installing the shim's require-in-the-middle hook

This is the recommended way to use the shim.
This is the recommended way to use the shim for tracing.

This package provides a `require-in-the-middle` hook which replaces OpenCensus's `CoreTracer`
class with a shim implementation that writes to the OpenTelemetry API. This will cause all
Expand Down Expand Up @@ -72,6 +72,25 @@ tracer.startRootSpan({name: 'main'}, rootSpan => {
});
```

## Metrics usage

OpenCensus metrics can be collected and sent to an OpenTelemetry exporter by providing the
`OpenCensusMetricProducer` to your `MetricReader`. For example, to export OpenCensus metrics
through the OpenTelemetry Prometheus exporter:

```js
meterProvider.addMetricReader(
new PrometheusExporter({
metricProducers: [
new OpenCensusMetricProducer({
openCensusMetricProducerManager:
oc.Metrics.getMetricProducerManager(),
}),
],
})
);
```

## Example

See [examples/opencensus-shim](https://github.com/open-telemetry/opentelemetry-js/tree/main/experimental/examples/opencensus-shim) for a short example.
Expand Down
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
"test:browser": "lerna run test:browser",
"test:webworker": "lerna run test:webworker",
"test:backcompat": "lerna run test:backcompat",
"test:bench": "lerna run test:bench",
"bootstrap": "lerna bootstrap --hoist --nohoist='zone.js'",
"changelog": "lerna-changelog",
"codecov": "lerna run codecov",
Expand Down Expand Up @@ -65,8 +66,9 @@
"devDependencies": {
"@typescript-eslint/eslint-plugin": "5.59.11",
"@typescript-eslint/parser": "5.59.11",
"benchmark": "2.1.4",
"eslint": "8.44.0",
"eslint-config-prettier": "8.5.0",
"eslint-config-prettier": "9.0.0",
"eslint-plugin-header": "3.1.1",
"eslint-plugin-node": "11.1.0",
"eslint-plugin-prettier": "5.0.0",
Expand Down
1 change: 1 addition & 0 deletions packages/opentelemetry-sdk-trace-base/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
"test": "nyc ts-mocha -p tsconfig.json 'test/**/*.test.ts' --exclude 'test/browser/**/*.ts'",
"test:browser": "karma start --single-run",
"test:webworker": "karma start karma.worker.js --single-run",
"test:bench": "node test/performance/benchmark/index.js",
"tdd": "npm run tdd:node",
"tdd:node": "npm run test -- --watch-extensions ts --watch",
"tdd:browser": "karma start",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/*
* Copyright The OpenTelemetry Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

require('./span');
Loading

0 comments on commit edc402d

Please sign in to comment.