---
title: "Logging, Metrics, and Distributed Tracing in .NET with OpenTelemetry and ClickStack"
description: "Two ASP.NET services (an Order API and a Payment Service backed by SQLite via EF Core) are instrumented with OpenTelemetry and export traces, logs and metrics over OTLP/gRPC to ClickStack, a ClickHouse-based observability stack run in Docker Compose."
url: "https://swe.quest/articles/logging-metrics-and-distributed-tracing-in-net-with-opentelemetry-and-clickstack-1c8d1423c6d63948"
canonical: "https://clickhouse.com/blog/logging-metrics-distributed-tracing-dotnet-otel-clickstack"
source: "ClickHouse"
published: "2026-06-03"
difficulty: "medium"
kind: "How-to"
reading_minutes: 12
tags: ["observability","dotnet","sqlite"]
---

# Logging, Metrics, and Distributed Tracing in .NET with OpenTelemetry and ClickStack

A post on [ClickHouse](https://swe.quest/sources/clickhouse.md), published 2026-06-03, 12 min read, How-to. Original: [https://clickhouse.com/blog/logging-metrics-distributed-tracing-dotnet-otel-clickstack](https://clickhouse.com/blog/logging-metrics-distributed-tracing-dotnet-otel-clickstack)

## Summary

Two ASP.NET services (an Order API and a Payment Service backed by SQLite via EF Core) are instrumented with OpenTelemetry and export traces, logs and metrics over OTLP/gRPC to ClickStack, a ClickHouse-based observability stack run in Docker Compose. The setup uses ASP.NET Core, HttpClient and EF Core auto-instrumentation plus custom ActivitySource spans and Meter counters and histograms. W3C traceparent headers propagate context across services so a single trace shows HTTP and database spans on both sides. A deliberate 3-second client timeout against a slow payment path demonstrates how trace waterfalls, log-to-trace correlation and log pattern clustering pinpoint cross-service failures.

Written by swe.quest, not by the author.

**Difficulty:** Medium: assumes a working developer; shows how it is built or done

## Topics

- [Observability](https://swe.quest/tags/observability.md) (Reliability & operations)
- [.NET](https://swe.quest/tags/dotnet.md) (Languages)
- [SQLite](https://swe.quest/tags/sqlite.md) (Data & databases)

## Prerequisites

- ASP.NET Core basics
- Docker Compose ([easy posts on Containers](https://swe.quest/tags/containers.md?difficulty=easy))
- OpenTelemetry concepts ([easy posts on Observability](https://swe.quest/tags/observability.md?difficulty=easy))

## Keywords

OpenTelemetry, ClickStack, ClickHouse, ASP.NET Core, Entity Framework Core, OTLP, SQLite

## Related posts

- [Building a .NET API Gateway with ClickHouse and Aspire](https://swe.quest/articles/building-a-net-api-gateway-with-clickhouse-and-aspire-d43f7774c1e69e19.md): ClickHouse · 2026-06-02 · Medium · 13 min read · .NET, Analytics & OLAP, Observability, Load balancing
  A sample .NET API gateway uses Aspire to orchestrate a ClickHouse container, a YARP gateway, backend APIs, a load generator, an analytics API and a Blazor dashboard.
- [Zero-config Debugging with Deno and OpenTelemetry](https://swe.quest/articles/zero-config-debugging-with-deno-and-opentelemetry-84e6e1786536c301.md): Deno · 2025-04-09 · Medium · 9 min read · Observability, Debugging, Runtimes & VMs, TypeScript
  Deno's built-in OpenTelemetry support (enabled with --unstable-otel) automatically correlates console.log output with trace IDs, creates spans for incoming and outgoing HTTP requests, propagates W3C tracecontext headers across services, and records request-count and latency metrics by status code, all without code changes.
- [Observability as a superpower](https://swe.quest/articles/observability-as-a-superpower-5609b41c95a2309f.md): incident.io · 2024-11-04 · Medium · 8 min read · Observability, Go, Debugging, Incidents & postmortems
  Distributed tracing with OpenTelemetry lets incident.io engineers spot bugs before customers report them, by showing each request's route as a tree of timed spans that exposes slow steps, N+1 queries and duplicate calls.
- [Structured Logging in .NET with Serilog and ClickHouse](https://swe.quest/articles/structured-logging-in-net-with-serilog-and-clickhouse-433c37101ab76f06.md): ClickHouse · 2026-03-23 · Medium · 20 min read · .NET, Observability, Analytics & OLAP
  Serilog's ClickHouse sink lets an ASP.NET service write structured logs directly into a ClickHouse table with one WriteTo.ClickHouse() call.
- [Instrumenting your NextJS application with OpenTelemetry and ClickStack](https://swe.quest/articles/instrumenting-your-nextjs-application-with-opentelemetry-and-clickstack-d85c0f4f10071552.md): ClickHouse · 2025-09-04 · Medium · 17 min read · Observability, JavaScript, React, Analytics & OLAP
  ClickPy, a Next.js app over ClickHouse serving 1.8 trillion rows of PyPI download data, is instrumented with OpenTelemetry via ClickStack (ClickHouse, HyperDX and an OTel collector) to capture browser sessions and distributed traces.

Browse: [Latest posts](https://swe.quest/index.md) · [Topics](https://swe.quest/tags.md) · [Sources](https://swe.quest/sources.md) · [Topic map](https://swe.quest/map.md) · [Site guide (llms.txt)](https://swe.quest/llms.txt)
