Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
ocelotl committed Sep 30, 2021
1 parent aaba2b6 commit bce8eed
Show file tree
Hide file tree
Showing 7 changed files with 129 additions and 447 deletions.
11 changes: 2 additions & 9 deletions opentelemetry-api/src/opentelemetry/metrics/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,6 @@


class MeterProvider(ABC):
def __init__(self):
super().__init__()

@abstractmethod
def get_meter(
self,
Expand Down Expand Up @@ -268,9 +265,7 @@ def create_observable_gauge(self, *args, **kwargs) -> ObservableGauge:
def create_observable_up_down_counter(
self, *args, **kwargs
) -> ObservableUpDownCounter:
return self._meter.create_observable_up_down_counter(
*args, **kwargs
)
return self._meter.create_observable_up_down_counter(*args, **kwargs)


class _DefaultMeter(Meter):
Expand All @@ -284,9 +279,7 @@ def create_up_down_counter(
super().create_up_down_counter(
name, unit=unit, description=description
)
return DefaultUpDownCounter(
name, unit=unit, description=description
)
return DefaultUpDownCounter(name, unit=unit, description=description)

def create_observable_counter(
self, name, callback, unit="", description=""
Expand Down
216 changes: 0 additions & 216 deletions opentelemetry-api/src/opentelemetry/metrics/meter.py

This file was deleted.

112 changes: 112 additions & 0 deletions opentelemetry-sdk/src/opentelemetry/sdk/metrics/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
# 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
#
# http://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.

# pylint: disable=function-redefined,too-many-ancestors

from opentelemetry.metrics import Meter, MeterProvider
from opentelemetry.metrics.measurement import Measurement
from opentelemetry.sdk.metrics.instrument import (
Counter,
Histogram,
ObservableCounter,
ObservableGauge,
ObservableUpDownCounter,
UpDownCounter,
)
from opentelemetry.sdk.resources import Resource
from opentelemetry.util.types import Attributes


class Measurement(Measurement):
def __init__(self, value, **attributes: Attributes):
self._value = value
self._attributes = attributes
super().__init__(value, **attributes)

@property
def value(self):
return self._value

@property
def attributes(self):
return self._attributes


class Meter(Meter):
def __init__(self, name, version=None, schema_url=None):

super().__init__(name, version=version, schema_url=schema_url)

def create_counter(self, name, unit=None, description=None) -> Counter:
# pylint: disable=abstract-class-instantiated
return Counter(name, unit=unit, description=description)

def create_up_down_counter(
self, name, unit=None, description=None
) -> UpDownCounter:
# pylint: disable=abstract-class-instantiated
return UpDownCounter(name, unit=unit, description=description)

def create_observable_counter(
self, name, callback, unit=None, description=None
) -> ObservableCounter:
# pylint: disable=abstract-class-instantiated
return ObservableCounter(
name, callback, unit=unit, description=description
)

def create_histogram(self, name, unit=None, description=None) -> Histogram:
# pylint: disable=abstract-class-instantiated
return Histogram(name, unit=unit, description=description)

def create_observable_gauge(
self, name, callback, unit=None, description=None
) -> ObservableGauge:
# pylint: disable=abstract-class-instantiated
return ObservableGauge(
name, callback, unit=unit, description=description
)

def create_observable_up_down_counter(
self, name, callback, unit=None, description=None
) -> ObservableUpDownCounter:
# pylint: disable=abstract-class-instantiated
return ObservableUpDownCounter(
name, callback, unit=unit, description=description
)


class MeterProvider(MeterProvider):
def __init__(self, resource=None):
if resource is None:
self._resource = Resource()
else:
self._resource = resource

def add_pipeline(self):
pass

def configure_views(self):
pass

def configure_timint(self):
pass

def get_meter(
self,
name,
version=None,
schema_url=None,
) -> Meter:
return Meter(name, version=version, schema_url=schema_url)
Loading

0 comments on commit bce8eed

Please sign in to comment.