Skip to content

Commit 50c1b9b

Browse files
vgrozdaniclcian
andauthored
feat(ai): Add gen_ai_cost_total_tokens field and deprecate old version (#126)
* feat(ai): Add gen_ai_cost_total_tokens field and deprecate old version * Update model/attributes/gen_ai/gen_ai__usage__total_cost.json Co-authored-by: Lorenzo Cian <[email protected]> * backfill --------- Co-authored-by: Lorenzo Cian <[email protected]>
1 parent 8cc17b9 commit 50c1b9b

File tree

5 files changed

+77
-14
lines changed

5 files changed

+77
-14
lines changed

generated/attributes/gen_ai.md

Lines changed: 25 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
- [gen_ai.choice](#gen_aichoice)
99
- [gen_ai.cost.input_tokens](#gen_aicostinput_tokens)
1010
- [gen_ai.cost.output_tokens](#gen_aicostoutput_tokens)
11+
- [gen_ai.cost.total_tokens](#gen_aicosttotal_tokens)
1112
- [gen_ai.operation.name](#gen_aioperationname)
1213
- [gen_ai.operation.type](#gen_aioperationtype)
1314
- [gen_ai.pipeline.name](#gen_aipipelinename)
@@ -40,13 +41,13 @@
4041
- [gen_ai.usage.input_tokens.cached](#gen_aiusageinput_tokenscached)
4142
- [gen_ai.usage.output_tokens](#gen_aiusageoutput_tokens)
4243
- [gen_ai.usage.output_tokens.reasoning](#gen_aiusageoutput_tokensreasoning)
43-
- [gen_ai.usage.total_cost](#gen_aiusagetotal_cost)
4444
- [gen_ai.usage.total_tokens](#gen_aiusagetotal_tokens)
4545
- [gen_ai.user.message](#gen_aiusermessage)
4646
- [Deprecated Attributes](#deprecated-attributes)
4747
- [gen_ai.prompt](#gen_aiprompt)
4848
- [gen_ai.usage.completion_tokens](#gen_aiusagecompletion_tokens)
4949
- [gen_ai.usage.prompt_tokens](#gen_aiusageprompt_tokens)
50+
- [gen_ai.usage.total_cost](#gen_aiusagetotal_cost)
5051

5152
## Stable Attributes
5253

@@ -105,6 +106,17 @@ The cost of tokens used for creating the AI output in USD (without reasoning tok
105106
| Exists in OpenTelemetry | No |
106107
| Example | `123.45` |
107108

109+
### gen_ai.cost.total_tokens
110+
111+
The total cost for the tokens used.
112+
113+
| Property | Value |
114+
| --- | --- |
115+
| Type | `double` |
116+
| Has PII | false |
117+
| Exists in OpenTelemetry | No |
118+
| Example | `12.34` |
119+
108120
### gen_ai.operation.name
109121

110122
The name of the operation being performed.
@@ -473,17 +485,6 @@ The number of tokens used for reasoning to create the AI output.
473485
| Exists in OpenTelemetry | No |
474486
| Example | `75` |
475487

476-
### gen_ai.usage.total_cost
477-
478-
The total cost for the tokens used.
479-
480-
| Property | Value |
481-
| --- | --- |
482-
| Type | `double` |
483-
| Has PII | false |
484-
| Exists in OpenTelemetry | No |
485-
| Example | `12.34` |
486-
487488
### gen_ai.usage.total_tokens
488489

489490
The total number of tokens used to process the prompt. (input tokens plus output todkens)
@@ -550,3 +551,15 @@ The number of tokens used in the GenAI input (prompt).
550551
| Deprecated | Yes, use `gen_ai.usage.input_tokens` instead |
551552
| Aliases | `ai.prompt_tokens.used`, `gen_ai.usage.input_tokens` |
552553

554+
### gen_ai.usage.total_cost
555+
556+
The total cost for the tokens used.
557+
558+
| Property | Value |
559+
| --- | --- |
560+
| Type | `double` |
561+
| Has PII | false |
562+
| Exists in OpenTelemetry | No |
563+
| Example | `12.34` |
564+
| Deprecated | Yes, use `gen_ai.cost.total_tokens` instead |
565+

javascript/sentry-conventions/src/attributes.ts

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2101,6 +2101,26 @@ export const GEN_AI_COST_OUTPUT_TOKENS = 'gen_ai.cost.output_tokens';
21012101
*/
21022102
export type GEN_AI_COST_OUTPUT_TOKENS_TYPE = number;
21032103

2104+
// Path: model/attributes/gen_ai/gen_ai__cost__total_tokens.json
2105+
2106+
/**
2107+
* The total cost for the tokens used. `gen_ai.cost.total_tokens`
2108+
*
2109+
* Attribute Value Type: `number` {@link GEN_AI_COST_TOTAL_TOKENS_TYPE}
2110+
*
2111+
* Contains PII: false
2112+
*
2113+
* Attribute defined in OTEL: No
2114+
*
2115+
* @example 12.34
2116+
*/
2117+
export const GEN_AI_COST_TOTAL_TOKENS = 'gen_ai.cost.total_tokens';
2118+
2119+
/**
2120+
* Type for {@link GEN_AI_COST_TOTAL_TOKENS} gen_ai.cost.total_tokens
2121+
*/
2122+
export type GEN_AI_COST_TOTAL_TOKENS_TYPE = number;
2123+
21042124
// Path: model/attributes/gen_ai/gen_ai__operation__name.json
21052125

21062126
/**
@@ -2851,6 +2871,7 @@ export type GEN_AI_USAGE_PROMPT_TOKENS_TYPE = number;
28512871
*
28522872
* Attribute defined in OTEL: No
28532873
*
2874+
* @deprecated Use {@link GEN_AI_COST_TOTAL_TOKENS} (gen_ai.cost.total_tokens) instead
28542875
* @example 12.34
28552876
*/
28562877
export const GEN_AI_USAGE_TOTAL_COST = 'gen_ai.usage.total_cost';
@@ -6571,6 +6592,7 @@ export type Attributes = {
65716592
[GEN_AI_CHOICE]?: GEN_AI_CHOICE_TYPE;
65726593
[GEN_AI_COST_INPUT_TOKENS]?: GEN_AI_COST_INPUT_TOKENS_TYPE;
65736594
[GEN_AI_COST_OUTPUT_TOKENS]?: GEN_AI_COST_OUTPUT_TOKENS_TYPE;
6595+
[GEN_AI_COST_TOTAL_TOKENS]?: GEN_AI_COST_TOTAL_TOKENS_TYPE;
65746596
[GEN_AI_OPERATION_NAME]?: GEN_AI_OPERATION_NAME_TYPE;
65756597
[GEN_AI_OPERATION_TYPE]?: GEN_AI_OPERATION_TYPE_TYPE;
65766598
[GEN_AI_PIPELINE_NAME]?: GEN_AI_PIPELINE_NAME_TYPE;
@@ -6603,7 +6625,6 @@ export type Attributes = {
66036625
[GEN_AI_USAGE_INPUT_TOKENS_CACHED]?: GEN_AI_USAGE_INPUT_TOKENS_CACHED_TYPE;
66046626
[GEN_AI_USAGE_OUTPUT_TOKENS]?: GEN_AI_USAGE_OUTPUT_TOKENS_TYPE;
66056627
[GEN_AI_USAGE_OUTPUT_TOKENS_REASONING]?: GEN_AI_USAGE_OUTPUT_TOKENS_REASONING_TYPE;
6606-
[GEN_AI_USAGE_TOTAL_COST]?: GEN_AI_USAGE_TOTAL_COST_TYPE;
66076628
[GEN_AI_USAGE_TOTAL_TOKENS]?: GEN_AI_USAGE_TOTAL_TOKENS_TYPE;
66086629
[GEN_AI_USER_MESSAGE]?: GEN_AI_USER_MESSAGE_TYPE;
66096630
[GRAPHQL_OPERATION_NAME]?: GRAPHQL_OPERATION_NAME_TYPE;
@@ -6846,6 +6867,7 @@ export type FullAttributes = {
68466867
[GEN_AI_CHOICE]?: GEN_AI_CHOICE_TYPE;
68476868
[GEN_AI_COST_INPUT_TOKENS]?: GEN_AI_COST_INPUT_TOKENS_TYPE;
68486869
[GEN_AI_COST_OUTPUT_TOKENS]?: GEN_AI_COST_OUTPUT_TOKENS_TYPE;
6870+
[GEN_AI_COST_TOTAL_TOKENS]?: GEN_AI_COST_TOTAL_TOKENS_TYPE;
68496871
[GEN_AI_OPERATION_NAME]?: GEN_AI_OPERATION_NAME_TYPE;
68506872
[GEN_AI_OPERATION_TYPE]?: GEN_AI_OPERATION_TYPE_TYPE;
68516873
[GEN_AI_PIPELINE_NAME]?: GEN_AI_PIPELINE_NAME_TYPE;
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"key": "gen_ai.cost.total_tokens",
3+
"brief": "The total cost for the tokens used.",
4+
"type": "double",
5+
"pii": {
6+
"key": "false"
7+
},
8+
"is_in_otel": false,
9+
"example": 12.34
10+
}

model/attributes/gen_ai/gen_ai__usage__total_cost.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,9 @@
66
"key": "false"
77
},
88
"is_in_otel": false,
9-
"example": 12.34
9+
"example": 12.34,
10+
"deprecation": {
11+
"_status": "backfill",
12+
"replacement": "gen_ai.cost.total_tokens"
13+
}
1014
}

shared/deprecated_attributes.json

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -624,6 +624,20 @@
624624
},
625625
"alias": ["ai.prompt_tokens.used", "gen_ai.usage.input_tokens"]
626626
},
627+
{
628+
"key": "gen_ai.usage.total_cost",
629+
"brief": "The total cost for the tokens used.",
630+
"type": "double",
631+
"pii": {
632+
"key": "false"
633+
},
634+
"is_in_otel": false,
635+
"example": 12.34,
636+
"deprecation": {
637+
"_status": "backfill",
638+
"replacement": "gen_ai.cost.total_tokens"
639+
}
640+
},
627641
{
628642
"key": "http.client_ip",
629643
"brief": "Client address - domain name if available without reverse DNS lookup; otherwise, IP address or Unix domain socket name.",

0 commit comments

Comments
 (0)