Skip to content

Commit

Permalink
Merge branch 'main' into node18_unit_test
Browse files Browse the repository at this point in the history
  • Loading branch information
Flarna committed May 3, 2022
2 parents bf79e36 + ddb0775 commit 341bfd5
Show file tree
Hide file tree
Showing 26 changed files with 282 additions and 186 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/unit-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ jobs:
packages/*/package-lock.json
experimental/packages/*/node_modules
experimental/packages/*/package-lock.json
key: node-tests-${{ runner.os }}-${{ matrix.node_version }}-${{ hashFiles('package.json', 'packages/*/package.json', 'experimental/packages/*/package.json') }}-04142022
key: node-tests-${{ runner.os }}-${{ matrix.node_version }}-${{ hashFiles('package.json', 'packages/*/package.json', 'experimental/packages/*/package.json') }}-04292022

- name: Bootstrap
run: |
Expand Down Expand Up @@ -72,7 +72,7 @@ jobs:
packages/*/package-lock.json
experimental/packages/*/node_modules
experimental/packages/*/package-lock.json
key: browser-tests-${{ runner.os }}-${{ hashFiles('package.json', 'packages/*/package.json', 'experimental/packages/*/package.json') }}-04142022
key: browser-tests-${{ runner.os }}-${{ hashFiles('package.json', 'packages/*/package.json', 'experimental/packages/*/package.json') }}-04292022

- name: Bootstrap
run: |
Expand Down Expand Up @@ -112,7 +112,7 @@ jobs:
packages/*/package-lock.json
experimental/packages/*/node_modules
experimental/packages/*/package-lock.json
key: webworker-tests-${{ runner.os }}-${{ hashFiles('package.json', 'packages/*/package.json', 'experimental/packages/*/package.json') }}-04142022
key: webworker-tests-${{ runner.os }}-${{ hashFiles('package.json', 'packages/*/package.json', 'experimental/packages/*/package.json') }}-04292022

- name: Bootstrap
run: |
Expand Down
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ All notable changes to this project will be documented in this file.

* feat(ConsoleSpanExporter): export span links [#2917](https://github.com/open-telemetry/opentelemetry-js/pull/2917) @trentm
* feat: warn when hooked module is already loaded [#2926](https://github.com/open-telemetry/opentelemetry-js/pull/2926) @nozik
* feat: implement OSDetector [#2927](https://github.com/open-telemetry/opentelemetry-js/pull/2927) @rauno56
* feat: implement HostDetector [#2921](https://github.com/open-telemetry/opentelemetry-js/pull/2921) @rauno56

### :bug: (Bug Fix)

Expand All @@ -28,6 +30,7 @@ All notable changes to this project will be documented in this file.
* fix: sanitize attributes inputs [#2881](https://github.com/open-telemetry/opentelemetry-js/pull/2881) @legendecas
* fix: support earlier API versions [#2892](https://github.com/open-telemetry/opentelemetry-js/pull/2892) @dyladan
* fix: support extract one digit '0' in jaeger traceFlag [#2905](https://github.com/open-telemetry/opentelemetry-js/issues/2905) @shmilyoo
* fix(resources): extend ResourceAttributes interface to comply with spec [#2924](https://github.com/open-telemetry/opentelemetry-js/pull/2924) @blumamir

### :books: (Refine Doc)

Expand Down
Binary file removed examples/prometheus/images/prom-counter.png
Binary file not shown.
Binary file removed examples/prometheus/images/prom-updowncounter.png
Binary file not shown.
32 changes: 0 additions & 32 deletions examples/prometheus/index.js

This file was deleted.

7 changes: 7 additions & 0 deletions experimental/examples/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
module.exports = {
"env": {
"mocha": true,
"node": true
},
...require('../../eslint.config.js')
}
File renamed without changes.
File renamed without changes.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
38 changes: 38 additions & 0 deletions experimental/examples/prometheus/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
'use strict';

const { DiagConsoleLogger, DiagLogLevel, diag } = require('@opentelemetry/api');
const { MeterProvider } = require('@opentelemetry/sdk-metrics-base');
const { PrometheusExporter } = require('@opentelemetry/exporter-prometheus');

// Optional and only needed to see the internal diagnostic logging (during development)
diag.setLogger(new DiagConsoleLogger(), DiagLogLevel.DEBUG);

const { endpoint, port } = PrometheusExporter.DEFAULT_OPTIONS;

const exporter = new PrometheusExporter({}, () => {
console.log(
`prometheus scrape endpoint: http://localhost:${port}${endpoint}`,
);
});

// Creates MeterProvider and installs the exporter as a MetricReader
const meterProvider = new MeterProvider();
meterProvider.addMetricReader(exporter);
const meter = meterProvider.getMeter('example-prometheus');

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

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

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

// Record metrics
setInterval(() => {
requestCounter.add(1, attributes);
upDownCounter.add(Math.random() > 0.5 ? 1 : -1, attributes);
}, 1000);
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "prometheus-example",
"version": "0.25.0",
"version": "0.28.0",
"description": "Example of using @opentelemetry/sdk-metrics-base and @opentelemetry/exporter-prometheus",
"main": "index.js",
"scripts": {
Expand All @@ -10,7 +10,7 @@
"license": "Apache-2.0",
"dependencies": {
"@opentelemetry/api": "^1.0.2",
"@opentelemetry/exporter-prometheus": "0.25.0",
"@opentelemetry/sdk-metrics-base": "0.25.0"
"@opentelemetry/exporter-prometheus": "0.28.0",
"@opentelemetry/sdk-metrics-base": "0.28.0"
}
}
File renamed without changes.

This file was deleted.

This file was deleted.

This file was deleted.

Binary file not shown.
Binary file not shown.
Binary file not shown.

This file was deleted.

52 changes: 52 additions & 0 deletions packages/opentelemetry-resources/src/detectors/HostDetector.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/*
* 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.
*/

