Skip to content

Commit

Permalink
add mypy and make it happy
Browse files Browse the repository at this point in the history
  • Loading branch information
lmolkova committed Jun 13, 2024
1 parent 219b9d8 commit 390727b
Show file tree
Hide file tree
Showing 10 changed files with 65 additions and 53 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,7 @@
"""


@deprecated(
reason="Deprecated in favor of stable :py:const:`opentelemetry.semconv.attributes.error_attributes.ErrorTypeValues`."
)
@deprecated(reason="Deprecated in favor of stable :py:const:`opentelemetry.semconv.attributes.error_attributes.ErrorTypeValues`.") # type: ignore
class ErrorTypeValues(Enum):
OTHER: Final = "_OTHER"
"""A fallback error value to be used when the instrumentation doesn't define a custom value."""
Original file line number Diff line number Diff line change
Expand Up @@ -130,9 +130,7 @@ class HttpConnectionStateValues(Enum):
"""idle state."""


@deprecated(
reason="The attribute http.flavor is deprecated - Replaced by `network.protocol.name`"
)
@deprecated(reason="The attribute http.flavor is deprecated - Replaced by `network.protocol.name`") # type: ignore
class HttpFlavorValues(Enum):
HTTP_1_0: Final = "1.0"
"""HTTP/1.0."""
Expand All @@ -148,9 +146,7 @@ class HttpFlavorValues(Enum):
"""QUIC protocol."""


@deprecated(
reason="Deprecated in favor of stable :py:const:`opentelemetry.semconv.attributes.http_attributes.HttpRequestMethodValues`."
)
@deprecated(reason="Deprecated in favor of stable :py:const:`opentelemetry.semconv.attributes.http_attributes.HttpRequestMethodValues`.") # type: ignore
class HttpRequestMethodValues(Enum):
CONNECT: Final = "CONNECT"
"""CONNECT method."""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,8 @@
# 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.

from enum import Enum
# limitations under t
from typing from enum import Enum
from typing import Final

MESSAGING_BATCH_MESSAGE_COUNT: Final = "messaging.batch.message_count"
Expand All @@ -26,12 +25,6 @@
A unique identifier for the client that consumes or produces a message.
"""

MESSAGING_CLIENT_ID: Final = "messaging.client.id"
"""
TEST ME
"""


MESSAGING_DESTINATION_ANONYMOUS: Final = "messaging.destination.anonymous"
"""
A boolean that is true if the message destination is anonymous (could be unnamed or have auto-generated name).
Expand Down Expand Up @@ -319,3 +312,14 @@ class MessagingSystemValues(Enum):
"""RabbitMQ."""
ROCKETMQ: Final = "rocketmq"
"""Apache RocketMQ."""
e Bus."""
GCP_PUBSUB: Final = "gcp_pubsub"
"""Google Cloud Pub/Sub."""
JMS: Final = "jms"
"""Java Message Service."""
KAFKA: Final = "kafka"
"""Apache Kafka."""
RABBITMQ: Final = "rabbitmq"
"""RabbitMQ."""
ROCKETMQ: Final = "rocketmq"
""Apache RocketMQ."""
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,7 @@
"""


@deprecated(
reason="The attribute net.sock.family is deprecated - Split to `network.transport` and `network.type`"
)
@deprecated(reason="The attribute net.sock.family is deprecated - Split to `network.transport` and `network.type`") # type: ignore
class NetSockFamilyValues(Enum):
INET: Final = "inet"
"""IPv4 address."""
Expand All @@ -95,9 +93,7 @@ class NetSockFamilyValues(Enum):
"""Unix domain socket path."""


@deprecated(
reason="The attribute net.transport is deprecated - Replaced by `network.transport`"
)
@deprecated(reason="The attribute net.transport is deprecated - Replaced by `network.transport`") # type: ignore
class NetTransportValues(Enum):
IP_TCP: Final = "ip_tcp"
"""ip_tcp."""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -158,9 +158,7 @@ class NetworkIoDirectionValues(Enum):
"""receive."""


@deprecated(
reason="Deprecated in favor of stable :py:const:`opentelemetry.semconv.attributes.network_attributes.NetworkTransportValues`."
)
@deprecated(reason="Deprecated in favor of stable :py:const:`opentelemetry.semconv.attributes.network_attributes.NetworkTransportValues`.") # type: ignore
class NetworkTransportValues(Enum):
TCP: Final = "tcp"
"""TCP."""
Expand All @@ -172,9 +170,7 @@ class NetworkTransportValues(Enum):
"""Unix domain socket."""


@deprecated(
reason="Deprecated in favor of stable :py:const:`opentelemetry.semconv.attributes.network_attributes.NetworkTypeValues`."
)
@deprecated(reason="Deprecated in favor of stable :py:const:`opentelemetry.semconv.attributes.network_attributes.NetworkTypeValues`.") # type: ignore
class NetworkTypeValues(Enum):
IPV4: Final = "ipv4"
"""IPv4."""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,7 @@
"""


@deprecated(
reason="Deprecated in favor of stable :py:const:`opentelemetry.semconv.attributes.otel_attributes.OtelStatusCodeValues`."
)
@deprecated(reason="Deprecated in favor of stable :py:const:`opentelemetry.semconv.attributes.otel_attributes.OtelStatusCodeValues`.") # type: ignore
class OtelStatusCodeValues(Enum):
OK: Final = "OK"
"""The operation has been validated by an Application developer or Operator to have completed successfully."""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -201,9 +201,7 @@ class SystemProcessStatusValues(Enum):
"""defunct."""


