Skip to content

Commit 764d317

Browse files
authored
Metrics Implementation (#160)
* Create functions Comments for Meter More comments Add more comments Fix typos * fix lint * Fix lint * fix typing * Remove options, constructors, seperate labels * Consistent naming for float and int * Abstract time series * Use ABC * Fix typo * Fix docs * seperate measure classes * Add examples * fix lint * Update to RFC 0003 * Add spancontext, measurebatch * Fix docs * Fix comments * fix lint * fix lint * fix lint * skip examples * white space * fix spacing * fix imports * fix imports * LabelValues to str * Black formatting * fix isort * Remove aggregation * Fix names * Remove aggregation from docs * Fix lint * metric changes * Typing * Fix lint * Fix lint * Add space * Fix lint * fix comments * handle, recordbatch * docs * Update recordbatch * black * Fix typo * remove ValueType * fix lint * sdk * metrics * example * counter * Tests * Address comments * ADd tests * Fix typing and examples * black * fix lint * remove override * Fix tests * mypy * fix lint * fix type * fix typing * fix tests * isort * isort * isort * isort * noop * lint * lint * fix tuple typing * fix type * black * address comments * fix type * fix lint * remove imports * default tests * fix lint * usse sequence * remove ellipses * remove ellipses * black * Fix typo * fix example * fix type * fix type * address comments
1 parent 74f2cec commit 764d317

File tree

12 files changed

+780
-336
lines changed

12 files changed

+780
-336
lines changed

docs/opentelemetry.metrics.handle.rst

Lines changed: 0 additions & 5 deletions
This file was deleted.

docs/opentelemetry.metrics.rst

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,6 @@
11
opentelemetry.metrics package
22
=============================
33

4-
Submodules
5-
----------
6-
7-
.. toctree::
8-
9-
opentelemetry.metrics.handle
10-
114
Module contents
125
---------------
136

opentelemetry-api/src/opentelemetry/metrics/examples/raw.py renamed to examples/opentelemetry-example-app/src/opentelemetry_example_app/metrics_example.py

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -11,26 +11,29 @@
1111
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
14+
#
15+
"""
16+
This module serves as an example for a simple application using metrics
17+
"""
1418

15-
# pylint: skip-file
1619
from opentelemetry import metrics
20+
from opentelemetry.sdk.metrics import Counter, Meter
1721

18-
METER = metrics.Meter()
19-
MEASURE = metrics.create_measure(
20-
"idle_cpu_percentage",
21-
"cpu idle over time",
22-
"percentage",
23-
metrics.ValueType.FLOAT,
24-
["environment"],
22+
metrics.set_preferred_meter_implementation(lambda _: Meter())
23+
meter = metrics.meter()
24+
counter = meter.create_metric(
25+
"available memory",
26+
"available memory",
27+
"bytes",
28+
int,
29+
Counter,
30+
("environment",),
2531
)
2632

27-
# Metrics sent to some exporter
28-
MEASURE_METRIC_TESTING = MEASURE.get_handle("Testing")
29-
MEASURE_METRIC_STAGING = MEASURE.get_handle("Staging")
30-
31-
# record individual measures
32-
STATISTIC = 100
33-
MEASURE_METRIC_STAGING.record(STATISTIC)
33+
label_values = ("staging",)
34+
counter_handle = counter.get_handle(label_values)
35+
counter_handle.add(100)
36+
meter.record_batch(label_values, [(counter, 50)])
37+
print(counter_handle.data)
3438

35-
# Batch recording
36-
METER.record_batch([tuple(MEASURE_METRIC_STAGING, STATISTIC)])
39+
# TODO: exporters

0 commit comments

Comments
 (0)