haiway 0.19.0__py3-none-any.whl → 0.19.1__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -7,7 +7,7 @@ from logging import INFO as INFO_LOGGING
7
7
  from logging import WARNING as WARNING_LOGGING
8
8
  from logging import Logger, getLogger
9
9
  from types import TracebackType
10
- from typing import Any, Final, Protocol, Self, final, runtime_checkable
10
+ from typing import Any, Protocol, Self, final, runtime_checkable
11
11
 
12
12
  from haiway.context.identifier import ScopeIdentifier
13
13
  from haiway.state import State
@@ -15,10 +15,6 @@ from haiway.types import Missing
15
15
  from haiway.utils.formatting import format_str
16
16
 
17
17
  __all__ = (
18
- "DEBUG",
19
- "ERROR",
20
- "INFO",
21
- "WARNING",
22
18
  "Observability",
23
19
  "ObservabilityAttribute",
24
20
  "ObservabilityAttributesRecording",
@@ -40,11 +36,6 @@ class ObservabilityLevel(IntEnum):
40
36
  DEBUG = DEBUG_LOGGING
41
37
 
42
38
 
43
- ERROR: Final[int] = ObservabilityLevel.ERROR
44
- WARNING: Final[int] = ObservabilityLevel.WARNING
45
- INFO: Final[int] = ObservabilityLevel.INFO
46
- DEBUG: Final[int] = ObservabilityLevel.DEBUG
47
-
48
39
  type ObservabilityAttribute = (
49
40
  Sequence[str]
50
41
  | Sequence[float]
@@ -282,7 +273,7 @@ def _logger_observability(
282
273
  /,
283
274
  ) -> None:
284
275
  logger.log(
285
- DEBUG,
276
+ ObservabilityLevel.DEBUG,
286
277
  f"{scope.unique_name} Entering scope: {scope.label}",
287
278
  )
288
279
 
@@ -293,7 +284,7 @@ def _logger_observability(
293
284
  exception: BaseException | None,
294
285
  ) -> None:
295
286
  logger.log(
296
- DEBUG,
287
+ ObservabilityLevel.DEBUG,
297
288
  f"{scope.unique_name} Exiting scope: {scope.label}",
298
289
  exc_info=exception,
299
290
  )
@@ -410,7 +401,7 @@ class ObservabilityContext:
410
401
 
411
402
  except Exception as exc:
412
403
  cls.record_log(
413
- ERROR,
404
+ ObservabilityLevel.ERROR,
414
405
  f"Failed to record event: {type(event).__qualname__}",
415
406
  exception=exc,
416
407
  )
@@ -441,7 +432,7 @@ class ObservabilityContext:
441
432
 
442
433
  except Exception as exc:
443
434
  cls.record_log(
444
- ERROR,
435
+ ObservabilityLevel.ERROR,
445
436
  f"Failed to record metric: {metric}",
446
437
  exception=exc,
447
438
  )
@@ -466,7 +457,7 @@ class ObservabilityContext:
466
457
 
467
458
  except Exception as exc:
468
459
  cls.record_log(
469
- ERROR,
460
+ ObservabilityLevel.ERROR,
470
461
  "Failed to record attributes",
471
462
  exception=exc,
472
463
  )
haiway/helpers/tracing.py CHANGED
@@ -3,6 +3,7 @@ from collections.abc import Callable, Coroutine
3
3
  from typing import Any, cast, overload
4
4
 
5
5
  from haiway.context import ctx
6
+ from haiway.context.observability import ObservabilityLevel
6
7
  from haiway.types import MISSING
7
8
  from haiway.utils import mimic_function
8
9
  from haiway.utils.formatting import format_str
@@ -20,6 +21,7 @@ def traced[**Args, Result](
20
21
  @overload
21
22
  def traced[**Args, Result](
22
23
  *,
24
+ level: ObservabilityLevel = ObservabilityLevel.DEBUG,
23
25
  label: str,
24
26
  ) -> Callable[[Callable[Args, Result]], Callable[Args, Result]]: ...
25
27
 
@@ -28,6 +30,7 @@ def traced[**Args, Result](
28
30
  function: Callable[Args, Result] | None = None,
29
31
  /,
30
32
  *,
33
+ level: ObservabilityLevel = ObservabilityLevel.DEBUG,
31
34
  label: str | None = None,
32
35
  ) -> Callable[[Callable[Args, Result]], Callable[Args, Result]] | Callable[Args, Result]:
33
36
  def wrap(
@@ -40,6 +43,7 @@ def traced[**Args, Result](
40
43
  _traced_async(
41
44
  wrapped,
42
45
  label=label or wrapped.__name__,
46
+ level=level,
43
47
  ),
44
48
  )
45
49
 
@@ -47,6 +51,7 @@ def traced[**Args, Result](
47
51
  return _traced_sync(
48
52
  wrapped,
49
53
  label=label or wrapped.__name__,
54
+ level=level,
50
55
  )
51
56
 
52
57
  else: # do not trace on non debug runs
@@ -63,6 +68,7 @@ def _traced_sync[**Args, Result](
63
68
  function: Callable[Args, Result],
64
69
  /,
65
70
  label: str,
71
+ level: ObservabilityLevel,
66
72
  ) -> Callable[Args, Result]:
67
73
  def traced(
68
74
  *args: Args.args,
@@ -70,17 +76,20 @@ def _traced_sync[**Args, Result](
70
76
  ) -> Result:
71
77
  with ctx.scope(label):
72
78
  ctx.record(
79
+ level,
73
80
  attributes={
74
81
  f"[{idx}]": f"{arg}" for idx, arg in enumerate(args) if arg is not MISSING
75
- }
82
+ },
76
83
  )
77
84
  ctx.record(
78
- attributes={key: f"{arg}" for key, arg in kwargs.items() if arg is not MISSING}
85
+ level,
86
+ attributes={key: f"{arg}" for key, arg in kwargs.items() if arg is not MISSING},
79
87
  )
80
88
 
81
89
  try:
82
90
  result: Result = function(*args, **kwargs)
83
91
  ctx.record(
92
+ level,
84
93
  event="result",
85
94
  attributes={"value": format_str(result)},
86
95
  )
@@ -88,6 +97,7 @@ def _traced_sync[**Args, Result](
88
97
 
89
98
  except BaseException as exc:
90
99
  ctx.record(
100
+ level,
91
101
  event="result",
92
102
  attributes={"error": f"{type(exc)}: {exc}"},
93
103
  )
@@ -103,6 +113,7 @@ def _traced_async[**Args, Result](
103
113
  function: Callable[Args, Coroutine[Any, Any, Result]],
104
114
  /,
105
115
  label: str,
116
+ level: ObservabilityLevel,
106
117
  ) -> Callable[Args, Coroutine[Any, Any, Result]]:
107
118
  async def traced(
108
119
  *args: Args.args,
@@ -110,17 +121,20 @@ def _traced_async[**Args, Result](
110
121
  ) -> Result:
111
122
  with ctx.scope(label):
112
123
  ctx.record(
124
+ level,
113
125
  attributes={
114
126
  f"[{idx}]": f"{arg}" for idx, arg in enumerate(args) if arg is not MISSING
115
- }
127
+ },
116
128
  )
117
129
  ctx.record(
118
- attributes={key: f"{arg}" for key, arg in kwargs.items() if arg is not MISSING}
130
+ level,
131
+ attributes={key: f"{arg}" for key, arg in kwargs.items() if arg is not MISSING},
119
132
  )
120
133
 
121
134
  try:
122
135
  result: Result = await function(*args, **kwargs)
123
136
  ctx.record(
137
+ level,
124
138
  event="result",
125
139
  attributes={"value": format_str(result)},
126
140
  )
@@ -128,6 +142,7 @@ def _traced_async[**Args, Result](
128
142
 
129
143
  except BaseException as exc:
130
144
  ctx.record(
145
+ level,
131
146
  event="result",
132
147
  attributes={"error": f"{type(exc)}: {exc}"},
133
148
  )
@@ -67,6 +67,9 @@ def _object_str(
67
67
  other: object,
68
68
  /,
69
69
  ) -> str:
70
+ if not hasattr(other, "__dict__"):
71
+ return str(other)
72
+
70
73
  variables: ItemsView[str, Any] = vars(other).items()
71
74
 
72
75
  parts: list[str] = [f"┍━ {type(other).__name__}:"]
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: haiway
3
- Version: 0.19.0
3
+ Version: 0.19.1
4
4
  Summary: Framework for dependency injection and state management within structured concurrency model.
5
5
  Project-URL: Homepage, https://miquido.com
6
6
  Project-URL: Repository, https://github.com/miquido/haiway.git
@@ -4,7 +4,7 @@ haiway/context/__init__.py,sha256=eoxqxUmFtkWLhc_gH6tqax9m90tSDie-jiP1BHruTdk,11
4
4
  haiway/context/access.py,sha256=vTh5BlduAGBjqnVyTgTUt08DG6SrnAakweAfIDBqx-0,18838
5
5
  haiway/context/disposables.py,sha256=xE8RZYsYgXiOZY_TjWR7UiPG6dirna6y2LBZvMwTkIs,2588
6
6
  haiway/context/identifier.py,sha256=i6nO-tozps7iDnpS5Se7CRch7hh6z2akjZthutxHte8,3943
7
- haiway/context/observability.py,sha256=SiBKW7IEZVqxjAi4FCXSuOc-qVENYUa3s2E90M0UJ18,14502
7
+ haiway/context/observability.py,sha256=yvNEd2vL49hUARgaeSphQiYvmnsWO3apb_Y64GcgvH4,14354
8
8
  haiway/context/state.py,sha256=0oq7ctNO0urJd7rVzwwNtgpguoXuI6Tp1exfCsxrS2M,5981
9
9
  haiway/context/tasks.py,sha256=QOxFdjmMp4IYff0ihHElKLCQrcVksSJmxqTlOKfoH4o,2907
10
10
  haiway/context/types.py,sha256=WulPvpqUbI1vYyny-s2NItldDnk3zh1O-n_hGibFZRY,142
@@ -15,7 +15,7 @@ haiway/helpers/observability.py,sha256=VjT9ENMRrRck9QbYiMTtlf-BLwwf2d_wGMXbGFzdK
15
15
  haiway/helpers/retries.py,sha256=unssUKBDOENvquh6R4Ud65TuSKl4mTHgZ5N_b7mAYa4,7533
16
16
  haiway/helpers/throttling.py,sha256=U6HJvSzffw47730VeiXxXSW4VVxpDx48k0oIAOpL-O4,4115
17
17
  haiway/helpers/timeouted.py,sha256=_M8diuD_GN49pl5KQA5fMKn4iUHsUuhkDSatAwWXiK8,3331
18
- haiway/helpers/tracing.py,sha256=3-gbrAp4X-vNBbPGR6Li8BpMB0svH_PgRNJYopvYYXw,3752
18
+ haiway/helpers/tracing.py,sha256=6724MnXDqVcdWiQh0ggZRC3s5ZZSp6LEtLh3uze8SS0,4264
19
19
  haiway/opentelemetry/__init__.py,sha256=TV-1C14mDAtcHhFZ29ActFQdrGH6x5KuGV9w-JlKYJg,91
20
20
  haiway/opentelemetry/observability.py,sha256=ac0Jl0YFkpb4rbmwg3smPAs-QV_pcMjxSzelGhbwcsc,15332
21
21
  haiway/state/__init__.py,sha256=AaMqlMhO4zKS_XNevy3A7BHh5PxmguA-Sk_FnaNDY1Q,355
@@ -32,14 +32,14 @@ haiway/utils/__init__.py,sha256=HOylRgBEa0uNxEuPBupaJ28l4wEQiy98cGJi2Gtirr4,972
32
32
  haiway/utils/always.py,sha256=dd6jDQ1j4DpJjTKO1J2Tv5xS8X1LnMC4kQ0D7DtKUvw,1230
33
33
  haiway/utils/collections.py,sha256=pSBXhtLdhrLqmYo9YZEx716JI9S_sIztLJ5z5wi2d7Y,4162
34
34
  haiway/utils/env.py,sha256=gdZcQS9l82hKm4Jojy1vnE42s89JqPFbiYODAE8I2sA,5339
35
- haiway/utils/formatting.py,sha256=9OZUDa9aUSjzYj8pBwadfDwz7SjD9aB_vgn43RtGbrI,3042
35
+ haiway/utils/formatting.py,sha256=9BQR7Gc1dXbhwy_lSb8QSEDW2JlNtbS2O9eOznqELWQ,3108
36
36
  haiway/utils/freezing.py,sha256=QsThd6FJ8TgErio7pCsHSnUKmVQbHZu6iEDYiqvJteo,614
37
37
  haiway/utils/logs.py,sha256=NuwoqKQnMNi1FMIA91cVFnAPefUFeg3UIT50IOl3sJk,1571
38
38
  haiway/utils/mimic.py,sha256=L5AS4WEL2aPMZAQZlvLvRzHl0cipI7ivky60_eL4iwY,1822
39
39
  haiway/utils/noop.py,sha256=f54PSLHGEwCQNYXQHkPAW5NDE-tk5yjzkNL1pZj0TJQ,344
40
40
  haiway/utils/queue.py,sha256=YTvCn3wgSwLJiLqolMx44sa3304Xkv3tJG77gvfWnZs,4114
41
41
  haiway/utils/stream.py,sha256=Mjhy2S-ZDR1g_NsgS_nuBA8AgVbhrGXKvG3wjJ5mCJQ,2826
42
- haiway-0.19.0.dist-info/METADATA,sha256=VbWYq_-EAnn3JtAluszAzWZ7kVt3okHNNMrVvBh_sMk,4527
43
- haiway-0.19.0.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
44
- haiway-0.19.0.dist-info/licenses/LICENSE,sha256=3phcpHVNBP8jsi77gOO0E7rgKeDeu99Pi7DSnK9YHoQ,1069
45
- haiway-0.19.0.dist-info/RECORD,,
42
+ haiway-0.19.1.dist-info/METADATA,sha256=XJiRfIv8uKi-HLwfGAmFP9fxI7oiRSRaO1FCqNYBX5c,4527
43
+ haiway-0.19.1.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
44
+ haiway-0.19.1.dist-info/licenses/LICENSE,sha256=3phcpHVNBP8jsi77gOO0E7rgKeDeu99Pi7DSnK9YHoQ,1069
45
+ haiway-0.19.1.dist-info/RECORD,,