Featured image of post Profiling LLM with OTel and Aspire

Profiling LLM with OTel and Aspire

A practical, reproducible guide to profiling LLM agent workflows, token consumption, and tool execution using GitHub Copilot CLI, OpenTelemetry (OTel), and a local Aspire Dashboard.

AI coding agents are no longer just completion engines; they plan tasks, delegate subagents, and execute shell tools autonomously. Yet without observability, these multi-turn interactions remain an impenetrable black box.

In this hands-on guide, we set up a 100% local profiling lab to inspect every LLM call, token metric, and tool invocation using GitHub Copilot CLI, OpenTelemetry (OTel), and the .NET Aspire Dashboard.


1. Core Concepts: OpenTelemetry & Aspire

What is OpenTelemetry (OTel) in GenAI?

OpenTelemetry (OTel) is the vendor-neutral Cloud Native Computing Foundation (CNCF) standard for collecting traces, metrics, and logs.

In modern LLM systems, OTel defines the GenAI Semantic Conventions (gen_ai.*), capturing:

  • Spans & Traces: Hierarchical trees detailing agent orchestration (invoke_agent), model queries (chat), and environment interactions (execute_tool).
  • Attributes: Exact model identifiers (gen_ai.request.model), finish reasons (gen_ai.response.finish_reasons), and temperature.
  • Token Metrics: Input/output token usage and Time-To-First-Token (TTFT) latency.

Why the .NET Aspire Dashboard?

.NET Aspire is an enterprise cloud-ready stack. However, we only use its standalone, zero-cloud OTel server & telemetry dashboard.

It runs locally, accepts standard OTLP (OpenTelemetry Protocol) streams over HTTP/gRPC, and provides an immediate UI with waterfall traces, latency breakdowns, and structured span attributes without requiring any SaaS account or external backend.


2. Architecture & Telemetry Flow

The Copilot CLI acts as an OTLP producer, transmitting traces over local HTTP protobuf to Aspire’s telemetry collector on port 4318. The developer monitors the live waterfall via Aspire’s web UI on port 18888.

sequenceDiagram autonumber actor Dev as Developer participant CLI as GitHub Copilot CLI (Agent) participant AspireServer as Aspire OTel Collector (:4318) participant AspireUI as Aspire Dashboard UI (:18888) participant LLM as GitHub Copilot Router (Fusion) Dev->>AspireServer: 1. Launch Aspire Dashboard (local OTLP receiver) Dev->>CLI: 2. Run PowerShell lab script (with /fleet prompt) activate CLI CLI->>LLM: 3. Invoke orchestrator model (task decomposition) LLM-->>CLI: Response: plan & subagent assignment CLI->>AspireServer: OTLP Span: invoke_agent & chat rect rgb(20, 30, 40) Note over CLI,LLM: Subagent Fleet Execution (clone, inspect, review) CLI->>CLI: Execute tool: pwsh.exe / git clone CLI->>AspireServer: OTLP Span: execute_tool powershell CLI->>LLM: Invoke subagent model (e.g. gpt-6-luna) LLM-->>CLI: Subagent tool call & review results CLI->>AspireServer: OTLP Span: chat gpt-6-luna (with token attributes) end CLI->>Dev: 4. Display task completion & session stats deactivate CLI Dev->>AspireUI: 5. Inspect traces, durations & span hierarchy AspireUI-->>Dev: Waterfall display of spans, latencies & tokens

3. Hands-On Lab Setup

Terminal 1: Launch the Local Aspire Dashboard

Run Aspire’s standalone dashboard via npx (no .NET installation required):

1
2
3
4
$env:ASPIRE_CLI_TELEMETRY_OPTOUT = "1"
$env:ASPIRE_DASHBOARD_TELEMETRY_OPTOUT = "true"

npx -y @microsoft/aspire-cli@13.5.3 dashboard run

Aspire will start its local OTLP collector on port 4318 and provide an authenticated web dashboard URL on http://localhost:18888.


Terminal 2: Run the Instrumented Copilot CLI

Save and run this portable, self-contained PowerShell script. It automatically provisions an isolated workspace directory, injects OTel environment variables, and launches Copilot CLI:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# ==============================================================================
# OpenTelemetry Profiling - GitHub Copilot CLI
# Portable & Reproducible Script (Windows / macOS / Linux via PowerShell)
# ==============================================================================

# 1. Configurable variables
$ModelName    = "fusion"
$OtelEndpoint = "http://localhost:4318"
$RunId        = "run-$ModelName-$((Get-Date).ToString('yyyyMMdd-HHmmss'))"

# Dynamic home directory resolution
$WorkspaceDir = Join-Path $HOME "copilot-otel-workspace"

