Skip to content

Commit 506427d

Browse files
stephentoubCopilot
andcommitted
Address PR feedback
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent 3faaed5 commit 506427d

6 files changed

Lines changed: 26 additions & 29 deletions

File tree

dotnet/src/Client.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1337,7 +1337,7 @@ public async Task<ToolCallResponse> OnToolCall(string sessionId,
13371337
serverAddress: session.TelemetryServerAddress,
13381338
serverPort: session.TelemetryServerPort,
13391339
error: operationError,
1340-
operationName: OpenTelemetryConsts.GenAI.ExecuteTool);
1340+
operationName: OpenTelemetryConsts.GenAI.OperationNames.ExecuteTool);
13411341
}
13421342
}
13431343
}

dotnet/src/CopilotTelemetry.cs

Lines changed: 17 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -106,12 +106,12 @@ public CopilotTelemetry(TelemetryConfig? config)
106106
}
107107

108108
string displayName = string.IsNullOrWhiteSpace(agentName)
109-
? OpenTelemetryConsts.GenAI.InvokeAgent
110-
: $"{OpenTelemetryConsts.GenAI.InvokeAgent} {agentName}";
109+
? OpenTelemetryConsts.GenAI.OperationNames.InvokeAgent
110+
: $"{OpenTelemetryConsts.GenAI.OperationNames.InvokeAgent} {agentName}";
111111

112112
ActivityTagsCollection tags = new()
113113
{
114-
{ OpenTelemetryConsts.GenAI.Operation.Name, OpenTelemetryConsts.GenAI.InvokeAgent },
114+
{ OpenTelemetryConsts.GenAI.Operation.Name, OpenTelemetryConsts.GenAI.OperationNames.InvokeAgent },
115115
{ OpenTelemetryConsts.GenAI.Provider.Name, providerName },
116116
{ OpenTelemetryConsts.GenAI.Agent.Id, sessionId },
117117
{ OpenTelemetryConsts.GenAI.Conversation.Id, sessionId },
@@ -159,12 +159,12 @@ public CopilotTelemetry(TelemetryConfig? config)
159159
}
160160

161161
string displayName = string.IsNullOrWhiteSpace(model)
162-
? OpenTelemetryConsts.GenAI.Chat
163-
: $"{OpenTelemetryConsts.GenAI.Chat} {model}";
162+
? OpenTelemetryConsts.GenAI.OperationNames.Chat
163+
: $"{OpenTelemetryConsts.GenAI.OperationNames.Chat} {model}";
164164

165165
ActivityTagsCollection tags = new()
166166
{
167-
{ OpenTelemetryConsts.GenAI.Operation.Name, OpenTelemetryConsts.GenAI.Chat },
167+
{ OpenTelemetryConsts.GenAI.Operation.Name, OpenTelemetryConsts.GenAI.OperationNames.Chat },
168168
{ OpenTelemetryConsts.GenAI.Provider.Name, providerName },
169169
};
170170

@@ -198,11 +198,11 @@ public CopilotTelemetry(TelemetryConfig? config)
198198
return null;
199199
}
200200

201-
string displayName = $"{OpenTelemetryConsts.GenAI.ExecuteTool} {toolName}";
201+
string displayName = $"{OpenTelemetryConsts.GenAI.OperationNames.ExecuteTool} {toolName}";
202202

203203
ActivityTagsCollection tags = new()
204204
{
205-
{ OpenTelemetryConsts.GenAI.Operation.Name, OpenTelemetryConsts.GenAI.ExecuteTool },
205+
{ OpenTelemetryConsts.GenAI.Operation.Name, OpenTelemetryConsts.GenAI.OperationNames.ExecuteTool },
206206
{ OpenTelemetryConsts.GenAI.Tool.Name, toolName },
207207
{ OpenTelemetryConsts.GenAI.Tool.CallId, toolCallId },
208208
{ OpenTelemetryConsts.GenAI.Tool.Type, "function" },
@@ -297,7 +297,7 @@ public void RecordTimeToFirstChunk(
297297
TimeToFirstChunkHistogram.Record(
298298
durationSeconds,
299299
CreateMetricTags(
300-
OpenTelemetryConsts.GenAI.Chat,
300+
OpenTelemetryConsts.GenAI.OperationNames.Chat,
301301
requestModel,
302302
responseModel,
303303
providerName,
@@ -319,7 +319,7 @@ public void RecordTimePerOutputChunk(
319319
TimePerOutputChunkHistogram.Record(
320320
durationSeconds,
321321
CreateMetricTags(
322-
OpenTelemetryConsts.GenAI.Chat,
322+
OpenTelemetryConsts.GenAI.OperationNames.Chat,
323323
requestModel,
324324
responseModel,
325325
providerName,
@@ -1152,7 +1152,7 @@ private void CompleteChatTurnLocked(Exception? error)
11521152
ServerAddress,
11531153
ServerPort,
11541154
error,
1155-
OpenTelemetryConsts.GenAI.Chat);
1155+
OpenTelemetryConsts.GenAI.OperationNames.Chat);
11561156

11571157
// Per-turn operation duration
11581158
if (_telemetry.OperationDurationHistogram.Enabled)
@@ -1165,7 +1165,7 @@ private void CompleteChatTurnLocked(Exception? error)
11651165
ServerAddress,
11661166
ServerPort,
11671167
error: error,
1168-
operationName: OpenTelemetryConsts.GenAI.Chat);
1168+
operationName: OpenTelemetryConsts.GenAI.OperationNames.Chat);
11691169
}
11701170

11711171
_firstOutputChunkRecorded = false;
@@ -1310,7 +1310,7 @@ private void CompleteAgentTurnLocked(Exception? error)
13101310
ServerAddress,
13111311
ServerPort,
13121312
error: error,
1313-
operationName: OpenTelemetryConsts.GenAI.InvokeAgent);
1313+
operationName: OpenTelemetryConsts.GenAI.OperationNames.InvokeAgent);
13141314
}
13151315

