11import time
2- from typing import Optional
2+ from typing import Dict , Optional , Mapping
33
44from opentelemetry .exporter .prometheus import PrometheusMetricReader
55from opentelemetry .metrics import (
1313from opentelemetry .sdk .metrics .view import View , ExplicitBucketHistogramAggregation
1414from opentelemetry .sdk .metrics .export import MetricReader
1515from opentelemetry .sdk .resources import Resource
16+ from opentelemetry .util .types import AttributeValue
1617
1718from ..exemplar import get_exemplar
1819from .types import Result
3334)
3435from ..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
3750class 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