Skip to main content

Sending GitHub Copilot telemetry to Application Insights

In a previous post I showed how to send the GitHub Copilot OpenTelemetry data to the Aspire Dashboard. Great for "what just happened on my machine?", but the data is gone when the container stops. And nobody else on the team can see it.

So, the question becomes: how do we get the same data into Application Insights?

There are two possible routes we can try: through an OpenTelemetry Collector, or directly to the OTLP endpoint of Application Insights.

In this post we focus on the OpenTelemetry Collector. This is probably the easiest one and the one you’ll find in the documentation.

We’ll put an OpenTelemetry Collector between Copilot Chat and Application Insights:

VS Code Copilot Chat
        │ OTLP/HTTP
        ▼
OpenTelemetry Collector
        │ Azure Monitor exporter
        ▼
Application Insights

The collector receives standard OpenTelemetry data and forwards it using the Application Insights connection string.

Create an Application Insights resource

Create an Application Insights resource in Azure, then copy its connection string from the resource’s Overview page.

You’ll also need Docker and VS Code with Copilot Chat.

Configure the collector

Create a file called otel-collector-config.yaml:

receivers:
  otlp:
    protocols:
      http:
        endpoint: 0.0.0.0:4318

processors:
  batch:

exporters:
  azuremonitor:
    connection_string: ${env:APPLICATIONINSIGHTS_CONNECTION_STRING}

service:
  pipelines:
    traces:
      receivers: [otlp]
      processors: [batch]
      exporters: [azuremonitor]
    metrics:
      receivers: [otlp]
      processors: [batch]
      exporters: [azuremonitor]
    logs:
      receivers: [otlp]
      processors: [batch]
      exporters: [azuremonitor]

We need the contrib collector distribution because it includes the Azure Monitor exporter. The exporter maps OpenTelemetry spans, metrics, and logs into Application Insights telemetry.

Start it from PowerShell:

$env:APPLICATIONINSIGHTS_CONNECTION_STRING = "<your-connection-string>"

docker run --rm --name copilot-otel-collector `
  -p 127.0.0.1:4318:4318 `
  -e APPLICATIONINSIGHTS_CONNECTION_STRING `
  -v "${PWD}\otel-collector-config.yaml:/etc/otelcol-contrib/config.yaml:ro" `
  otel/opentelemetry-collector-contrib:latest

The receiver listens inside the container, but the Docker port is bound only to your machine’s loopback interface. Don’t expose an unauthenticated collector to your network!

Remark: This example assumes connection-string ingestion is allowed for your Application Insights resource. If your organization requires Entra-only ingestion, use an appropriately authenticated exporter configuration instead.

Point Copilot Chat at the collector

In VS Code, update settings.json:

{ "github.copilot.chat.otel.enabled": true, "github.copilot.chat.otel.exporterType": "otlp-http", "github.copilot.chat.otel.otlpEndpoint": "http://localhost:4318", "github.copilot.chat.otel.captureContent": true

}

Reload the VS Code window and start a Copilot Chat interaction.

Notice that I've enabled content capture. Our data is going to a persistent cloud service. Prompt and response content, tool arguments, and file contents can contain sensitive information. So disable it, if you want to avoid this.

Environment variables and enterprise-managed settings can override these settings, so check those if telemetry goes somewhere unexpected.

Find the data

Open your Application Insights resource and select Logs. For the collector’s Azure Monitor exporter, Copilot’s internal and client spans generally appear as dependencies:

dependencies
| where timestamp > ago(24h)
| where cloud_RoleName == "copilot-chat"
| project timestamp, name, duration, success, operation_Id
| order by timestamp desc

You can then investigate individual operations and their related spans. Log records go to traces, while metrics from this exporter go to customMetrics.

Give ingestion a little time. If nothing appears, check the collector’s console output, the connection string, and whether VS Code inherited an overriding OTEL endpoint.

View the data

There is also an easier option, as you can use one of the built-in Grafana dashboards. Dashboards exist for multiple coding agents but we'll use the one for GitHub Copilot.

Just click on the dashboard link and select the correct App Insights resource:

You can see information about operations, input/output tokens, chat sessions, tool calls, response time and time to first token (TTFT) by model

More information

Popular posts from this blog

Podman– Command execution failed with exit code 125

After updating WSL on one of the developer machines, Podman failed to work. When we took a look through Podman Desktop, we noticed that Podman had stopped running and returned the following error message: Error: Command execution failed with exit code 125 Here are the steps we tried to fix the issue: We started by running podman info to get some extra details on what could be wrong: >podman info OS: windows/amd64 provider: wsl version: 5.3.1 Cannot connect to Podman. Please verify your connection to the Linux system using `podman system connection list`, or try `podman machine init` and `podman machine start` to manage a new Linux VM Error: unable to connect to Podman socket: failed to connect: dial tcp 127.0.0.1:2655: connectex: No connection could be made because the target machine actively refused it. That makes sense as the podman VM was not running. Let’s check the VM: >podman machine list NAME         ...

Cache stampede: when our cache turned against us

While investigating some performance issues, we ran into an ASP.NET Core API that cached a fairly expensive aggregation query for 60 seconds. Under normal load, that was fine: one request rebuilds the cache, everyone else reads from it. Under peak load, dozens of requests would arrive in that same expiry window, all see a cache miss, and all fire the same expensive query in parallel. The database didn't like that. That was the moment when our caching layer stopped helping and started hurting. A burst of requests comes in at the same time, all miss the cache, and all go hammer the database or the downstream API at once. That's a cache stampede . The cache was supposed to protect our backend, and for a few hundred milliseconds it did the opposite. Why this happens IMemoryCache.GetOrCreate (and its async sibling) looks like it protects you, but it doesn't add any locking on its own. Look at the naive version: public async Task<Report> GetReportAsync(string key) ...

Cleaner switch expressions with pattern matching in C#

Ever find yourself mapping multiple string values to the same result? Being a C# developer for a long time, I sometimes forget that the C# has evolved so I still dare to chain case labels or reach for a dictionary. Of course with pattern matching this is no longer necessary. With pattern matching, you can express things inline, declaratively, and with zero repetition. A small example I was working on a small script that should invoke different actions depending on the environment. As our developers were using different variations for the same environment e.g.  "tst" alongside "test" , "prd" alongside "prod" .  We asked to streamline this a long time ago, but as these things happen, we still see variations in the wild. This brought me to the following code that is a perfect example for pattern matching: The or keyword here is a logical pattern combinator , not a boolean operator. It matches if either of the specified pattern...