import { SemanticResourceAttributes } from '@opentelemetry/semantic-conventions';
import { Resource } from '../Resource';
import { Detector, ResourceAttributes } from '../types';
import { ResourceDetectionConfig } from '../config';
import { arch, hostname } from 'os';

/**
* HostDetector detects the resources related to the host current process is
* running on. Currently only non-cloud-based attributes are included.
*/
class HostDetector implements Detector {
async detect(_config?: ResourceDetectionConfig): Promise<Resource> {
const attributes: ResourceAttributes = {
[SemanticResourceAttributes.HOST_NAME]: hostname(),
[SemanticResourceAttributes.HOST_ARCH]: this._normalizeArch(arch()),
};
return new Resource(attributes);
}

private _normalizeArch(nodeArchString: string): string {
// Maps from https://nodejs.org/api/os.html#osarch to arch values in spec:
// https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/resource/semantic_conventions/host.md
switch (nodeArchString) {
case 'arm':
return 'arm32';
case 'ppc':
return 'ppc32';
case 'x64':
return 'amd64';
default:
return nodeArchString;
}
}
}

export const hostDetector = new HostDetector();
50 changes: 50 additions & 0 deletions packages/opentelemetry-resources/src/detectors/OSDetector.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/*
* 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.
*/

import { SemanticResourceAttributes } from '@opentelemetry/semantic-conventions';
import { Resource } from '../Resource';
import { Detector, ResourceAttributes } from '../types';
import { ResourceDetectionConfig } from '../config';
import { platform, release } from 'os';

/**
* OSDetector detects the resources related to the operating system (OS) on
* which the process represented by this resource is running.
*/
class OSDetector implements Detector {
async detect(_config?: ResourceDetectionConfig): Promise<Resource> {
const attributes: ResourceAttributes = {
[SemanticResourceAttributes.OS_TYPE]: this._normalizeType(platform()),
[SemanticResourceAttributes.OS_VERSION]: release(),
};
return new Resource(attributes);
}

private _normalizeType(nodePlatform: string): string {
// Maps from https://nodejs.org/api/os.html#osplatform to arch values in spec:
// https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/resource/semantic_conventions/os.md
switch (nodePlatform) {
case 'sunos':
return 'solaris';
case 'win32':
return 'windows';
default:
return nodePlatform;
}
}
}

export const osDetector = new OSDetector();
Loading

0 comments on commit 341bfd5

Please sign in to comment.