.Net: New Feature: Feature Request: Add OpenTelemetry GenAI instrumentation sample & docs
name: Feature request about: Suggest an idea for this project
Summary
otel-genai-bridges provides a .NET library (SkOtel) that adds both ASP.NET Core middleware and a DelegatingHandler to emit OpenTelemetry Generative AI telemetry for Semantic Kernel apps. Surfacing this as a community sample in the SK docs would give teams a ready-made path to end-to-end GenAI observability.
Key features
AddSemanticKernelTelemetryextension registers options, middleware, and handler- Captures prompts/completions/tool invocations, tokens, latency, cost, and RAG retrieval latency
- Bundled sample (
dotnet/samples/sk-chat) plus Dockerized Collector → Tempo/Prometheus → Grafana stack
Snippet
builder.Services.AddSemanticKernelTelemetry(options =>
{
options.System = "azure.ai.openai";
options.Model = "gpt-4o";
options.CapturePrompts = true;
options.CaptureCompletions = true;
});
builder.Services.AddOpenTelemetry()
.ConfigureResource(r => r.AddService("sk-chat"))
.WithTracing(t => t
.AddSource("otel-genai-bridges/semantic-kernel")
.AddAspNetCoreInstrumentation()
.AddOtlpExporter());

Proposal
Add a docs/sample entry referencing this instrumentation so developers can adopt OTEL GenAI semantics today. Repository: https://github.com/dineshkumarkummara/otel-genai-bridges
@dineshkumarkummara Thanks for creating this issue. Would you be interested in creating a sample that demonstrates this functionality?
Hi @markwallace-microsoft 👋 — per your ask I fleshed out a complete Semantic Kernel sample that emits the OpenTelemetry GenAI semantics end to end.
Sample + docs
- Code lives in
dotnet/samples/sk-chatwith middleware/delegating-handler wiring fromdotnet/libs/sk-otel/*. - New README: https://github.com/dineshkumarkummara/otel-genai-bridges/blob/docs/add-otel-genai-guide/dotnet/samples/sk-chat/README.md walks through prerequisites, launch commands, and what telemetry to expect.
- PR tracking it: https://github.com/dineshkumarkummara/otel-genai-bridges/pull/1
How to run it
git clone https://github.com/dineshkumarkummara/otel-genai-bridges.gitcd otel-genai-bridges- (Ensure Docker Desktop is running, since the stack brings up Tempo/Prometheus/Grafana.)
./scripts/run_all.sh- Builds the Java RAG sample + SK .NET sample, spins up the OTLP collector, and serves the chat API at
http://localhost:7080. - Curl helper:
curl -s http://localhost:7080/chat -H "Content-Type: application/json" -d '{"question":"How do GenAI semantic conventions work?"}' | jq - Grafana dashboard auto-opens at
http://localhost:3000/d/genai-overviewso you can watch spans/metrics/tokens in real time.
- Builds the Java RAG sample + SK .NET sample, spins up the OTLP collector, and serves the chat API at
If you just need the .NET side you can run dotnet run --project dotnet/samples/sk-chat/SkChat.csproj --urls http://localhost:7080; it defaults OTEL_EXPORTER_OTLP_ENDPOINT to http://localhost:4317 so pointing at any collector is straightforward.
Verification done on my end
git pull origin maindotnet build dotnet/libs/sk-otel/SkOtel.csprojdotnet build dotnet/samples/sk-chat/SkChat.csprojdotnet test dotnet/libs/sk-otel.Tests/SkOtel.Tests.csproj./mvnw -f java/pom.xml package -DskipTests./scripts/run_all.sh(completes the build steps; container startup requires Docker Desktop running)
Let me know if you’d like the sample mirrored directly under the microsoft/semantic-kernel repo as well — happy to open a PR there next.
Quick follow-up: reran ./scripts/run_all.sh with Docker Desktop up and verified the integrated stack end-to-end. The helper curls return:
/chat -> {"answer":"Telemetry friendly response for: How do GenAI semantic conventions work?","tokens":{"input":6,"output":10}}
/rag -> {"answer":"Telemetry friendly response for: Use retrieval augmented generation to answer: Explain OTEL GenAI telemetry"}
Containers spin up cleanly (Tempo, Prometheus, Grafana, Collector, Java RAG service, SK chat API) and tear down when the script exits. Grafana auto-loads the genai-overview dashboard for tracing/metrics inspection.
This issue is stale because it has been open for 90 days with no activity.
This issue was closed because it has been inactive for 14 days since being marked as stale.