-
Notifications
You must be signed in to change notification settings - Fork 683
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(sdk): backpropagate association property to nearest workflow/task (…
- Loading branch information
Showing
3 changed files
with
84 additions
and
10 deletions.
There are no files selected for viewing
71 changes: 71 additions & 0 deletions
71
packages/traceloop-sdk/tests/test_association_properties.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
from opentelemetry.semconv.ai import SpanAttributes | ||
from traceloop.sdk import Traceloop | ||
from traceloop.sdk.decorators import task, workflow | ||
|
||
|
||
def test_association_properties(exporter): | ||
@workflow(name="test_workflow") | ||
def test_workflow(): | ||
return test_task() | ||
|
||
@task(name="test_task") | ||
def test_task(): | ||
return | ||
|
||
Traceloop.set_association_properties({"user_id": 1, "user_name": "John Doe"}) | ||
test_workflow() | ||
|
||
spans = exporter.get_finished_spans() | ||
assert [span.name for span in spans] == [ | ||
"test_task.task", | ||
"test_workflow.workflow", | ||
] | ||
|
||
some_task_span = spans[0] | ||
some_workflow_span = spans[1] | ||
assert ( | ||
some_workflow_span.attributes[ | ||
f"{SpanAttributes.TRACELOOP_ASSOCIATION_PROPERTIES}.user_id" | ||
] | ||
== 1 | ||
) | ||
assert ( | ||
some_workflow_span.attributes[ | ||
f"{SpanAttributes.TRACELOOP_ASSOCIATION_PROPERTIES}.user_name" | ||
] | ||
== "John Doe" | ||
) | ||
assert ( | ||
some_task_span.attributes[ | ||
f"{SpanAttributes.TRACELOOP_ASSOCIATION_PROPERTIES}.user_id" | ||
] | ||
== 1 | ||
) | ||
assert ( | ||
some_task_span.attributes[ | ||
f"{SpanAttributes.TRACELOOP_ASSOCIATION_PROPERTIES}.user_name" | ||
] | ||
== "John Doe" | ||
) | ||
|
||
|
||
def test_association_properties_within_workflow(exporter): | ||
@workflow(name="test_workflow_within") | ||
def test_workflow(): | ||
Traceloop.set_association_properties({"session_id": 15}) | ||
return | ||
|
||
test_workflow() | ||
|
||
spans = exporter.get_finished_spans() | ||
assert [span.name for span in spans] == [ | ||
"test_workflow_within.workflow", | ||
] | ||
|
||
some_workflow_span = spans[0] | ||
assert ( | ||
some_workflow_span.attributes[ | ||
f"{SpanAttributes.TRACELOOP_ASSOCIATION_PROPERTIES}.session_id" | ||
] | ||
== 15 | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters