Skip to content

Commit 4d8277e

Browse files
committed
feat: remove metadata
1 parent 7f41918 commit 4d8277e

4 files changed

Lines changed: 3 additions & 43 deletions

File tree

src/duron/_core/context.py

Lines changed: 1 addition & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
import asyncio
44
import contextvars
5-
from contextlib import contextmanager
65
from contextvars import ContextVar
76
from random import Random
87
from typing import TYPE_CHECKING, cast
@@ -29,15 +28,14 @@
2928
from duron.typing import inspect_function
3029

3130
if TYPE_CHECKING:
32-
from collections.abc import Callable, Coroutine, Generator, Mapping
31+
from collections.abc import Callable, Coroutine
3332
from contextvars import Token
3433
from types import TracebackType
3534

3635
from duron._core.signal import Signal, SignalWriter
3736
from duron._core.stream import Stream, StreamWriter
3837
from duron._decorator.durable import DurableFn
3938
from duron._loop import EventLoop
40-
from duron.codec import JSONValue
4139
from duron.typing import TypeHint
4240

4341
_T = TypeVar("_T")
@@ -243,29 +241,6 @@ def random(self) -> Random:
243241
raise RuntimeError(msg)
244242
return Random(self._loop.generate_op_id()) # noqa: S311
245243

246-
@contextmanager
247-
def annotate(
248-
self,
249-
*,
250-
labels: Mapping[str, str] | None = None,
251-
metadata: Mapping[str, JSONValue] | None = None,
252-
) -> Generator[None, None, None]:
253-
if asyncio.get_running_loop() is not self._loop:
254-
msg = "Context labels can only be used in the context loop"
255-
raise RuntimeError(msg)
256-
if not labels and not metadata:
257-
yield
258-
return
259-
260-
current = _annotation.get()
261-
token = _annotation.set(
262-
OpAnnotations.extend(current, metadata=metadata, labels=labels)
263-
)
264-
try:
265-
yield
266-
finally:
267-
_annotation.reset(token)
268-
269244
@overload
270245
async def complete_promise(
271246
self,

src/duron/_core/invoke.py

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -530,7 +530,6 @@ async def enqueue_op(self, id_: str, fut: OpFuture[object]) -> None:
530530

531531
set_annotations(
532532
promise_create_entry,
533-
metadata=op.annotations.metadata,
534533
labels=op.annotations.labels,
535534
)
536535
if self._tracer:
@@ -550,9 +549,7 @@ async def cb() -> None:
550549
"promise_id": id_,
551550
}
552551
with (
553-
op_span.new_span(op.annotations.name, op.annotations.metadata)
554-
if op_span
555-
else NULL_SPAN
552+
op_span.new_span(op.annotations.name) if op_span else NULL_SPAN
556553
):
557554
try:
558555
result = op.callable(*op.args, **op.kwargs)
@@ -619,7 +616,6 @@ def done(f: OpFuture[object]) -> None:
619616

620617
set_annotations(
621618
stream_create_entry,
622-
metadata=op.annotations.metadata,
623619
labels=op.annotations.labels,
624620
)
625621
await self.enqueue_log(stream_create_entry)
@@ -685,7 +681,6 @@ def done(f: OpFuture[object]) -> None:
685681
}
686682
set_annotations(
687683
promise_create_entry,
688-
metadata=op.annotations.metadata,
689684
labels=op.annotations.labels,
690685
)
691686
if self._tracer:

src/duron/_core/ops.py

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
from contextvars import Context
1111

1212
from duron._loop import EventLoop, OpFuture
13-
from duron.codec import JSONValue
1413
from duron.typing import TypeHint
1514

1615
_T = TypeVar("_T")
@@ -28,14 +27,9 @@ def frozen(_cls: type[_T]) -> type[_T]: ...
2827

2928
@frozen
3029
class OpAnnotations:
31-
_metadata: dict[str, JSONValue]
3230
_labels: dict[str, str]
3331
_name: str | None
3432

35-
@property
36-
def metadata(self) -> Mapping[str, JSONValue]:
37-
return self._metadata
38-
3933
@property
4034
def labels(self) -> Mapping[str, str]:
4135
return self._labels
@@ -51,19 +45,16 @@ def extend(
5145
base: OpAnnotations | None,
5246
*,
5347
name: str | None = None,
54-
metadata: Mapping[str, JSONValue] | None = None,
5548
labels: Mapping[str, str] | None = None,
5649
) -> OpAnnotations:
5750
if not base:
5851
return OpAnnotations(
59-
_metadata={**metadata} if metadata else _EMPTY_DICT,
6052
_labels={**labels} if labels else _EMPTY_DICT,
6153
_name=name,
6254
)
6355

6456
# OpAnnotations is immutable, so it's safe to use the existing dicts
6557
return OpAnnotations(
66-
_metadata={**base._metadata, **metadata} if metadata else base._metadata, # noqa: SLF001
6758
_labels={**base._labels, **labels} if labels else base._labels, # noqa: SLF001
6859
_name=name if name is not None else base._name, # noqa: SLF001
6960
)

tests/test_invoke.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -240,8 +240,7 @@ async def bg() -> list[int]:
240240
async def test_watch_stream() -> None:
241241
@durable
242242
async def activity(ctx: Context) -> int:
243-
with ctx.annotate(labels={"name": "output"}):
244-
_, sink = await ctx.create_stream(int)
243+
_, sink = await ctx.create_stream(int, name="output")
245244
for i in range(10):
246245
await sink.send(i)
247246
await sink.close()

0 commit comments

Comments
 (0)