13161316
activity.Dispose();
@@ -1324,7 +1324,7 @@ private void RecordOutputChunkMetricLocked()
13241324
{
13251325
Debug.Assert(Monitor.IsEntered(_lock));
13261326

1327-
if (!_isStreaming)
1327+
if (!_isStreaming || _turnTimestamp == 0)
13281328
{
13291329
return;
13301330
}
@@ -1433,12 +1433,11 @@ private void ProcessSubagentEventLocked(SubagentState subagent, SessionEvent ses
14331433
case AssistantUsageEvent usageEvent:
14341434
subagent.ResponseModel = usageEvent.Data.Model;
14351435

1436-
// Update response model on both spans if the subagent is using
1436+
// Update response model on chat span if the subagent is using
14371437
// a different model than what was set at span creation time.
14381438
if (!string.IsNullOrWhiteSpace(usageEvent.Data.Model))
14391439
{
14401440
subagent.ChatActivity?.SetTag(OpenTelemetryConsts.GenAI.Response.Model, usageEvent.Data.Model);
1441-
subagent.InvokeAgentActivity?.SetTag(OpenTelemetryConsts.GenAI.Response.Model, usageEvent.Data.Model);
14421441
}
14431442

14441443
if (!string.IsNullOrWhiteSpace(usageEvent.Data.ApiCallId))
@@ -1637,7 +1636,7 @@ private void CompleteSubagentLocked(string toolCallId, Exception? error)
16371636
ServerAddress,
16381637
ServerPort,
16391638
error,
1640-
OpenTelemetryConsts.GenAI.Chat);
1639+
OpenTelemetryConsts.GenAI.OperationNames.Chat);
16411640

16421641
chatActivity.Dispose();
16431642
}
@@ -1706,7 +1705,7 @@ private void CompleteSubagentLocked(string toolCallId, Exception? error)
17061705
ServerAddress,
17071706
ServerPort,
17081707
error: error,
1709-
operationName: OpenTelemetryConsts.GenAI.InvokeAgent);
1708+
operationName: OpenTelemetryConsts.GenAI.OperationNames.InvokeAgent);
17101709
}
17111710

17121711
invokeActivity.Dispose();

dotnet/src/OpenTelemetryConsts.cs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,12 @@ public static class Server
3636

3737
public static class GenAI
3838
{
39-
public const string Chat = "chat";
40-
public const string InvokeAgent = "invoke_agent";
41-
public const string ExecuteTool = "execute_tool";
39+
public static class OperationNames
40+
{
41+
public const string Chat = "chat";
42+
public const string InvokeAgent = "invoke_agent";
43+
public const string ExecuteTool = "execute_tool";
44+
}
4245

4346
public static class Operation
4447
{

go/copilot_telemetry.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1438,7 +1438,6 @@ func (t *agentTurnTracker) processSubagentEventLocked(sub *subagentState, event
14381438
if sub.chatSpan != nil {
14391439
sub.chatSpan.SetAttributes(attribute.String(otelGenAIResponseModel, *event.Data.Model))
14401440
}
1441-
sub.invokeAgentSpan.SetAttributes(attribute.String(otelGenAIResponseModel, *event.Data.Model))
14421441
}
14431442
if event.Data.APICallID != nil && *event.Data.APICallID != "" {
14441443
sub.responseID = *event.Data.APICallID

nodejs/src/copilot-telemetry.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1590,11 +1590,9 @@ export class AgentTurnTracker {
15901590
switch (event.type) {
15911591
case "assistant.usage": {
15921592
const data = (event as Extract<SessionEvent, { type: "assistant.usage" }>).data;
1593-
subagent.responseModel = data.model;
1594-
15951593
if (data.model) {
1594+
subagent.responseModel = data.model;
15961595
subagent.chatSpan?.setAttribute(ATTR.GEN_AI_RESPONSE_MODEL, data.model);
1597-
subagent.invokeAgentSpan.setAttribute(ATTR.GEN_AI_RESPONSE_MODEL, data.model);
15981596
}
15991597

16001598
if (data.apiCallId) {

python/copilot/_copilot_telemetry.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1532,12 +1532,10 @@ def _process_subagent_event(self, subagent: _SubagentState, event: SessionEvent)
15321532
if event.type == SessionEventType.ASSISTANT_USAGE:
15331533
data = event.data
15341534
model = getattr(data, "model", None)
1535-
subagent.response_model = model
1536-
15371535
if model:
1536+
subagent.response_model = model
15381537
if subagent.chat_span is not None:
15391538
subagent.chat_span.set_attribute(ATTR_GEN_AI_RESPONSE_MODEL, model)
1540-
subagent.invoke_agent_span.set_attribute(ATTR_GEN_AI_RESPONSE_MODEL, model)
15411539

15421540
api_call_id = getattr(data, "api_call_id", None)
15431541
provider_call_id = getattr(data, "provider_call_id", None)

0 commit comments

Comments
 (0)