Skip to content

In development. Expect rough edges and changes. The source code is not public yet.

ClickHouse 12 min read How-to mediumAdept

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

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.

Assumes: ASP.NET Core basicsDocker ComposeOpenTelemetry concepts

Related posts

  • Building a .NET API Gateway with ClickHouse and Aspire

    ClickHouse mediumAdept

    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. Aspire provides live OpenTelemetry metrics and ClickHouse stores the full request history for aggregate analytics. The gateway middleware never blocks on the database: it enqueues rows into a bounded System.Threading.Channels queue with DropWrite, counts drops as a metric, and a background service batch-inserts via RowBinary with async_insert and wait_for_async_insert. The ClickHouse schema uses LowCardinality columns, daily partitions, a sorting key, a 30-day TTL, and an AggregatingMergeTree materialized view with -State/-Merge combinators so percentile dashboards stay fast regardless of log volume.

  • Zero-config Debugging with Deno and OpenTelemetry

    Deno mediumAdept

    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. The walkthrough shows why interleaved logs need request correlation and how spans and parent span IDs build a trace. It provides a withSpan helper around startActiveSpan for adding custom spans such as database calls, and contrasts automatic propagation with manually injecting traceparent headers.

  • Observability as a superpower

    incident.io mediumAdept

    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. The team gets spans for free from instrumented database and HTTP clients, follows a consistent span naming convention, and tags spans with metadata such as table names, row counts, query fingerprints and org IDs. In Go, an internal library plus a defer-with-named-return pattern records errors on spans automatically. Traces go to Cloud Trace locally and to Grafana Tempo in production, where TraceQL queries power debugging. Trace URLs are threaded into logs, Sentry errors and response headers, with a caution that span and attribute volume drives storage cost.

  • Structured Logging in .NET with Serilog and ClickHouse

    ClickHouse mediumAdept

    Serilog's ClickHouse sink lets an ASP.NET service write structured logs directly into a ClickHouse table with one WriteTo.ClickHouse() call. A fluent C# schema builder controls the table: typed JSON property hints, promoted columns such as CorrelationId, a text inverted index on messages, a MergeTree ORDER BY key and a TTL. The demo also covers correlation ID middleware via LogContext, single per-request summary events with UseSerilogRequestLogging and IDiagnosticContext, and flushing batched events with Log.CloseAndFlushAsync on shutdown. For production, manage the schema externally rather than letting the sink create it, and tune compression codecs and Kubernetes-aware sort keys.

  • Instrumenting your NextJS application with OpenTelemetry and ClickStack

    ClickHouse mediumAdept

    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. The HyperDX browser SDK adds session replay, console and network capture, and traceparent propagation that links frontend spans to server spans. The Node.js SDK is wired in through Next.js instrumentation.js with header-capture environment variables. Custom spans around a central query function record each ClickHouse query's timing, rows returned, settings and the dashboard component that issued it, so slow dashboard loads can be traced to specific queries and package properties.

The quest for software engineering knowledge.

Look:
Layout: