[#923] OTel improvements: Instrument copilotstudio-client#1018
Open
ceciliaavila wants to merge 4 commits intosouthworks/feature/otelfrom
Open
[#923] OTel improvements: Instrument copilotstudio-client#1018ceciliaavila wants to merge 4 commits intosouthworks/feature/otelfrom
ceciliaavila wants to merge 4 commits intosouthworks/feature/otelfrom
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR adds OpenTelemetry tracing/metrics instrumentation for @microsoft/agents-copilotstudio-client by extending @microsoft/agents-telemetry with a manually-managed span helper and introducing new Copilot Studio span/metric names.
Changes:
- Added
managedSpansupport inagents-telemetryfor long-lived operations that can’t usestartActiveSpancallbacks (e.g., async generators/streaming). - Added new Copilot Studio Client span + metric constants and client-side instrumentation (request, streaming, webchat connection).
- Introduced a Copilot Studio Client metrics module and wired telemetry dependency into the client package.
Reviewed changes
Copilot reviewed 9 out of 10 changed files in this pull request and generated 7 comments.
Show a summary per file
| File | Description |
|---|---|
| packages/agents-telemetry/src/trace.ts | Adds startManagedSpan helper and managed span types. |
| packages/agents-telemetry/src/index.mts | Exports managedSpan and managed span types (ESM). |
| packages/agents-telemetry/src/index.cts | Exports managedSpan and managed span types (CJS). |
| packages/agents-telemetry/src/constants.ts | Adds Copilot Studio Client span and metric names. |
| packages/agents-copilotstudio-client/src/observability/metrics.ts | Defines Copilot Studio Client meters/counters/histograms. |
| packages/agents-copilotstudio-client/src/observability/index.ts | Re-exports observability helpers. |
| packages/agents-copilotstudio-client/src/copilotStudioWebChat.ts | Adds connection-level managed span + webchat metrics/events. |
| packages/agents-copilotstudio-client/src/copilotStudioClient.ts | Adds managed spans + request/streaming metrics instrumentation. |
| packages/agents-copilotstudio-client/package.json | Adds @microsoft/agents-telemetry dependency and updates browser build target. |
| package-lock.json | Locks the new dependency. |
Comments suppressed due to low confidence (1)
packages/agents-copilotstudio-client/src/copilotStudioWebChat.ts:319
- The connection-level managed span is only ended in the explicit
end()method. IfstartConversationStreaming()throws insideactivity$, or if a consumer unsubscribes / the observable errors, the span can remain open. Consider adding teardown/error handling so the span ends on observable completion/error/unsubscribe (and useendWithErrorwhen appropriate).
const managed = managedSpan(SpanNames.COPILOT_CREATE_CONNECTION, {
attributes: {
'copilot.webchat.show_typing': settings?.showTyping ?? 'unknown'
}
})
const connectionStatus$ = new BehaviorSubject(0)
const activity$ = createObservable<Partial<Activity>>(async (subscriber) => {
activitySubscriber = subscriber
const handleAcknowledgementOnce = once(async (): Promise<void> => {
connectionStatus$.next(2)
await Promise.resolve() // Webchat requires an extra tick to process the connection status change
})
// When resuming (shouldStart === false), transition straight to connected
if (!shouldStart || started) {
await handleAcknowledgementOnce()
return
}
started = true
logger.debug('--> Connection established.')
CopilotStudioClientMetrics.webchatConnectionsCounter.add(1)
notifyTyping()
for await (const activity of client.startConversationStreaming()) {
delete activity.replyToId
if (!conversation && activity.conversation) {
conversation = activity.conversation
}
if (activity.conversation?.id) {
activeConversationId = activity.conversation.id
}
await handleAcknowledgementOnce()
notifyActivity(activity)
managed.span.addEvent('Activity received from Copilot Studio', {
'copilot.webchat.activity.type': activity.type,
'copilot.webchat.activity.conversation_id': activity.conversation?.id ?? 'unknown'
})
}
// If no activities received from bot, we should still acknowledge.
await handleAcknowledgementOnce()
})
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Addresses #923
Description
Adds OpenTelemetry tracing/metrics instrumentation for @microsoft/agents-copilotstudio-client and extends @microsoft/agents-telemetry to support manually managed spans for long-lived/streaming operations.
Detailed Changes:
Testing
These images show the traces, events, and metrics exported from the library.