# 2. Automated workspace creation (idempotent)
if (-not (Test-Path -Path $WorkspaceDir)) {
    New-Item -ItemType Directory -Path $WorkspaceDir -Force | Out-Null
}

# 3. OpenTelemetry Configuration (OTLP HTTP Export)
$env:COPILOT_OTEL_ENABLED                               = "true"
$env:COPILOT_OTEL_EXPORTER_TYPE                         = "otlp-http"
$env:OTEL_EXPORTER_OTLP_ENDPOINT                        = $OtelEndpoint
$env:OTEL_EXPORTER_OTLP_PROTOCOL                        = "http/protobuf"
$env:OTEL_SERVICE_NAME                                  = "copilot-cli-fleet-test"
$env:OTEL_INSTRUMENTATION_GENAI_CAPTURE_MESSAGE_CONTENT = "true"

# Semantic attributes for run indexing and filtering
$env:OTEL_RESOURCE_ATTRIBUTES = "service.name=$($env:OTEL_SERVICE_NAME),model=$ModelName,experiment.run_id=$RunId"

# 4. Cleanup stale environment variables
Remove-Item Env:COPILOT_HOME -ErrorAction SilentlyContinue
Remove-Item Env:COPILOT_OTEL_FILE_EXPORTER_PATH -ErrorAction SilentlyContinue

# 5. Enter isolated workspace
Set-Location -Path $WorkspaceDir

# 6. Launch instrumented Copilot session
copilot `
    --model $ModelName `
    --no-custom-instructions `
    --no-auto-update `
    --disable-builtin-mcps `
    --excluded-tools=skill,session_store_sql

4. Subagent Delegation with /fleet

In Copilot CLI, the /fleet command delegates tasks to autonomous subagents running in parallel.

Here is the exact prompt executed during our benchmark:

1
2
3
4
/fleet
agent1: clone https://github.com/github-education-resources/edu-resource-guide.git in ~/repo and tell me the latest commit id
agent2: create html one page listing stat about agent1 task
agent3: rubber duck; ensure agent tasks are done and well performed

Copilot CLI Fleet Execution

Copilot Fusion evaluated the assignment and routed the subtasks to specialized models (such as gpt-6-luna), executing shell inspection, Git checkouts, and verification in sequence while consuming 0.7 AIC (Agent Interaction Credits).


5. Analyzing Traces in Aspire Dashboard

Navigate to http://localhost:18888 and select the Traces tab.

Trace Overview

The dashboard groups agent executions by service name (copilot-cli-fleet-test). Each run displays total elapsed time and span count:

Aspire Traces Overview

Notice the distinct runs: the /fleet multi-agent workload took 1m 06s across 31 spans, compared to faster, single-turn prompts taking between 3s and 27s.


Detailed Span Waterfall & GenAI Metadata

Drilling into the 1m 06s trace reveals the exact execution breakdown:

Aspire Trace Details

Key insights visible in the timeline:

  • Span Decomposition: The root invoke_agent span orchestrates alternating chat gpt-6-luna inference spans (3.42s, 4.48s, 2.68s) and execute_tool powershell pwsh.exe execution spans (2.18s, 4.36s).
  • GenAI Semantic Attributes: The right panel displays standard OTel attributes:
    • gen_ai.operation.name: chat
    • gen_ai.provider.name: github
    • gen_ai.request.model: gpt-6-luna
    • gen_ai.response.finish_reasons: ["tool_calls"]

6. Real-World Use Cases for LLM Profiling

Why does telemetry matter when building or choosing AI developer tooling?

1. Token Economics & Bottleneck Discovery

Visualizing spans separates inference latency (time spent waiting on the remote model provider) from tool execution latency (local disk I/O, compilation, slow shell commands). This enables teams to:

  • Optimize prompt sizes and context windows to reduce token waste.
  • Spot runaway retry loops or redundant tool calls before billing spirals.
  • Track Time-To-First-Token (TTFT) and caching efficiency.

2. Understanding Agent Harnessing

A common misconception is that model capability depends solely on the underlying weights. In practice, harnessing dictates performance:

The Harnessing Effect: Two tools using the exact same model (e.g. GPT-4o or Gemini 1.5 Pro) with the exact same prompt often produce radically different output quality, execution times, and token costs.

Why?

  • System Prompt Framing: The hidden system instructions preloaded into the context window.
  • Tool Schema Design: How tool signatures and JSON schemas are serialized and parsed.
  • Orchestration Logic: Re-prompting strategies, error recovery, and subagent delegation protocols.

Profiling with OpenTelemetry exposes the harness: you see exactly what instructions are sent, which tools are called, how many turns are taken, and where latency originates.