Skip to content

Commit

Permalink
Merge 62eb14f into 27bbb11
Browse files Browse the repository at this point in the history
  • Loading branch information
svetlanabrennan authored Dec 17, 2021
2 parents 27bbb11 + 62eb14f commit c9471f3
Show file tree
Hide file tree
Showing 8 changed files with 57 additions and 14 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"env": {
"node": true
},
"extends": "airbnb-base",
"parserOptions": {
"sourceType": "script"
},
"rules": {
"strict": ["error", "global"],
"no-use-before-define": ["error", "nofunc"],
"no-console": "off",
"import/no-unresolved": "off",
"no-unused-vars": ["error", { "argsIgnorePattern": "^_" }]
},
"ignorePatterns": "**/*_pb.js"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# OpenTelemetry JavaScript Examples

This directory contains examples of how to run real applications with OpenTelemetry JavaScript.

## Work in Progress Examples

These examples are using work in progress metrics packages.

|Name | Description | Complexity Level |
------------- | ------------- | ------------ |
|[metrics](metrics/) | Basic metrics collection and exports those metrics to a Prometheus compatible endpoint | Beginner |

## Contributing

Please see [CONTRIBUTING.md](https://github.com/open-telemetry/opentelemetry-js/blob/main/CONTRIBUTING.md) for instructions on how to contribute.

## LICENSE

Apache License 2.0
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,23 @@ const meter = new MeterProvider({
interval: 2000,
}).getMeter('example-meter');

meter.createObservableGauge('cpu_core_usage', async (observableResult) => { // this callback is called once per each interval
await new Promise((resolve) => {
setTimeout(() => { resolve(); }, 50);
});
observableResult.observe(getRandomValue(), { core: '1' });
observableResult.observe(getRandomValue(), { core: '2' });
}, {
description: 'Example of a sync observable gauge with callback',
// async callback - for operation that needs to wait for value
meter.createObservableGauge('cpu_core_usage', {
description: 'Example of an async observable gauge with callback',
}, async (observableResult) => {
const value = await getAsyncValue();
observableResult.observe(value, { core: '1' });
observableResult.observe(value, { core: '2' });
});

function getRandomValue() {
return Math.random();
function getAsyncValue() {
return new Promise((resolve) => {
setTimeout(()=> {
resolve(Math.random());
}, 100);
});
}

setInterval(function(){
console.log("simulating an app being kept open")
}, 5000);
File renamed without changes
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "example-metrics",
"private": true,
"version": "0.25.0",
"version": "0.27.0",
"description": "Example of using @opentelemetry/sdk-metrics-base",
"main": "index.js",
"scripts": {
Expand All @@ -27,9 +27,9 @@
},
"dependencies": {
"@opentelemetry/api": "^1.0.2",
"@opentelemetry/core": "0.25.0",
"@opentelemetry/exporter-prometheus": "0.25.0",
"@opentelemetry/sdk-metrics-base": "0.25.0"
"@opentelemetry/core": "^1.0.1",
"@opentelemetry/exporter-prometheus": "^0.27.0",
"@opentelemetry/sdk-metrics-base": "^0.27.0"
},
"homepage": "https://github.com/open-telemetry/opentelemetry-js#readme"
}

0 comments on commit c9471f3

Please sign in to comment.