Skip to content

Commit

Permalink
fix: input/output for workflows & tasks
Browse files Browse the repository at this point in the history
  • Loading branch information
nirga committed Feb 13, 2024
1 parent 301dc79 commit a1b2d2d
Showing 1 changed file with 60 additions and 4 deletions.
64 changes: 60 additions & 4 deletions packages/traceloop-sdk/traceloop/sdk/decorators/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import json
from functools import wraps
import os
from typing import Optional

from opentelemetry import context as context_api
from opentelemetry.semconv.ai import SpanAttributes, TraceloopSpanKindValues

from traceloop.sdk.tracing import get_tracer, set_workflow_name
Expand Down Expand Up @@ -42,7 +45,19 @@ def wrap(*args, **kwargs):
SpanAttributes.TRACELOOP_SPAN_KIND, tlp_span_kind.value
)
span.set_attribute(SpanAttributes.TRACELOOP_ENTITY_NAME, name)
return fn(*args, **kwargs)

if _should_send_prompts():
span.set_attribute(
SpanAttributes.TRACELOOP_ENTITY_INPUT,
json.dumps({"args": args, "kwargs": kwargs}),
)

res = fn(*args, **kwargs)

if _should_send_prompts():
span.set_attribute(SpanAttributes.TRACELOOP_ENTITY_OUTPUT, res)

return res

return wrap

Expand Down Expand Up @@ -99,7 +114,18 @@ def wrap(*args, **kwargs):
)
span.set_attribute(SpanAttributes.TRACELOOP_ENTITY_NAME, name)

return fn(*args, **kwargs)
if _should_send_prompts():
span.set_attribute(
SpanAttributes.TRACELOOP_ENTITY_INPUT,
json.dumps({"args": args, "kwargs": kwargs}),
)

res = fn(*args, **kwargs)

if _should_send_prompts():
span.set_attribute(SpanAttributes.TRACELOOP_ENTITY_OUTPUT, res)

return res

return wrap

Expand Down Expand Up @@ -169,7 +195,19 @@ async def wrap(*args, **kwargs):
SpanAttributes.TRACELOOP_SPAN_KIND, tlp_span_kind.value
)
span.set_attribute(SpanAttributes.TRACELOOP_ENTITY_NAME, name)
return await fn(*args, **kwargs)

if _should_send_prompts():
span.set_attribute(
SpanAttributes.TRACELOOP_ENTITY_INPUT,
json.dumps({"args": args, "kwargs": kwargs}),
)

res = await fn(*args, **kwargs)

if _should_send_prompts():
span.set_attribute(SpanAttributes.TRACELOOP_ENTITY_OUTPUT, res)

return res

return wrap

Expand Down Expand Up @@ -230,7 +268,19 @@ async def wrap(*args, **kwargs):
span.set_attribute(
SpanAttributes.TRACELOOP_CORRELATION_ID, correlation_id
)
return await fn(*args, **kwargs)

if _should_send_prompts():
span.set_attribute(
SpanAttributes.TRACELOOP_ENTITY_INPUT,
json.dumps({"args": args, "kwargs": kwargs}),
)

res = await fn(*args, **kwargs)

if _should_send_prompts():
span.set_attribute(SpanAttributes.TRACELOOP_ENTITY_OUTPUT, res)

return res

return wrap

Expand Down Expand Up @@ -263,3 +313,9 @@ def atool(name: Optional[str] = None, method_name: Optional[str] = None):
return atask(
name=name, method_name=method_name, tlp_span_kind=TraceloopSpanKindValues.TOOL
)


def _should_send_prompts():
return (
os.getenv("TRACELOOP_TRACE_CONTENT") or "true"
).lower() == "true" or context_api.get_value("override_enable_content_tracing")

0 comments on commit a1b2d2d

Please sign in to comment.