Commit aab3512
committed
[google-genai] Provide a way to attach extra attributes to the operation-details event but not to the span
Add GENERATE_CONTENT_EVENT_ONLY_EXTRA_ATTRIBUTES_CONTEXT_KEY for caller-supplied
attributes that should be emitted only on the
gen_ai.client.inference.operation.details log event and never on the
generate_content {model} span. Threaded through all four wrappers
(sync/async x streaming/non-streaming).
Precedence on the event: caller-supplied extra_attributes, then
event-only extra_attributes (so they win over extra_attributes on
collision), then request_attributes and final_attributes. Putting the
instrumentation-owned semconv fields last ensures callers cannot
accidentally clobber them (e.g. gen_ai.usage.input_tokens) via the
event-only context value. The span continues to carry only
extra_attributes for any collisions; event-only attributes are never set
on the span.
Tests cover sync/async x streaming/non-streaming for: event-only
attributes not appearing on the span, the event-only-vs-extra-attributes
collision on the event, and event-only not overriding semconv fields.
Originally proposed at open-telemetry/opentelemetry-python-contrib#4581 before
the package moved to this repo.
Assisted-by: opencode agent1 parent 7018efc commit aab3512
5 files changed
Lines changed: 339 additions & 1 deletion
File tree
- instrumentation/opentelemetry-instrumentation-google-genai
- .changelog
- src/opentelemetry/instrumentation/google_genai
- tests/generate_content
Lines changed: 1 addition & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
Lines changed: 5 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
30 | 30 | | |
31 | 31 | | |
32 | 32 | | |
33 | | - | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
34 | 37 | | |
35 | 38 | | |
36 | 39 | | |
37 | 40 | | |
38 | 41 | | |
39 | 42 | | |
| 43 | + | |
40 | 44 | | |
41 | 45 | | |
Lines changed: 54 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
101 | 101 | | |
102 | 102 | | |
103 | 103 | | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
104 | 118 | | |
105 | 119 | | |
106 | 120 | | |
| |||
495 | 509 | | |
496 | 510 | | |
497 | 511 | | |
| 512 | + | |
| 513 | + | |
| 514 | + | |
| 515 | + | |
| 516 | + | |
| 517 | + | |
| 518 | + | |
| 519 | + | |
| 520 | + | |
498 | 521 | | |
499 | 522 | | |
500 | 523 | | |
| |||
750 | 773 | | |
751 | 774 | | |
752 | 775 | | |
| 776 | + | |
| 777 | + | |
| 778 | + | |
753 | 779 | | |
754 | 780 | | |
755 | 781 | | |
| |||
763 | 789 | | |
764 | 790 | | |
765 | 791 | | |
| 792 | + | |
| 793 | + | |
| 794 | + | |
| 795 | + | |
| 796 | + | |
| 797 | + | |
766 | 798 | | |
767 | 799 | | |
768 | 800 | | |
| 801 | + | |
769 | 802 | | |
770 | 803 | | |
771 | 804 | | |
| |||
1032 | 1065 | | |
1033 | 1066 | | |
1034 | 1067 | | |
| 1068 | + | |
| 1069 | + | |
| 1070 | + | |
| 1071 | + | |
1035 | 1072 | | |
1036 | 1073 | | |
1037 | 1074 | | |
| |||
1068 | 1105 | | |
1069 | 1106 | | |
1070 | 1107 | | |
| 1108 | + | |
1071 | 1109 | | |
1072 | 1110 | | |
1073 | 1111 | | |
| |||
1109 | 1147 | | |
1110 | 1148 | | |
1111 | 1149 | | |
| 1150 | + | |
| 1151 | + | |
| 1152 | + | |
| 1153 | + | |
1112 | 1154 | | |
1113 | 1155 | | |
1114 | 1156 | | |
| |||
1145 | 1187 | | |
1146 | 1188 | | |
1147 | 1189 | | |
| 1190 | + | |
1148 | 1191 | | |
1149 | 1192 | | |
1150 | 1193 | | |
| |||
1186 | 1229 | | |
1187 | 1230 | | |
1188 | 1231 | | |
| 1232 | + | |
| 1233 | + | |
| 1234 | + | |
| 1235 | + | |
1189 | 1236 | | |
1190 | 1237 | | |
1191 | 1238 | | |
| |||
1221 | 1268 | | |
1222 | 1269 | | |
1223 | 1270 | | |
| 1271 | + | |
1224 | 1272 | | |
1225 | 1273 | | |
1226 | 1274 | | |
| |||
1264 | 1312 | | |
1265 | 1313 | | |
1266 | 1314 | | |
| 1315 | + | |
| 1316 | + | |
| 1317 | + | |
| 1318 | + | |
1267 | 1319 | | |
1268 | 1320 | | |
1269 | 1321 | | |
| |||
1291 | 1343 | | |
1292 | 1344 | | |
1293 | 1345 | | |
| 1346 | + | |
1294 | 1347 | | |
1295 | 1348 | | |
1296 | 1349 | | |
| |||
1328 | 1381 | | |
1329 | 1382 | | |
1330 | 1383 | | |
| 1384 | + | |
1331 | 1385 | | |
1332 | 1386 | | |
1333 | 1387 | | |
| |||
Lines changed: 141 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
23 | 23 | | |
24 | 24 | | |
25 | 25 | | |
| 26 | + | |
26 | 27 | | |
27 | 28 | | |
28 | 29 | | |
| |||
925 | 926 | | |
926 | 927 | | |
927 | 928 | | |
| 929 | + | |
| 930 | + | |
| 931 | + | |
| 932 | + | |
| 933 | + | |
| 934 | + | |
| 935 | + | |
| 936 | + | |
| 937 | + | |
| 938 | + | |
| 939 | + | |
| 940 | + | |
| 941 | + | |
| 942 | + | |
| 943 | + | |
| 944 | + | |
| 945 | + | |
| 946 | + | |
| 947 | + | |
| 948 | + | |
| 949 | + | |
| 950 | + | |
| 951 | + | |
| 952 | + | |
| 953 | + | |
| 954 | + | |
| 955 | + | |
| 956 | + | |
| 957 | + | |
| 958 | + | |
| 959 | + | |
| 960 | + | |
| 961 | + | |
| 962 | + | |
| 963 | + | |
| 964 | + | |
| 965 | + | |
| 966 | + | |
| 967 | + | |
| 968 | + | |
| 969 | + | |
| 970 | + | |
| 971 | + | |
| 972 | + | |
| 973 | + | |
| 974 | + | |
| 975 | + | |
| 976 | + | |
| 977 | + | |
| 978 | + | |
| 979 | + | |
| 980 | + | |
| 981 | + | |
| 982 | + | |
| 983 | + | |
| 984 | + | |
| 985 | + | |
| 986 | + | |
| 987 | + | |
| 988 | + | |
| 989 | + | |
| 990 | + | |
| 991 | + | |
| 992 | + | |
| 993 | + | |
| 994 | + | |
| 995 | + | |
| 996 | + | |
| 997 | + | |
| 998 | + | |
| 999 | + | |
| 1000 | + | |
| 1001 | + | |
| 1002 | + | |
| 1003 | + | |
| 1004 | + | |
| 1005 | + | |
| 1006 | + | |
| 1007 | + | |
| 1008 | + | |
| 1009 | + | |
| 1010 | + | |
| 1011 | + | |
| 1012 | + | |
| 1013 | + | |
| 1014 | + | |
| 1015 | + | |
| 1016 | + | |
| 1017 | + | |
| 1018 | + | |
| 1019 | + | |
| 1020 | + | |
| 1021 | + | |
| 1022 | + | |
| 1023 | + | |
| 1024 | + | |
| 1025 | + | |
| 1026 | + | |
| 1027 | + | |
| 1028 | + | |
| 1029 | + | |
| 1030 | + | |
| 1031 | + | |
| 1032 | + | |
| 1033 | + | |
| 1034 | + | |
| 1035 | + | |
| 1036 | + | |
| 1037 | + | |
| 1038 | + | |
| 1039 | + | |
| 1040 | + | |
| 1041 | + | |
| 1042 | + | |
| 1043 | + | |
| 1044 | + | |
| 1045 | + | |
| 1046 | + | |
| 1047 | + | |
| 1048 | + | |
| 1049 | + | |
| 1050 | + | |
| 1051 | + | |
| 1052 | + | |
| 1053 | + | |
| 1054 | + | |
| 1055 | + | |
| 1056 | + | |
| 1057 | + | |
| 1058 | + | |
| 1059 | + | |
| 1060 | + | |
| 1061 | + | |
| 1062 | + | |
| 1063 | + | |
| 1064 | + | |
| 1065 | + | |
| 1066 | + | |
| 1067 | + | |
| 1068 | + | |
928 | 1069 | | |
929 | 1070 | | |
930 | 1071 | | |
| |||
0 commit comments