Skip to content

Adds logging LLM usage information using OpenTelemetry. Closes #1067 #1167

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

waldekmastykarz
Copy link
Collaborator

Adds logging LLM usage information using OpenTelemetry. Closes #1067

To test

devproxyrc.json:

{
  "$schema": "https://raw.githubusercontent.com/dotnet/dev-proxy/main/schemas/v0.27.0/rc.schema.json",
  "plugins": [
    {
      "name": "OpenAITelemetryPlugin",
      "enabled": false,
      "pluginPath": "~appFolder/plugins/dev-proxy-plugins.dll"
    }
  ],
  "urlsToWatch": [
    "http://localhost:11434/*"
  ],
  "logLevel": "information",
  "newVersionNotification": "stable",
  "showSkipMessages": true,
  "showTimestamps": true,
  "validateSchemas": true
}

Visualize using Aspire dashboard:

docker run --rm -it -p 18888:18888 -p 4317:18889 -p 4318:18890 --name aspire-dashboard mcr.microsoft.com/dotnet/aspire-dashboard:latest

Call Ollama using its OpenAI-compatible API:

curl -ikx http://127.0.0.1:8000 -X POST -H Content-Type: application/json -d '{"model":"llama3.2","messages":[{"role":"user","content":"What is the capital of France?"}],"stream":false}' http://localhost:11434/v1/chat/completions

In the Aspire dashboard, you'll see tracing and metrics (it takes a moment for metrics to show up).

To test cost estimation

devproxyrc.json

{
  "$schema": "https://raw.githubusercontent.com/dotnet/dev-proxy/main/schemas/v0.27.0/rc.schema.json",
  "plugins": [
    {
      "name": "OpenAITelemetryPlugin",
      "enabled": false,
      "pluginPath": "~appFolder/plugins/dev-proxy-plugins.dll",
      "configSection": "openAITelemetryPlugin"
    }
  ],
  "urlsToWatch": [
    "http://localhost:11434/*"
  ],
  "openAITelemetryPlugin": {
    "includeCosts": true,
    "pricesFile": "llm-prices.json"
  },
  "logLevel": "information",
  "newVersionNotification": "stable",
  "showSkipMessages": true,
  "showTimestamps": true,
  "validateSchemas": true
}

llm-prices.json:

{
  "prices": {
    "llama3.2": {
      "input": 10.0,
      "output": 30.0
    }
}

Call Ollama again, check out the new span with cost information and wait for additional metrics to show up in the dashboard.

@waldekmastykarz waldekmastykarz requested a review from a team as a code owner May 8, 2025 09:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Count LLM tokens in Azure AI Foundry models
1 participant