Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Conform metric field type to Singer spec #1574

Merged
merged 2 commits into from
Apr 3, 2023
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 docs/implementation/logging.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ version: 1
disable_existing_loggers: false
formatters:
metrics:
format: "{asctime} {message}"
format: "{asctime} {levelname} {message}"
style: "{"
handlers:
metrics:
Expand Down
14 changes: 11 additions & 3 deletions singer_sdk/metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import logging
import logging.config
import os
from dataclasses import asdict, dataclass, field
from dataclasses import dataclass, field
from pathlib import Path
from time import time
from typing import TYPE_CHECKING, Any, Generic, Mapping, TypeVar
Expand Down Expand Up @@ -79,7 +79,15 @@ def to_json(self) -> str:
Returns:
A JSON object.
"""
return json.dumps(asdict(self), default=str)
return json.dumps(
{
"type": self.metric_type,
"metric": self.metric.value,
"value": self.value,
"tags": self.tags,
},
default=str,
)


def log(logger: logging.Logger, point: Point) -> None:
Expand All @@ -89,7 +97,7 @@ def log(logger: logging.Logger, point: Point) -> None:
logger: An logger instance.
point: A measurement.
"""
logger.info("INFO METRIC: %s", point)
logger.info("METRIC: %s", point)


class Meter(metaclass=abc.ABCMeta):
Expand Down
4 changes: 2 additions & 2 deletions tests/core/test_metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ def test_record_counter(caplog: pytest.LogCaptureFixture):

for record in caplog.records:
assert record.levelname == "INFO"
assert record.msg == "INFO METRIC: %s"
assert record.msg == "METRIC: %s"
assert "test=1" in record.message

point: metrics.Point[int] = record.args[0]
Expand Down Expand Up @@ -89,7 +89,7 @@ def test_sync_timer(caplog: pytest.LogCaptureFixture):

record = caplog.records[0]
assert record.levelname == "INFO"
assert record.msg == "INFO METRIC: %s"
assert record.msg == "METRIC: %s"

point: metrics.Point[float] = record.args[0]
assert point.metric_type == "timer"
Expand Down