pi-otel 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE ADDED
@@ -0,0 +1,183 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship made available under
36
+ the License, as indicated by a copyright notice that is included in
37
+ or attached to the work (an example is provided in the Appendix below).
38
+
39
+ "Derivative Works" shall mean any work, whether in Source or Object
40
+ form, that is based on (or derived from) the Work and for which the
41
+ editorial revisions, annotations, elaborations, or other modifications
42
+ represent, as a whole, an original work of authorship. For the purposes
43
+ of this License, Derivative Works shall not include works that remain
44
+ separable from, or merely link (or bind by name) to the interfaces of,
45
+ the Work and Derivative Works thereof.
46
+
47
+ "Contribution" shall mean, as submitted to the Licensor for inclusion
48
+ in the Work by the copyright owner or by an individual or Legal Entity
49
+ authorized to submit on behalf of the copyright owner. For the purposes
50
+ of this definition, "submitted" means any form of electronic, verbal,
51
+ or written communication sent to the Licensor or its representatives,
52
+ including but not limited to communication on electronic mailing lists,
53
+ source code control systems, and issue tracking systems that are managed
54
+ by, or on behalf of, the Licensor for the purpose of discussing and
55
+ improving the Work, but excluding communication that is conspicuously
56
+ marked or designated in writing by the copyright owner as "Not a
57
+ Contribution."
58
+
59
+ "Contributor" shall mean Licensor and any Legal Entity on behalf of
60
+ whom a Contribution has been received by the Licensor and included
61
+ within the Work.
62
+
63
+ 2. Grant of Copyright License. Subject to the terms and conditions of
64
+ this License, each Contributor hereby grants to You a perpetual,
65
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
66
+ copyright license to reproduce, prepare Derivative Works of,
67
+ publicly display, publicly perform, sublicense, and distribute the
68
+ Work and such Derivative Works in Source or Object form.
69
+
70
+ 3. Grant of Patent License. Subject to the terms and conditions of
71
+ this License, each Contributor hereby grants to You a perpetual,
72
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
73
+ (except as stated in this section) patent license to make, have made,
74
+ use, offer to sell, sell, import, and otherwise transfer the Work,
75
+ where such license applies only to those patent claims licensable
76
+ by such Contributor that are necessarily infringed by their
77
+ Contribution(s) alone or by the combination of their Contribution(s)
78
+ with the Work to which such Contribution(s) was submitted. If You
79
+ institute patent litigation against any entity (including a cross-claim
80
+ or counterclaim in a lawsuit) alleging that the Work or any patent
81
+ claim(s) constituted by a Work constitutes direct or contributory
82
+ patent infringement, then any patent licenses granted to You under
83
+ this License for that Work shall terminate as of the date such
84
+ litigation is filed.
85
+
86
+ 4. Redistribution. You may reproduce and distribute copies of the
87
+ Work or Derivative Works thereof in any medium, with or without
88
+ modifications, and in Source or Object form, provided that You
89
+ meet the following conditions:
90
+
91
+ (a) You must give any other recipients of the Work or Derivative
92
+ Works a copy of this License; and
93
+
94
+ (b) You must cause any modified files to carry prominent notices
95
+ stating that You changed the files; and
96
+
97
+ (c) You must retain, in the Source form of any Derivative Works
98
+ that You distribute, all copyright, patent, trademark, and
99
+ attribution notices from the Source form of the Work,
100
+ excluding those notices that do not pertain to any part of
101
+ the Derivative Works; and
102
+
103
+ (d) If the Work includes a "NOTICE" text file as part of its
104
+ distribution, You must include a readable copy of the
105
+ attribution notices contained in such NOTICE file, in at least
106
+ one of the following places: within a NOTICE text file distributed
107
+ as part of the Derivative Works; within the Source form or
108
+ documentation, if provided along with the Derivative Works; or,
109
+ within a display generated by the Derivative Works, if and
110
+ wherever such third-party notices normally appear. The contents
111
+ of the NOTICE file are for informational purposes only and
112
+ do not modify the License. You may add Your own attribution
113
+ notices within Derivative Works that You distribute, alongside
114
+ or as an addendum to the NOTICE text from the Work, provided
115
+ that such additional attribution notices cannot be construed
116
+ as modifying the License.
117
+
118
+ You may add Your own license statement for Your modifications and
119
+ may provide additional grant of rights to use, copy, modify, merge,
120
+ publish, distribute, sublicense, and/or sell copies of the
121
+ Contribution, either on an original or modified basis.
122
+
123
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
124
+ any Contribution intentionally submitted for inclusion in the Work
125
+ by You to the Licensor shall be under the terms and conditions of
126
+ this License, without any additional terms or conditions.
127
+ Notwithstanding the above, nothing herein shall supersede or modify
128
+ the terms of any separate license agreement you may have executed
129
+ with Licensor regarding such Contributions.
130
+
131
+ 6. Trademarks. This License does not grant permission to use the trade
132
+ names, trademarks, service marks, or product names of the Licensor,
133
+ except as required for reasonable and customary use in describing the
134
+ origin of the Work and reproducing the content of the NOTICE file.
135
+
136
+ 7. Disclaimer of Warranty. Unless required by applicable law or
137
+ agreed to in writing, Licensor provides the Work (and each
138
+ Contributor provides its Contributions) on an "AS IS" BASIS,
139
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
140
+ implied, including, without limitation, any warranties or conditions
141
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
142
+ PARTICULAR PURPOSE. You are solely responsible for determining the
143
+ appropriateness of using or reproducing the Work and assume any
144
+ risks associated with Your exercise of permissions under this License.
145
+
146
+ 8. Limitation of Liability. In no event and under no legal theory,
147
+ whether in tort (including negligence), contract, or otherwise,
148
+ unless required by applicable law (such as deliberate and grossly
149
+ negligent acts) or agreed to in writing, shall any Contributor be
150
+ liable to You for damages, including any direct, indirect, special,
151
+ incidental, or exemplary damages of any character arising as a
152
+ result of this License or out of the use or inability to use the
153
+ Work (including but not limited to damages for loss of goodwill,
154
+ work stoppage, computer failure or malfunction, or all other
155
+ commercial damages or losses), even if such Contributor has been
156
+ advised of the possibility of such damages.
157
+
158
+ 9. Accepting Warranty or Additional Liability. While redistributing
159
+ the Work or Derivative Works thereof, You may choose to offer,
160
+ and charge a fee for, acceptance of support, warranty, indemnity,
161
+ or other liability obligations and/or rights consistent with this
162
+ License. However, in accepting such obligations, You may offer such
163
+ conditions only on Your own behalf and on Your sole responsibility,
164
+ not on behalf of any other Contributor, and only if You agree to
165
+ indemnify, defend, and hold each Contributor harmless for any
166
+ liability incurred by, or claims asserted against, such Contributor
167
+ by reason of your accepting any such warranty or additional liability.
168
+
169
+ END OF TERMS AND CONDITIONS
170
+
171
+ Copyright 2026 Oleksii Nikiforov
172
+
173
+ Licensed under the Apache License, Version 2.0 (the "License");
174
+ you may not use this file except in compliance with the License.
175
+ You may obtain a copy of the License at
176
+
177
+ http://www.apache.org/licenses/LICENSE-2.0
178
+
179
+ Unless required by applicable law or agreed to in writing, software
180
+ distributed under the License is distributed on an "AS IS" BASIS,
181
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
182
+ See the License for the specific language governing permissions and
183
+ limitations under the License.
package/README.md ADDED
@@ -0,0 +1,66 @@
1
+ # pi-otel
2
+
3
+ [![Docs](https://img.shields.io/badge/docs-pi--otel-blue)](https://nikiforovall.blog/pi-otel/)
4
+
5
+ OpenTelemetry tracing for [pi](https://github.com/earendil-works/pi-coding-agent) agent.
6
+
7
+ Full OTel GenAI semantic-convention coverage (`gen_ai.*`) for token usage, cost, model, finish reasons, and tool calls.
8
+
9
+ <table>
10
+ <tr>
11
+ <th align="center" colspan="3">Aspire dashboard</th>
12
+ </tr>
13
+ <tr>
14
+ <td><img src="https://raw.githubusercontent.com/NikiforovAll/pi-otel/master/samples/aspire/assets/aspire-traces.png"/></td>
15
+ <td><img src="https://raw.githubusercontent.com/NikiforovAll/pi-otel/master/samples/aspire/assets/aspire-metrics.png"/></td>
16
+ <td><img src="https://raw.githubusercontent.com/NikiforovAll/pi-otel/master/samples/aspire/assets/aspire-logs.png"/></td>
17
+ </tr>
18
+ <tr>
19
+ <th align="center" colspan="3">Grafana LGTM</th>
20
+ </tr>
21
+ <tr>
22
+ <td><img src="https://raw.githubusercontent.com/NikiforovAll/pi-otel/master/samples/lgtm/assets/traces-tempo.png"/></td>
23
+ <td><img src="https://raw.githubusercontent.com/NikiforovAll/pi-otel/master/samples/lgtm/assets/grafana-metrics.png"/></td>
24
+ <td><img src="https://raw.githubusercontent.com/NikiforovAll/pi-otel/master/samples/lgtm/assets/loki-logs.png"/></td>
25
+ </tr>
26
+ </table>
27
+
28
+ ## Install
29
+
30
+ ```
31
+ pi install npm:pi-otel
32
+ ```
33
+
34
+ ## Quickstart
35
+
36
+ ```
37
+ /otel start # spawn local Aspire dashboard
38
+ ```
39
+
40
+ Backend auto-detect: Aspire CLI first, then Docker / Podman. Install one:
41
+
42
+ - Aspire CLI
43
+ - Docker or Podman
44
+
45
+ ## Configuration
46
+
47
+ `.pi/settings.json` (project) or `~/.pi/agent/settings.json` (global):
48
+
49
+ ```jsonc
50
+ {
51
+ "otel": {
52
+ "enabled": true,
53
+ "endpoint": "http://localhost:4317",
54
+ "protocol": "grpc",
55
+ "headers": {},
56
+ "serviceName": "pi",
57
+ "captureContent": "metadata_only",
58
+ "sampleRatio": 1.0,
59
+ "signals": { "traces": true, "metrics": false, "logs": false }
60
+ }
61
+ }
62
+ ```
63
+
64
+ Key env var overrides: `OTEL_EXPORTER_OTLP_ENDPOINT`, `PI_OTEL_METRICS=1`, `PI_OTEL_LOGS=1`, `PI_OTEL_DISABLED=1`.
65
+
66
+ Full reference — settings, env vars, content capture modes, sampling, logs signal, and extensibility: [nikiforovall.blog/pi-otel/configuration](https://nikiforovall.blog/pi-otel/configuration)
@@ -0,0 +1,67 @@
1
+ /**
2
+ * gen_ai.* attribute and metric constants.
3
+ *
4
+ * Names follow the OTel GenAI semantic conventions:
5
+ * https://opentelemetry.io/docs/specs/semconv/gen-ai/
6
+ */
7
+ export declare const ATTR_CONVERSATION_ID = "gen_ai.conversation.id";
8
+ export declare const ATTR_AGENT_NAME = "gen_ai.agent.name";
9
+ export declare const ATTR_AGENT_VERSION = "gen_ai.agent.version";
10
+ export declare const ATTR_USER_ID = "user.id";
11
+ export declare const ATTR_ERROR_TYPE = "error.type";
12
+ export declare const ATTR_OPERATION_NAME = "gen_ai.operation.name";
13
+ export declare const ATTR_SYSTEM = "gen_ai.system";
14
+ export declare const ATTR_PROVIDER_NAME = "gen_ai.provider.name";
15
+ export declare const ATTR_REQUEST_MODEL = "gen_ai.request.model";
16
+ export declare const ATTR_REQUEST_MAX_TOKENS = "gen_ai.request.max_tokens";
17
+ export declare const ATTR_REQUEST_TEMPERATURE = "gen_ai.request.temperature";
18
+ export declare const ATTR_REQUEST_TOP_P = "gen_ai.request.top_p";
19
+ export declare const ATTR_RESPONSE_ID = "gen_ai.response.id";
20
+ export declare const ATTR_RESPONSE_MODEL = "gen_ai.response.model";
21
+ export declare const ATTR_FINISH_REASONS = "gen_ai.response.finish_reasons";
22
+ export declare const ATTR_INPUT_TOKENS = "gen_ai.usage.input_tokens";
23
+ export declare const ATTR_OUTPUT_TOKENS = "gen_ai.usage.output_tokens";
24
+ export declare const ATTR_TOKEN_TYPE = "gen_ai.token.type";
25
+ export declare const ATTR_CACHE_READ_TOKENS = "gen_ai.usage.cache_read_input_tokens";
26
+ export declare const ATTR_CACHE_WRITE_TOKENS = "gen_ai.usage.cache_write_input_tokens";
27
+ export declare const ATTR_CACHE_CREATION_TOKENS = "gen_ai.usage.cache_creation_input_tokens";
28
+ export declare const ATTR_REASONING_TOKENS = "gen_ai.usage.reasoning_tokens";
29
+ export declare const ATTR_TOOL_NAME = "gen_ai.tool.name";
30
+ export declare const ATTR_TOOL_CALL_ID = "gen_ai.tool.call.id";
31
+ export declare const ATTR_TOOL_TYPE = "gen_ai.tool.type";
32
+ export declare const ATTR_TOOL_DESCRIPTION = "gen_ai.tool.description";
33
+ export declare const ATTR_TOOL_CALL_ARGUMENTS = "gen_ai.tool.call.arguments";
34
+ export declare const ATTR_TOOL_CALL_RESULT = "gen_ai.tool.call.result";
35
+ export declare const ATTR_PI_SESSION_ID = "pi.session.id";
36
+ export declare const ATTR_SESSION_ID = "session.id";
37
+ export declare const ATTR_PI_CWD = "pi.cwd";
38
+ export declare const ATTR_PI_TURN_COUNT = "pi.turn_count";
39
+ export declare const ATTR_PI_TURN_INDEX = "pi.turn_index";
40
+ export declare const ATTR_PI_TOOL_COUNT = "pi.tool_count";
41
+ export declare const ATTR_PI_TOOL_NAME = "pi.tool.name";
42
+ export declare const ATTR_PI_TOOL_CALL_ID = "pi.tool.call_id";
43
+ export declare const ATTR_PI_TOOL_IS_ERROR = "pi.tool.is_error";
44
+ export declare const ATTR_PI_TOOL_INPUT = "pi.tool.input";
45
+ export declare const ATTR_PI_TOOL_OUTPUT = "pi.tool.output";
46
+ export declare const ATTR_PI_COST_USD = "pi.cost.usd";
47
+ export declare const ATTR_PI_USER_PROMPT = "pi.user_prompt";
48
+ export declare const ATTR_PI_USER_PROMPT_LENGTH = "pi.user_prompt_length";
49
+ export declare const ATTR_HTTP_STATUS_CODE = "http.response.status_code";
50
+ export declare const ATTR_GEN_AI_INPUT_MESSAGES = "gen_ai.input.messages";
51
+ export declare const ATTR_GEN_AI_OUTPUT_MESSAGES = "gen_ai.output.messages";
52
+ export declare const EVENT_GEN_AI_USER_MESSAGE = "gen_ai.user.message";
53
+ export declare const EVENT_GEN_AI_TOOL_MESSAGE = "gen_ai.tool.message";
54
+ export declare const EVENT_GEN_AI_ASSISTANT_MESSAGE = "gen_ai.assistant.message";
55
+ export declare const EVENT_GEN_AI_CHOICE = "gen_ai.choice";
56
+ export declare const SPAN_INTERACTION = "pi.interaction";
57
+ export declare const SPAN_LLM_REQUEST = "pi.llm_request";
58
+ export declare const SPAN_TURN = "pi.turn";
59
+ export declare const spanToolName: (name: string) => string;
60
+ export declare const GEN_AI_SYSTEM_PI = "pi";
61
+ export type ContentCapture = "metadata_only" | "no_tool_content" | "full";
62
+ export declare function clampAttr(value: unknown): string;
63
+ /**
64
+ * Pull token + cost data off a pi assistant message.usage object onto a span attributes record.
65
+ * Tolerant of missing fields — pi providers differ in what they populate.
66
+ */
67
+ export declare function applyUsageAttrs(attrs: Record<string, unknown>, usage: unknown): void;
package/dist/attrs.js ADDED
@@ -0,0 +1,124 @@
1
+ /**
2
+ * gen_ai.* attribute and metric constants.
3
+ *
4
+ * Names follow the OTel GenAI semantic conventions:
5
+ * https://opentelemetry.io/docs/specs/semconv/gen-ai/
6
+ */
7
+ // Conversation / agent identity
8
+ export const ATTR_CONVERSATION_ID = "gen_ai.conversation.id";
9
+ export const ATTR_AGENT_NAME = "gen_ai.agent.name";
10
+ export const ATTR_AGENT_VERSION = "gen_ai.agent.version";
11
+ export const ATTR_USER_ID = "user.id";
12
+ // Errors
13
+ export const ATTR_ERROR_TYPE = "error.type";
14
+ // Operation / provider
15
+ export const ATTR_OPERATION_NAME = "gen_ai.operation.name";
16
+ export const ATTR_SYSTEM = "gen_ai.system";
17
+ export const ATTR_PROVIDER_NAME = "gen_ai.provider.name";
18
+ // Request
19
+ export const ATTR_REQUEST_MODEL = "gen_ai.request.model";
20
+ export const ATTR_REQUEST_MAX_TOKENS = "gen_ai.request.max_tokens";
21
+ export const ATTR_REQUEST_TEMPERATURE = "gen_ai.request.temperature";
22
+ export const ATTR_REQUEST_TOP_P = "gen_ai.request.top_p";
23
+ // Response
24
+ export const ATTR_RESPONSE_ID = "gen_ai.response.id";
25
+ export const ATTR_RESPONSE_MODEL = "gen_ai.response.model";
26
+ export const ATTR_FINISH_REASONS = "gen_ai.response.finish_reasons";
27
+ // Usage
28
+ export const ATTR_INPUT_TOKENS = "gen_ai.usage.input_tokens";
29
+ export const ATTR_OUTPUT_TOKENS = "gen_ai.usage.output_tokens";
30
+ export const ATTR_TOKEN_TYPE = "gen_ai.token.type";
31
+ export const ATTR_CACHE_READ_TOKENS = "gen_ai.usage.cache_read_input_tokens";
32
+ export const ATTR_CACHE_WRITE_TOKENS = "gen_ai.usage.cache_write_input_tokens";
33
+ export const ATTR_CACHE_CREATION_TOKENS = "gen_ai.usage.cache_creation_input_tokens";
34
+ export const ATTR_REASONING_TOKENS = "gen_ai.usage.reasoning_tokens";
35
+ // Tool
36
+ export const ATTR_TOOL_NAME = "gen_ai.tool.name";
37
+ export const ATTR_TOOL_CALL_ID = "gen_ai.tool.call.id";
38
+ export const ATTR_TOOL_TYPE = "gen_ai.tool.type";
39
+ export const ATTR_TOOL_DESCRIPTION = "gen_ai.tool.description";
40
+ export const ATTR_TOOL_CALL_ARGUMENTS = "gen_ai.tool.call.arguments";
41
+ export const ATTR_TOOL_CALL_RESULT = "gen_ai.tool.call.result";
42
+ // Pi-specific attributes (SPEC §5.4)
43
+ export const ATTR_PI_SESSION_ID = "pi.session.id";
44
+ export const ATTR_SESSION_ID = "session.id";
45
+ export const ATTR_PI_CWD = "pi.cwd";
46
+ export const ATTR_PI_TURN_COUNT = "pi.turn_count";
47
+ export const ATTR_PI_TURN_INDEX = "pi.turn_index";
48
+ export const ATTR_PI_TOOL_COUNT = "pi.tool_count";
49
+ export const ATTR_PI_TOOL_NAME = "pi.tool.name";
50
+ export const ATTR_PI_TOOL_CALL_ID = "pi.tool.call_id";
51
+ export const ATTR_PI_TOOL_IS_ERROR = "pi.tool.is_error";
52
+ export const ATTR_PI_TOOL_INPUT = "pi.tool.input";
53
+ export const ATTR_PI_TOOL_OUTPUT = "pi.tool.output";
54
+ export const ATTR_PI_COST_USD = "pi.cost.usd";
55
+ export const ATTR_PI_USER_PROMPT = "pi.user_prompt";
56
+ export const ATTR_PI_USER_PROMPT_LENGTH = "pi.user_prompt_length";
57
+ // HTTP
58
+ export const ATTR_HTTP_STATUS_CODE = "http.response.status_code";
59
+ // GenAI message-list attributes (Aspire 9.x AI panel reads these on the LLM span)
60
+ export const ATTR_GEN_AI_INPUT_MESSAGES = "gen_ai.input.messages";
61
+ export const ATTR_GEN_AI_OUTPUT_MESSAGES = "gen_ai.output.messages";
62
+ // GenAI span events
63
+ export const EVENT_GEN_AI_USER_MESSAGE = "gen_ai.user.message";
64
+ export const EVENT_GEN_AI_TOOL_MESSAGE = "gen_ai.tool.message";
65
+ export const EVENT_GEN_AI_ASSISTANT_MESSAGE = "gen_ai.assistant.message";
66
+ export const EVENT_GEN_AI_CHOICE = "gen_ai.choice";
67
+ // Span names
68
+ export const SPAN_INTERACTION = "pi.interaction";
69
+ export const SPAN_LLM_REQUEST = "pi.llm_request";
70
+ export const SPAN_TURN = "pi.turn";
71
+ export const spanToolName = (name) => `pi.tool.${name}`;
72
+ // Value used for ATTR_SYSTEM across this extension.
73
+ export const GEN_AI_SYSTEM_PI = "pi";
74
+ /**
75
+ * Truncate a string attribute to ~60 KB (Claude Code parity, SPEC §7).
76
+ */
77
+ const MAX_ATTR_BYTES = 60 * 1024;
78
+ export function clampAttr(value) {
79
+ let s;
80
+ if (typeof value === "string")
81
+ s = value;
82
+ else {
83
+ try {
84
+ s = JSON.stringify(value);
85
+ }
86
+ catch {
87
+ s = String(value);
88
+ }
89
+ }
90
+ if (Buffer.byteLength(s, "utf8") <= MAX_ATTR_BYTES)
91
+ return s;
92
+ // Byte-safe truncation: shrink until <= limit
93
+ let end = MAX_ATTR_BYTES;
94
+ while (Buffer.byteLength(s.slice(0, end), "utf8") > MAX_ATTR_BYTES - 32)
95
+ end -= 64;
96
+ return `${s.slice(0, end)}…[truncated]`;
97
+ }
98
+ /**
99
+ * Pull token + cost data off a pi assistant message.usage object onto a span attributes record.
100
+ * Tolerant of missing fields — pi providers differ in what they populate.
101
+ */
102
+ export function applyUsageAttrs(attrs, usage) {
103
+ if (!usage || typeof usage !== "object")
104
+ return;
105
+ const u = usage;
106
+ const set = (k, v) => {
107
+ if (typeof v === "number" && Number.isFinite(v))
108
+ attrs[k] = v;
109
+ };
110
+ set(ATTR_INPUT_TOKENS, u.input ?? u.inputTokens ?? u.input_tokens);
111
+ set(ATTR_OUTPUT_TOKENS, u.output ?? u.outputTokens ?? u.output_tokens);
112
+ set(ATTR_CACHE_READ_TOKENS, u.cacheRead ?? u.cache_read ?? u.cacheReadTokens);
113
+ set(ATTR_CACHE_WRITE_TOKENS, u.cacheWrite ?? u.cache_write ?? u.cacheWriteTokens);
114
+ set(ATTR_CACHE_CREATION_TOKENS, u.cacheCreation ?? u.cache_creation ?? u.cacheCreationTokens);
115
+ set(ATTR_REASONING_TOKENS, u.reasoning ?? u.reasoningTokens ?? u.reasoning_tokens);
116
+ const cost = u.cost;
117
+ if (cost && typeof cost === "object") {
118
+ const total = cost.total;
119
+ if (typeof total === "number" && Number.isFinite(total)) {
120
+ attrs[ATTR_PI_COST_USD] = total;
121
+ }
122
+ }
123
+ }
124
+ //# sourceMappingURL=attrs.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"attrs.js","sourceRoot":"","sources":["../src/attrs.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,gCAAgC;AAChC,MAAM,CAAC,MAAM,oBAAoB,GAAG,wBAAwB,CAAC;AAC7D,MAAM,CAAC,MAAM,eAAe,GAAG,mBAAmB,CAAC;AACnD,MAAM,CAAC,MAAM,kBAAkB,GAAG,sBAAsB,CAAC;AACzD,MAAM,CAAC,MAAM,YAAY,GAAG,SAAS,CAAC;AAEtC,SAAS;AACT,MAAM,CAAC,MAAM,eAAe,GAAG,YAAY,CAAC;AAE5C,uBAAuB;AACvB,MAAM,CAAC,MAAM,mBAAmB,GAAG,uBAAuB,CAAC;AAC3D,MAAM,CAAC,MA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,IAAI,MAAM,CAAC,QAAQ,CAAC,CAAC,CAAC;YAAE,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC;IAChE,CAAC,CAAC;IACF,GAAG,CAAC,iBAAiB,EAAE,CAAC,CAAC,KAAK,IAAI,CAAC,CAAC,WAAW,IAAI,CAAC,CAAC,YAAY,CAAC,CAAC;IACnE,GAAG,CAAC,kBAAkB,EAAE,CAAC,CAAC,MAAM,IAAI,CAAC,CAAC,YAAY,IAAI,CAAC,CAAC,aAAa,CAAC,CAAC;IACvE,GAAG,CAAC,sBAAsB,EAAE,CAAC,CAAC,SAAS,IAAI,CAAC,CAAC,UAAU,IAAI,CAAC,CAAC,eAAe,CAAC,CAAC;IAC9E,GAAG,CACD,uBAAuB,EACvB,CAAC,CAAC,UAAU,IAAI,CAAC,CAAC,WAAW,IAAI,CAAC,CAAC,gBAAgB,CACpD,CAAC;IACF,GAAG,CACD,0BAA0B,EAC1B,CAAC,CAAC,aAAa,IAAI,CAAC,CAAC,cAAc,IAAI,CAAC,CAAC,mBAAmB,CAC7D,CAAC;IACF,GAAG,CACD,qBAAqB,EACrB,CAAC,CAAC,SAAS,IAAI,CAAC,CAAC,eAAe,IAAI,CAAC,CAAC,gBAAgB,CACvD,CAAC;IACF,MAAM,IAAI,GAAG,CAAC,CAAC,IAAI,CAAC;IACpB,IAAI,IAAI,IAAI,OAAO,IAAI,KAAK,QAAQ,EAAE,CAAC;QACrC,MAAM,KAAK,GAAI,IAAY,CAAC,KAAK,CAAC;QAClC,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,MAAM,CAAC,QAAQ,CAAC,KAAK,CAAC,EAAE,CAAC;YACxD,KAAK,CAAC,gBAAgB,CAAC,GAAG,KAAK,CAAC;QAClC,CAAC;IACH,CAAC;AACH,CAAC"}
@@ -0,0 +1,2 @@
1
+ import type { ExtensionAPI } from "@earendil-works/pi-coding-agent";
2
+ export declare function registerOtelCommand(pi: ExtensionAPI, getCwd: () => string | undefined): void;