Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
microsoft
GitHub Repository: microsoft/vscode
Path: blob/main/extensions/copilot/src/platform/otel/common/genAiAttributes.ts
13401 views
1
/*---------------------------------------------------------------------------------------------
2
* Copyright (c) Microsoft Corporation. All rights reserved.
3
* Licensed under the MIT License. See License.txt in the project root for license information.
4
*--------------------------------------------------------------------------------------------*/
5
6
// gen_ai.operation.name values
7
export const GenAiOperationName = {
8
CHAT: 'chat',
9
INVOKE_AGENT: 'invoke_agent',
10
EXECUTE_TOOL: 'execute_tool',
11
EMBEDDINGS: 'embeddings',
12
/** Extension-specific: standalone markdown content event */
13
CONTENT_EVENT: 'content_event',
14
/** Extension-specific: hook command execution */
15
EXECUTE_HOOK: 'execute_hook',
16
} as const;
17
18
// gen_ai.provider.name values
19
export const GenAiProviderName = {
20
GITHUB: 'github',
21
OPENAI: 'openai',
22
ANTHROPIC: 'anthropic',
23
AZURE_AI_OPENAI: 'azure.ai.openai',
24
GEMINI: 'gemini',
25
} as const;
26
27
// gen_ai.token.type values
28
export const GenAiTokenType = {
29
INPUT: 'input',
30
OUTPUT: 'output',
31
} as const;
32
33
// gen_ai.tool.type values
34
export const GenAiToolType = {
35
FUNCTION: 'function',
36
EXTENSION: 'extension',
37
} as const;
38
39
/**
40
* OTel GenAI semantic convention attribute keys.
41
* @see https://github.com/open-telemetry/semantic-conventions/blob/main/docs/gen-ai/gen-ai-spans.md
42
*/
43
export const GenAiAttr = {
44
// Core
45
OPERATION_NAME: 'gen_ai.operation.name',
46
PROVIDER_NAME: 'gen_ai.provider.name',
47
48
// Request
49
REQUEST_MODEL: 'gen_ai.request.model',
50
REQUEST_TEMPERATURE: 'gen_ai.request.temperature',
51
REQUEST_MAX_TOKENS: 'gen_ai.request.max_tokens',
52
REQUEST_TOP_P: 'gen_ai.request.top_p',
53
REQUEST_FREQUENCY_PENALTY: 'gen_ai.request.frequency_penalty',
54
REQUEST_PRESENCE_PENALTY: 'gen_ai.request.presence_penalty',
55
REQUEST_SEED: 'gen_ai.request.seed',
56
REQUEST_STOP_SEQUENCES: 'gen_ai.request.stop_sequences',
57
58
// Response
59
RESPONSE_MODEL: 'gen_ai.response.model',
60
RESPONSE_ID: 'gen_ai.response.id',
61
RESPONSE_FINISH_REASONS: 'gen_ai.response.finish_reasons',
62
63
// Usage
64
USAGE_INPUT_TOKENS: 'gen_ai.usage.input_tokens',
65
USAGE_OUTPUT_TOKENS: 'gen_ai.usage.output_tokens',
66
USAGE_CACHE_READ_INPUT_TOKENS: 'gen_ai.usage.cache_read.input_tokens',
67
USAGE_CACHE_CREATION_INPUT_TOKENS: 'gen_ai.usage.cache_creation.input_tokens',
68
/** Custom: reasoning/thinking token count (not yet standardized in GenAI conventions) */
69
USAGE_REASONING_TOKENS: 'gen_ai.usage.reasoning_tokens',
70
71
// Conversation
72
CONVERSATION_ID: 'gen_ai.conversation.id',
73
OUTPUT_TYPE: 'gen_ai.output.type',
74
75
// Token type (for metrics)
76
TOKEN_TYPE: 'gen_ai.token.type',
77
78
// Agent
79
AGENT_NAME: 'gen_ai.agent.name',
80
AGENT_ID: 'gen_ai.agent.id',
81
AGENT_VERSION: 'gen_ai.agent.version',
82
AGENT_DESCRIPTION: 'gen_ai.agent.description',
83
84
// Tool
85
TOOL_NAME: 'gen_ai.tool.name',
86
TOOL_TYPE: 'gen_ai.tool.type',
87
TOOL_CALL_ID: 'gen_ai.tool.call.id',
88
TOOL_DESCRIPTION: 'gen_ai.tool.description',
89
TOOL_CALL_ARGUMENTS: 'gen_ai.tool.call.arguments',
90
TOOL_CALL_RESULT: 'gen_ai.tool.call.result',
91
92
// Content (opt-in)
93
INPUT_MESSAGES: 'gen_ai.input.messages',
94
OUTPUT_MESSAGES: 'gen_ai.output.messages',
95
SYSTEM_INSTRUCTIONS: 'gen_ai.system_instructions',
96
TOOL_DEFINITIONS: 'gen_ai.tool.definitions',
97
} as const;
98
99
/**
100
* Extension-specific attribute keys (custom namespace).
101
*/
102
export const CopilotChatAttr = {
103
LOCATION: 'copilot_chat.location',
104
INTENT: 'copilot_chat.intent',
105
TURN_INDEX: 'copilot_chat.turn.index',
106
TURN_COUNT: 'copilot_chat.turn_count',
107
TOOL_CALL_ROUND: 'copilot_chat.tool_call_round',
108
API_TYPE: 'copilot_chat.api_type',
109
FETCHER: 'copilot_chat.fetcher',
110
DEBUG_NAME: 'copilot_chat.debug_name',
111
ENDPOINT_TYPE: 'copilot_chat.endpoint_type',
112
MAX_PROMPT_TOKENS: 'copilot_chat.request.max_prompt_tokens',
113
TIME_TO_FIRST_TOKEN: 'copilot_chat.time_to_first_token',
114
SESSION_ID: 'copilot_chat.session_id',
115
SERVER_REQUEST_ID: 'copilot_chat.server_request_id',
116
CANCELED: 'copilot_chat.canceled',
117
/** Extended thinking/reasoning content (content-gated) */
118
REASONING_CONTENT: 'copilot_chat.reasoning_content',
119
/** User's actual typed message text, extracted from prompt context */
120
USER_REQUEST: 'copilot_chat.user_request',
121
/** Resolved context section (code snippets, file contents, etc.) */
122
PROMPT_CONTEXT: 'copilot_chat.prompt_context',
123
/** Custom instructions section */
124
PROMPT_INSTRUCTIONS: 'copilot_chat.prompt_instructions',
125
/** VS Code chat session ID from CapturingToken — the definitive session identifier */
126
CHAT_SESSION_ID: 'copilot_chat.chat_session_id',
127
/** Parent chat session ID for linking child sessions (e.g., title, categorization) to their parent */
128
PARENT_CHAT_SESSION_ID: 'copilot_chat.parent_chat_session_id',
129
/** Debug log label for child sessions (e.g., 'title', 'categorization', 'runSubagent') */
130
DEBUG_LOG_LABEL: 'copilot_chat.debug_log_label',
131
/** Markdown content for standalone content events */
132
MARKDOWN_CONTENT: 'copilot_chat.markdown_content',
133
/** Edit source: inline_chat, chat_editing, chat_editing_hunk, apply_patch, replace_string, code_mapper */
134
EDIT_SOURCE: 'copilot_chat.edit.source',
135
/** Edit outcome: accepted, rejected, saved, unknown */
136
EDIT_OUTCOME: 'copilot_chat.edit.outcome',
137
/** Language identifier of the document */
138
LANGUAGE_ID: 'copilot_chat.language_id',
139
/** Time delay in milliseconds between acceptance and measurement */
140
TIME_DELAY_MS: 'copilot_chat.time_delay_ms',
141
/** Whether additional unactioned edits remain */
142
HAS_REMAINING_EDITS: 'copilot_chat.has_remaining_edits',
143
/** Git branch name (HEAD) */
144
REPO_HEAD_BRANCH_NAME: 'copilot_chat.repo.head_branch_name',
145
/** Git commit hash (HEAD) */
146
REPO_HEAD_COMMIT_HASH: 'copilot_chat.repo.head_commit_hash',
147
/** Normalized remote fetch URL */
148
REPO_REMOTE_URL: 'copilot_chat.repo.remote_url',
149
/** File path relative to the repository root */
150
FILE_RELATIVE_PATH: 'copilot_chat.file.relative_path',
151
/** Hook type / event name (e.g. PreToolUse, PostToolUse, Stop) */
152
HOOK_TYPE: 'copilot_chat.hook_type',
153
/** Serialized hook command input (truncated; emitters may or may not gate on captureContent — used by the Agent Debug Log panel) */
154
HOOK_INPUT: 'copilot_chat.hook_input',
155
/** Serialized hook command output (truncated; emitters may or may not gate on captureContent — used by the Agent Debug Log panel) */
156
HOOK_OUTPUT: 'copilot_chat.hook_output',
157
/** Hook result kind: 'success', 'error', or 'non_blocking_error' */
158
HOOK_RESULT_KIND: 'copilot_chat.hook_result_kind',
159
/** Custom chat mode name (when a custom mode is active) */
160
MODE_NAME: 'copilot_chat.mode_name',
161
/** Aggregated session cost in USD (Claude agent) */
162
TOTAL_COST_USD: 'copilot_chat.total_cost_usd',
163
} as const;
164
165
export type EditSource = 'inline_chat' | 'chat_editing' | 'chat_editing_hunk' | 'apply_patch' | 'replace_string' | 'code_mapper';
166
export type EditOutcome = 'accepted' | 'rejected' | 'saved' | 'unknown';
167
168
/**
169
* Standard OTel attributes used alongside GenAI attributes.
170
*/
171
export const StdAttr = {
172
ERROR_TYPE: 'error.type',
173
SERVER_ADDRESS: 'server.address',
174
SERVER_PORT: 'server.port',
175
} as const;
176
177
/**
178
* Attribute keys emitted by the Copilot CLI SDK's native OTel instrumentation
179
* (read by the bridge processor and the debug panel; the extension itself does
180
* not produce these).
181
*/
182
export const CopilotCliSdkAttr = {
183
HOOK_TYPE: 'github.copilot.hook.type',
184
HOOK_INVOCATION_ID: 'github.copilot.hook.invocation_id',
185
} as const;
186
187