@deprecated(
reason="The attribute system.processes.status is deprecated - Replaced by `system.process.status`"
)
@deprecated(reason="The attribute system.processes.status is deprecated - Replaced by `system.process.status`") # type: ignore
class SystemProcessesStatusValues(Enum):
RUNNING: Final = "running"
"""running."""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,7 @@
"""


@deprecated(
reason="Deprecated in favor of stable :py:const:`opentelemetry.semconv.attributes.telemetry_attributes.TelemetrySdkLanguageValues`."
)
@deprecated(reason="Deprecated in favor of stable :py:const:`opentelemetry.semconv.attributes.telemetry_attributes.TelemetrySdkLanguageValues`.") # type: ignore
class TelemetrySdkLanguageValues(Enum):
CPP: Final = "cpp"
"""cpp."""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,29 @@
# limitations under the License.


from typing import Callable, Final, Sequence
from typing import (
Callable,
Final,
Generator,
Iterable,
Optional,
Sequence,
Union,
)

from opentelemetry.metrics import (
CallbackOptions,
Counter,
Meter,
ObservableGauge,
Observation,
UpDownCounter,
)

CallbackT = Union[
Callable[[CallbackOptions], Iterable[Observation]],
Generator[Iterable[Observation], CallbackOptions, None],
]
PROCESS_CONTEXT_SWITCHES: Final = "process.context_switches"
"""
Number of times the process has been context switched
Expand Down Expand Up @@ -65,12 +79,12 @@ def create_process_cpu_time(meter: Meter) -> Counter:


def create_process_cpu_utilization(
meter: Meter, callback: Sequence[Callable]
meter: Meter, callbacks: Optional[Sequence[CallbackT]]
) -> ObservableGauge:
"""Difference in process.cpu.time since the last measurement, divided by the elapsed time and number of CPUs available to the process"""
return meter.create_observable_gauge(
name="process.cpu.utilization",
callback=callback,
callbacks=callbacks,
description="Difference in process.cpu.time since the last measurement, divided by the elapsed time and number of CPUs available to the process.",
unit="1",
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,29 @@
# limitations under the License.


from typing import Callable, Final, Sequence
from typing import (
Callable,
Final,
Generator,
Iterable,
Optional,
Sequence,
Union,
)

from opentelemetry.metrics import (
CallbackOptions,
Counter,
Meter,
ObservableGauge,
Observation,
UpDownCounter,
)

CallbackT = Union[
Callable[[CallbackOptions], Iterable[Observation]],
Generator[Iterable[Observation], CallbackOptions, None],
]
SYSTEM_CPU_FREQUENCY: Final = "system.cpu.frequency"
"""
Reports the current frequency of the CPU in Hz
Expand All @@ -31,12 +45,12 @@


def create_system_cpu_frequency(
meter: Meter, callback: Sequence[Callable]
meter: Meter, callbacks: Optional[Sequence[CallbackT]]
) -> ObservableGauge:
"""Reports the current frequency of the CPU in Hz"""
return meter.create_observable_gauge(
name="system.cpu.frequency",
callback=callback,
callbacks=callbacks,
description="Reports the current frequency of the CPU in Hz",
unit="{Hz}",
)
Expand Down Expand Up @@ -102,12 +116,12 @@ def create_system_cpu_time(meter: Meter) -> Counter:


def create_system_cpu_utilization(
meter: Meter, callback: Sequence[Callable]
meter: Meter, callbacks: Optional[Sequence[CallbackT]]
) -> ObservableGauge:
"""Difference in system.cpu.time since the last measurement, divided by the elapsed time and number of logical CPUs"""
return meter.create_observable_gauge(
name="system.cpu.utilization",
callback=callback,
callbacks=callbacks,
description="Difference in system.cpu.time since the last measurement, divided by the elapsed time and number of logical CPUs",
unit="1",
)
Expand Down Expand Up @@ -225,11 +239,11 @@ def create_system_filesystem_usage(meter: Meter) -> UpDownCounter:


def create_system_filesystem_utilization(
meter: Meter, callback: Sequence[Callable]
meter: Meter, callbacks: Optional[Sequence[CallbackT]]
) -> ObservableGauge:
return meter.create_observable_gauge(
name="system.filesystem.utilization",
callback=callback,
callbacks=callbacks,
description="",
unit="1",
)
Expand Down Expand Up @@ -302,11 +316,11 @@ def create_system_memory_usage(meter: Meter) -> UpDownCounter:


def create_system_memory_utilization(
meter: Meter, callback: Sequence[Callable]
meter: Meter, callbacks: Optional[Sequence[CallbackT]]
) -> ObservableGauge:
return meter.create_observable_gauge(
name="system.memory.utilization",
callback=callback,
callbacks=callbacks,
description="",
unit="1",
)
Expand Down Expand Up @@ -456,11 +470,11 @@ def create_system_paging_usage(meter: Meter) -> UpDownCounter:


def create_system_paging_utilization(
meter: Meter, callback: Sequence[Callable]
meter: Meter, callbacks: Optional[Sequence[CallbackT]]
) -> ObservableGauge:
return meter.create_observable_gauge(
name="system.paging.utilization",
callback=callback,
callbacks=callbacks,
description="",
unit="1",
)
Expand Down

0 comments on commit 390727b

Please sign in to comment.