-
Notifications
You must be signed in to change notification settings - Fork 917
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into mengla/copilot_sample
- Loading branch information
Showing
9 changed files
with
231 additions
and
9 deletions.
There are no files selected for viewing
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
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
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
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
101 changes: 101 additions & 0 deletions
101
src/promptflow-devkit/tests/unittests/_sdk/_utilities/test_tracing_utils.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,101 @@ | ||
import pytest | ||
from pydash import partial | ||
|
||
from promptflow._constants import SpanAttributeFieldName, SpanResourceAttributesFieldName, SpanResourceFieldName | ||
from promptflow._sdk._utilities.tracing_utils import aggregate_trace_count | ||
from promptflow._sdk.entities._trace import Span | ||
|
||
# Mock definitions for Span, SpanResourceFieldName, SpanResourceAttributesFieldName, and SpanAttributeFieldName | ||
# These should match the actual implementations you're using in your application. | ||
|
||
|
||
@pytest.mark.unittest | ||
class TestTraceTelemetry: | ||
def test_empty_span_list(self): | ||
"""Test with an empty list of spans.""" | ||
result = aggregate_trace_count([]) | ||
assert result == {} | ||
|
||
def test_single_root_span(self): | ||
|
||
resource = { | ||
SpanResourceFieldName.ATTRIBUTES: { | ||
SpanResourceAttributesFieldName.SUBSCRIPTION_ID: "sub", | ||
SpanResourceAttributesFieldName.RESOURCE_GROUP_NAME: "rg", | ||
SpanResourceAttributesFieldName.WORKSPACE_NAME: "ws", | ||
} | ||
} | ||
create_span = partial( | ||
Span, | ||
trace_id=None, | ||
span_id=None, | ||
name=None, | ||
context=None, | ||
kind=None, | ||
start_time=None, | ||
end_time=None, | ||
status=None, | ||
parent_id=None, | ||
resource=resource, | ||
) | ||
|
||
batch_root_span = create_span( | ||
attributes={ | ||
SpanAttributeFieldName.EXECUTION_TARGET: "code", | ||
SpanAttributeFieldName.BATCH_RUN_ID: "batch_run_id", | ||
}, | ||
) | ||
line_root_span = create_span( | ||
attributes={ | ||
SpanAttributeFieldName.EXECUTION_TARGET: "code", | ||
SpanAttributeFieldName.LINE_RUN_ID: "line_run_id", | ||
}, | ||
) | ||
|
||
flex_root_span = create_span( | ||
attributes={ | ||
SpanAttributeFieldName.EXECUTION_TARGET: "flex", | ||
}, | ||
) | ||
prompty_root_span = create_span( | ||
attributes={ | ||
SpanAttributeFieldName.EXECUTION_TARGET: "prompty", | ||
}, | ||
) | ||
script_root_span = create_span( | ||
attributes={ | ||
SpanAttributeFieldName.EXECUTION_TARGET: "code", | ||
}, | ||
) | ||
none_ws_root_span = create_span( | ||
resource={}, | ||
attributes={ | ||
SpanAttributeFieldName.EXECUTION_TARGET: "prompty", | ||
}, | ||
) | ||
non_root_span = create_span( | ||
parent_id=1, | ||
attributes={ | ||
SpanAttributeFieldName.EXECUTION_TARGET: "code", | ||
}, | ||
) | ||
result = aggregate_trace_count( | ||
[ | ||
batch_root_span, | ||
line_root_span, | ||
script_root_span, | ||
flex_root_span, | ||
prompty_root_span, | ||
non_root_span, | ||
none_ws_root_span, | ||
] | ||
) | ||
expected_result = { | ||
("sub", "rg", "ws", "batch", "code"): 1, | ||
("sub", "rg", "ws", "script", "code"): 1, | ||
("sub", "rg", "ws", "script", "flex"): 1, | ||
("sub", "rg", "ws", "script", "prompty"): 1, | ||
("sub", "rg", "ws", "test", "code"): 1, | ||
(None, None, None, "script", "prompty"): 1, | ||
} | ||
assert result == expected_result |
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