|
| 1 | +# Copyright The OpenTelemetry Authors |
| 2 | +# |
| 3 | +# Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | +# you may not use this file except in compliance with the License. |
| 5 | +# You may obtain a copy of the License at |
| 6 | +# |
| 7 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | +# |
| 9 | +# Unless required by applicable law or agreed to in writing, software |
| 10 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | +# See the License for the specific language governing permissions and |
| 13 | +# limitations under the License. |
| 14 | + |
| 15 | +from opentelemetry.metrics import ( |
| 16 | + Counter, |
| 17 | + Histogram, |
| 18 | + Meter, |
| 19 | + UpDownCounter, |
| 20 | + ObservableGauge, |
| 21 | +) |
| 22 | +from typing import Callable, Sequence |
| 23 | + |
| 24 | +class AspnetcoreMetrics: |
| 25 | + |
| 26 | + """ |
| 27 | + Number of exceptions caught by exception handling middleware |
| 28 | + """ |
| 29 | + @staticmethod |
| 30 | + def create_aspnetcore_diagnostics_exceptions(meter: Meter) -> Counter: |
| 31 | + return meter.create_counter( |
| 32 | + name="aspnetcore.diagnostics.exceptions", |
| 33 | + description="Number of exceptions caught by exception handling middleware.", |
| 34 | + unit="{exception}", |
| 35 | + ) |
| 36 | + |
| 37 | + |
| 38 | + """ |
| 39 | + Number of requests that are currently active on the server that hold a rate limiting lease |
| 40 | + """ |
| 41 | + @staticmethod |
| 42 | + def create_aspnetcore_rate_limiting_active_request_leases(meter: Meter) -> UpDownCounter: |
| 43 | + return meter.create_up_down_counter( |
| 44 | + name="aspnetcore.rate_limiting.active_request_leases", |
| 45 | + description="Number of requests that are currently active on the server that hold a rate limiting lease.", |
| 46 | + unit="{request}", |
| 47 | + ) |
| 48 | + |
| 49 | + |
| 50 | + """ |
| 51 | + Number of requests that are currently queued, waiting to acquire a rate limiting lease |
| 52 | + """ |
| 53 | + @staticmethod |
| 54 | + def create_aspnetcore_rate_limiting_queued_requests(meter: Meter) -> UpDownCounter: |
| 55 | + return meter.create_up_down_counter( |
| 56 | + name="aspnetcore.rate_limiting.queued_requests", |
| 57 | + description="Number of requests that are currently queued, waiting to acquire a rate limiting lease.", |
| 58 | + unit="{request}", |
| 59 | + ) |
| 60 | + |
| 61 | + |
| 62 | + """ |
| 63 | + The time the request spent in a queue waiting to acquire a rate limiting lease |
| 64 | + """ |
| 65 | + @staticmethod |
| 66 | + def create_aspnetcore_rate_limiting_request_time_in_queue(meter: Meter) -> Histogram: |
| 67 | + return meter.create_histogram( |
| 68 | + name="aspnetcore.rate_limiting.request.time_in_queue", |
| 69 | + description="The time the request spent in a queue waiting to acquire a rate limiting lease.", |
| 70 | + unit="s", |
| 71 | + ) |
| 72 | + |
| 73 | + |
| 74 | + """ |
| 75 | + The duration of rate limiting lease held by requests on the server |
| 76 | + """ |
| 77 | + @staticmethod |
| 78 | + def create_aspnetcore_rate_limiting_request_lease_duration(meter: Meter) -> Histogram: |
| 79 | + return meter.create_histogram( |
| 80 | + name="aspnetcore.rate_limiting.request_lease.duration", |
| 81 | + description="The duration of rate limiting lease held by requests on the server.", |
| 82 | + unit="s", |
| 83 | + ) |
| 84 | + |
| 85 | + |
| 86 | + """ |
| 87 | + Number of requests that tried to acquire a rate limiting lease |
| 88 | + """ |
| 89 | + @staticmethod |
| 90 | + def create_aspnetcore_rate_limiting_requests(meter: Meter) -> Counter: |
| 91 | + return meter.create_counter( |
| 92 | + name="aspnetcore.rate_limiting.requests", |
| 93 | + description="Number of requests that tried to acquire a rate limiting lease.", |
| 94 | + unit="{request}", |
| 95 | + ) |
| 96 | + |
| 97 | + |
| 98 | + """ |
| 99 | + Number of requests that were attempted to be matched to an endpoint |
| 100 | + """ |
| 101 | + @staticmethod |
| 102 | + def create_aspnetcore_routing_match_attempts(meter: Meter) -> Counter: |
| 103 | + return meter.create_counter( |
| 104 | + name="aspnetcore.routing.match_attempts", |
| 105 | + description="Number of requests that were attempted to be matched to an endpoint.", |
| 106 | + unit="{match_attempt}", |
| 107 | + ) |
0 commit comments