|
42 | 42 | from pydantic_ai.settings import ModelSettings
|
43 | 43 | from pydantic_ai.usage import RequestUsage
|
44 | 44 |
|
45 |
| -from ..conftest import IsStr, try_import |
| 45 | +from ..conftest import IsInt, IsStr, try_import |
46 | 46 |
|
47 | 47 | with try_import() as imports_successful:
|
48 | 48 | from logfire.testing import CaptureLogfire
|
@@ -831,6 +831,115 @@ async def test_instrumented_model_attributes_mode(capfire: CaptureLogfire, instr
|
831 | 831 | ]
|
832 | 832 | )
|
833 | 833 |
|
| 834 | + assert capfire.get_collected_metrics() == snapshot( |
| 835 | + [ |
| 836 | + { |
| 837 | + 'name': 'gen_ai.client.token.usage', |
| 838 | + 'description': 'Measures number of input and output tokens used', |
| 839 | + 'unit': '{token}', |
| 840 | + 'data': { |
| 841 | + 'data_points': [ |
| 842 | + { |
| 843 | + 'attributes': { |
| 844 | + 'gen_ai.system': 'openai', |
| 845 | + 'gen_ai.operation.name': 'chat', |
| 846 | + 'gen_ai.request.model': 'gpt-4o', |
| 847 | + 'gen_ai.response.model': 'gpt-4o-2024-11-20', |
| 848 | + 'gen_ai.token.type': 'input', |
| 849 | + }, |
| 850 | + 'start_time_unix_nano': IsInt(), |
| 851 | + 'time_unix_nano': IsInt(), |
| 852 | + 'count': 1, |
| 853 | + 'sum': 100, |
| 854 | + 'scale': 20, |
| 855 | + 'zero_count': 0, |
| 856 | + 'positive': {'offset': 6966588, 'bucket_counts': [1]}, |
| 857 | + 'negative': {'offset': 0, 'bucket_counts': [0]}, |
| 858 | + 'flags': 0, |
| 859 | + 'min': 100, |
| 860 | + 'max': 100, |
| 861 | + 'exemplars': [], |
| 862 | + }, |
| 863 | + { |
| 864 | + 'attributes': { |
| 865 | + 'gen_ai.system': 'openai', |
| 866 | + 'gen_ai.operation.name': 'chat', |
| 867 | + 'gen_ai.request.model': 'gpt-4o', |
| 868 | + 'gen_ai.response.model': 'gpt-4o-2024-11-20', |
| 869 | + 'gen_ai.token.type': 'output', |
| 870 | + }, |
| 871 | + 'start_time_unix_nano': IsInt(), |
| 872 | + 'time_unix_nano': IsInt(), |
| 873 | + 'count': 1, |
| 874 | + 'sum': 200, |
| 875 | + 'scale': 20, |
| 876 | + 'zero_count': 0, |
| 877 | + 'positive': {'offset': 8015164, 'bucket_counts': [1]}, |
| 878 | + 'negative': {'offset': 0, 'bucket_counts': [0]}, |
| 879 | + 'flags': 0, |
| 880 | + 'min': 200, |
| 881 | + 'max': 200, |
| 882 | + 'exemplars': [], |
| 883 | + }, |
| 884 | + ], |
| 885 | + 'aggregation_temporality': 1, |
| 886 | + }, |
| 887 | + }, |
| 888 | + { |
| 889 | + 'name': 'operation.cost', |
| 890 | + 'description': 'Monetary cost', |
| 891 | + 'unit': '{USD}', |
| 892 | + 'data': { |
| 893 | + 'data_points': [ |
| 894 | + { |
| 895 | + 'attributes': { |
| 896 | + 'gen_ai.system': 'openai', |
| 897 | + 'gen_ai.operation.name': 'chat', |
| 898 | + 'gen_ai.request.model': 'gpt-4o', |
| 899 | + 'gen_ai.response.model': 'gpt-4o-2024-11-20', |
| 900 | + 'gen_ai.token.type': 'input', |
| 901 | + }, |
| 902 | + 'start_time_unix_nano': IsInt(), |
| 903 | + 'time_unix_nano': IsInt(), |
| 904 | + 'count': 1, |
| 905 | + 'sum': 0.00025, |
| 906 | + 'scale': 20, |
| 907 | + 'zero_count': 0, |
| 908 | + 'positive': {'offset': -12547035, 'bucket_counts': [1]}, |
| 909 | + 'negative': {'offset': 0, 'bucket_counts': [0]}, |
| 910 | + 'flags': 0, |
| 911 | + 'min': 0.00025, |
| 912 | + 'max': 0.00025, |
| 913 | + 'exemplars': [], |
| 914 | + }, |
| 915 | + { |
| 916 | + 'attributes': { |
| 917 | + 'gen_ai.system': 'openai', |
| 918 | + 'gen_ai.operation.name': 'chat', |
| 919 | + 'gen_ai.request.model': 'gpt-4o', |
| 920 | + 'gen_ai.response.model': 'gpt-4o-2024-11-20', |
| 921 | + 'gen_ai.token.type': 'output', |
| 922 | + }, |
| 923 | + 'start_time_unix_nano': IsInt(), |
| 924 | + 'time_unix_nano': IsInt(), |
| 925 | + 'count': 1, |
| 926 | + 'sum': 0.002, |
| 927 | + 'scale': 20, |
| 928 | + 'zero_count': 0, |
| 929 | + 'positive': {'offset': -9401307, 'bucket_counts': [1]}, |
| 930 | + 'negative': {'offset': 0, 'bucket_counts': [0]}, |
| 931 | + 'flags': 0, |
| 932 | + 'min': 0.002, |
| 933 | + 'max': 0.002, |
| 934 | + 'exemplars': [], |
| 935 | + }, |
| 936 | + ], |
| 937 | + 'aggregation_temporality': 1, |
| 938 | + }, |
| 939 | + }, |
| 940 | + ] |
| 941 | + ) |
| 942 | + |
834 | 943 |
|
835 | 944 | def test_messages_to_otel_events_serialization_errors():
|
836 | 945 | class Foo:
|
|
0 commit comments