uranusjr commented on code in PR #67527:
URL: https://github.com/apache/airflow/pull/67527#discussion_r3301548857
##########
airflow-core/src/airflow/models/callback.py:
##########
@@ -161,6 +162,17 @@ def get_metric_info(self, status: CallbackState, result:
Any) -> dict:
# Remove the context (if exists) to keep the tags simple
tags["kwargs"] = {k: v for k, v in tags["kwargs"].items() if k !=
"context"}
+ # Metric backends (statsd, OpenTelemetry) require tag values to be
primitives.
+ # OTel's aggregation key is built via
``frozenset(attributes.items())``, which
+ # raises ``TypeError: unhashable type: 'dict'`` if a value is a
dict/list. The
+ # callback's ``result`` (passed in from a user callback) and
``kwargs`` are both
+ # frequently dicts, so coerce any non-primitive tag value to a JSON
string before
+ # returning. Using ``default=str`` so values like ``datetime`` fall
back cleanly.
+ tags = {
+ k: v if isinstance(v, (str, int, float, bool)) or v is None else
json.dumps(v, default=str)
Review Comment:
Probably want to add `sort_keys=True` to have deterministic output?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]