Skip to content

Commit ccdb8cd

Browse files
committed
Tidy up OTEL plugin typing
Explicitly annotate, and return a copy of the configuration instead of a mutable reference.
1 parent 24de0d4 commit ccdb8cd

1 file changed

Lines changed: 10 additions & 4 deletions

File tree

src/workflows/util/zocalo/configuration.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
from __future__ import annotations
22

3+
from typing import ClassVar, TypedDict
4+
35
from marshmallow import fields
46
from zocalo.configuration import PluginSchema
57

@@ -11,21 +13,25 @@
1113
class OTEL:
1214
"""A Zocalo configuration plugin to pre-populate OTELTracing config defaults"""
1315

16+
class _OTELConfig(TypedDict, total=False):
17+
endpoint: str
18+
timeout: int
19+
20+
# Store configuration for access by services
21+
config: ClassVar[_OTELConfig] = {}
22+
1423
class Schema(PluginSchema):
1524
host = fields.Str(required=True)
1625
port = fields.Int(required=True)
1726
timeout = fields.Int(required=False, load_default=10)
1827

19-
# Store configuration for access by services
20-
config = {}
21-
2228
@staticmethod
2329
def activate(configuration):
2430
# Build the full endpoint URL
2531
endpoint = f"https://{configuration['host']}:{configuration['port']}/v1/traces"
2632
OTEL.config["endpoint"] = endpoint
2733
OTEL.config["timeout"] = configuration.get("timeout", 10)
28-
return OTEL.config
34+
return dict(OTEL.config)
2935

3036

3137
class Stomp:

0 commit comments

Comments
 (0)