Skip to content

Commit

Permalink
added named trace output to simplify generation
Browse files Browse the repository at this point in the history
  • Loading branch information
sethjuarez committed Nov 14, 2024
1 parent ec91629 commit 1990149
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 1 deletion.
22 changes: 21 additions & 1 deletion runtime/prompty/prompty/tracer.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,17 @@ def _trace_sync(
@wraps(func)
def wrapper(*args, **kwargs):
name, signature = _name(func, args)
altname: str = None
# special case
if "name" in okwargs:
altname = name
name = okwargs["name"]
del okwargs["name"]

with Tracer.start(name) as trace:
if altname != None:
trace("function", altname)

trace("signature", signature)

# support arbitrary keyword
Expand Down Expand Up @@ -178,10 +188,20 @@ def _trace_async(
@wraps(func)
async def wrapper(*args, **kwargs):
name, signature = _name(func, args)
altname: str = None
# special case
if "name" in okwargs:
altname = name
name = okwargs["name"]
del okwargs["name"]

with Tracer.start(name) as trace:
if altname != None:
trace("function", altname)

trace("signature", signature)

# support arbitrary keyword
# support arbitrary keyword
# arguments for trace decorator
for k, v in okwargs.items():
trace(k, to_dict(v))
Expand Down
15 changes: 15 additions & 0 deletions runtime/prompty/tests/test_tracing.py
Original file line number Diff line number Diff line change
Expand Up @@ -308,3 +308,18 @@ def test_tracing_attributes():
with Tracer.start("Test3", {"signature": "9", "ten": 10}) as trace:
trace("inputs", 11)
trace(Tracer.RESULT, 12)


@trace(name="OTHER")
def test_named_tracer():
with Tracer.start("Test1", {Tracer.SIGNATURE: "test1", "two": 2}) as trace:
trace(Tracer.INPUTS, 3)
trace(Tracer.RESULT, 4)


@pytest.mark.asyncio
@trace(name="OTHER")
async def test_named_tracer_async():
with Tracer.start("Test1", {Tracer.SIGNATURE: "test1", "two": 2}) as trace:
trace(Tracer.INPUTS, 3)
trace(Tracer.RESULT, 4)

0 comments on commit 1990149

Please sign in to comment.