-
Notifications
You must be signed in to change notification settings - Fork 62
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: add metric sample and update READMEs throughout
- Loading branch information
Showing
8 changed files
with
1,063 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
# Overview | ||
|
||
This example shows how to use [@opentelemetry/sdk-metrics](https://github.com/open-telemetry/opentelemetry-js/tree/main/packages/opentelemetry-sdk-metrics) to instrument a simple Node.js application and export metrics to [Google Cloud Monitoring](https://cloud.google.com/monitoring/). | ||
|
||
## Installation | ||
|
||
```sh | ||
$ # from root of repo, build all packages | ||
$ npm install | ||
``` | ||
|
||
## Run the Application | ||
|
||
```sh | ||
$ # from this directory | ||
$ npm start | ||
``` | ||
|
||
## View metrics | ||
|
||
https://console.cloud.google.com//monitoring/metrics-explorer?project=your-project-id | ||
|
||
1. Select the Metric from the dropdown. You should see it under the resource "Generic Task": | ||
|
||
<img width="1584" alt="choose metric type" src="images/choose-metric-type.png?raw=true"/> | ||
|
||
2. View the timeseries: | ||
|
||
<img width="1584" alt="view timeseries" src="images/metric-timeseries.png?raw=true"/> | ||
|
||
|
||
## Useful links | ||
- For more information on OpenTelemetry, visit: <https://opentelemetry.io/> | ||
- For more information on metrics, visit: <https://opentelemetry.io/docs/concepts/signals/metrics/> | ||
|
||
## LICENSE | ||
|
||
Apache License 2.0 |
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
const { | ||
MeterProvider, | ||
PeriodicExportingMetricReader, | ||
} = require("@opentelemetry/sdk-metrics"); | ||
const { Resource } = require("@opentelemetry/resources"); | ||
const { | ||
MetricExporter, | ||
} = require("@google-cloud/opentelemetry-cloud-monitoring-exporter"); | ||
|
||
// Create MeterProvider | ||
const meterProvider = new MeterProvider({ | ||
resource: new Resource({ | ||
"service.name": "example-metric-service", | ||
"service.namespace": "samples", | ||
"service.instance.id": "12345", | ||
}), | ||
}); | ||
// Register the exporter | ||
meterProvider.addMetricReader( | ||
new PeriodicExportingMetricReader({ | ||
exportIntervalMillis: 10_000, | ||
exporter: new MetricExporter(), | ||
}) | ||
); | ||
|
||
// Create a meter | ||
const meter = meterProvider.getMeter("metrics-sample"); | ||
|
||
// Now, start recording data | ||
const counter = meter.createCounter("metric_name"); | ||
counter.add(10, { key: "value" }); | ||
|
||
// Wait for the metric to be exporter | ||
new Promise((resolve) => { | ||
setTimeout(resolve, 10_000); | ||
}); |
Oops, something went wrong.