Skip to content

Commit 47f5f2e

Browse files
author
あで
committed
Fix typing
1 parent 5c61050 commit 47f5f2e

File tree

1 file changed

+15
-7
lines changed

1 file changed

+15
-7
lines changed

src/autometrics/tracker/opentelemetry.py

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import time
2-
from typing import Optional
2+
from typing import Dict, Optional, Mapping
33

44
from opentelemetry.exporter.prometheus import PrometheusMetricReader
55
from opentelemetry.metrics import (
@@ -13,6 +13,7 @@
1313
from opentelemetry.sdk.metrics.view import View, ExplicitBucketHistogramAggregation
1414
from opentelemetry.sdk.metrics.export import MetricReader
1515
from opentelemetry.sdk.resources import Resource
16+
from opentelemetry.util.types import AttributeValue
1617

1718
from ..exemplar import get_exemplar
1819
from .types import Result
@@ -33,6 +34,18 @@
3334
)
3435
from ..settings import get_settings
3536

37+
LabelValue = AttributeValue
38+
Attributes = Dict[str, LabelValue]
39+
40+
41+
def get_resource_attrs():
42+
attrs: Attributes = {}
43+
if get_settings()["service_name"] is not None:
44+
attrs[ResourceAttributes.SERVICE_NAME] = get_settings()["service_name"]
45+
if get_settings()["version"] is not None:
46+
attrs[ResourceAttributes.SERVICE_VERSION] = get_settings()["version"]
47+
return attrs
48+
3649

3750
class OpenTelemetryTracker:
3851
"""Tracker for OpenTelemetry."""
@@ -51,12 +64,7 @@ def __init__(self, reader: Optional[MetricReader] = None):
5164
boundaries=get_settings()["histogram_buckets"]
5265
),
5366
)
54-
attrs = {}
55-
if get_settings()["service_name"] is not None:
56-
attrs[ResourceAttributes.SERVICE_NAME] = get_settings()["service_name"]
57-
if get_settings()["version"] is not None:
58-
attrs[ResourceAttributes.SERVICE_VERSION] = get_settings()["version"]
59-
resource = Resource.create(attrs)
67+
resource = Resource.create(get_resource_attrs())
6068
readers = [reader or PrometheusMetricReader("")]
6169
meter_provider = MeterProvider(
6270
views=[view],

0 commit comments

Comments
 (0)