Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion dynatrace_extension/__about__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@
# SPDX-License-Identifier: MIT


__version__ = "1.4.1"
__version__ = "1.5.0"
8 changes: 8 additions & 0 deletions dynatrace_extension/sdk/extension.py
Original file line number Diff line number Diff line change
Expand Up @@ -457,6 +457,7 @@ def report_metric(
key: str,
value: Union[float, str, int, SummaryStat],
dimensions: Optional[Dict[str, str]] = None,
device_address: Optional[str] = None,
techrule: Optional[str] = None,
timestamp: Optional[datetime] = None,
metric_type: MetricType = MetricType.GAUGE,
Expand All @@ -472,6 +473,7 @@ def report_metric(
key: The metric key, must follow the MINT specification
value: The metric value, can be a simple value or a SummaryStat
dimensions: A dictionary of dimensions
device_address: The address of a monitored device/endpoint which produced the metric
techrule: The technology rule string set by self.techrule setter.
timestamp: The timestamp of the metric, defaults to the current time
metric_type: The type of the metric, defaults to MetricType.GAUGE
Expand All @@ -483,6 +485,12 @@ def report_metric(
if "dt.techrule.id" not in dimensions:
dimensions["dt.techrule.id"] = techrule

if device_address:
if not dimensions:
dimensions = {}
if "device.address" not in dimensions:
dimensions["device.address"] = device_address

if metric_type == MetricType.COUNT and timestamp is None:
# We must report a timestamp for count metrics
timestamp = datetime.now()
Expand Down
9 changes: 9 additions & 0 deletions tests/sdk/test_extension.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,15 @@ def test_add_metric(self):
self.assertEqual(len(extension._metrics), 1)
self.assertTrue(extension._metrics[0].startswith("my_metric gauge,1"))

def test_add_metric_with_device_address(self):
extension = Extension()
extension.logger = MagicMock()
extension._running_in_sim = True
extension.report_metric("my_metric", 1, device_address="10.10.10.10")
print(extension._metrics[0])
self.assertEqual(len(extension._metrics), 1)
self.assertTrue(extension._metrics[0].startswith('my_metric,device.address="10.10.10.10" gauge,1'))

def test_metrics_flushed(self):
extension = Extension()
extension._running_in_sim = True
Expand Down