Prompt

I’m building distributed tracing into a Go service architecture

Technology / Observability1 observationLast seen Oct 28, 2026

Latest observation

Oct 28, 2026OpenAI APIWeb search: off

Great project. In a Go service architecture, distributed tracing is most useful when you want to follow a request across multiple services, queues, and external dependencies.

Here’s a practical way to think about it:

1) Pick a tracing standard

Use OpenTelemetry. It’s the current standard and works well in Go.

Why:

  • vendor-neutral
  • supports traces, metrics, logs
  • easy export to Jaeger, Grafana Tempo, Honeycomb, Datadog, etc.

2) Define the trace flow

A typical request should:

  1. enter at an HTTP/gRPC boundary
  2. create or continue a trace
  3. propagate context to downstream services
  4. create spans for key operations
  5. export spans to your backend

3) Instrument the entry points

For Go HTTP:

  • use middleware to extract incoming trace headers
  • start a server span
  • attach the span to context.Context

For gRPC:

  • use unary and stream interceptors

4) Propagate context everywhere

In Go, pass context.Context through:

  • HTTP calls
  • DB queries
  • message publishing/consuming
  • internal function calls that do work

Avoid using global trace state.

5) Add spans around important work

Capture spans for:

  • request handling
  • outbound HTTP/gRPC calls
  • DB queries
  • cache calls
  • message queue publish/consume
  • slow business logic steps

Keep spans meaningful; don’t create a span for every tiny function unless it matters.

6) Use semantic conventions

Name spans and attributes consistently:

  • service name
  • operation name
  • HTTP method/path/status
  • peer service
  • DB system/query type
  • queue/topic name
  • error details

7) Export traces

Common setup:

  • Go app -> OpenTelemetry SDK -> OTLP exporter -> Collector -> backend

A collector is strongly recommended so you can:

  • batch spans
  • sample centrally
  • route to multiple backends
  • avoid tight coupling to one vendor

8) Sample intelligently

At scale, you usually don’t want 100% tracing. Options:

  • head sampling in the app
  • tail sampling in the collector
  • always sample errors and slow requests

9) Correlate logs and traces

Include trace/span IDs in logs so you can jump between them easily.

10) Measure the overhead

Tracing adds:

  • CPU
  • memory
  • network/export cost

Use batching, sensible sampling, and avoid excessive attributes.


Minimal Go setup example

Using OpenTelemetry for HTTP service instrumentation:

import (
    "context"
    "log"
    "net/http"

    "go.opentelemetry.io/otel"
    "go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc"
    "go.opentelemetry.io/otel/sdk/resource"
    sdktrace "go.opentelemetry.io/otel/sdk/trace"
    semconv "go.opentelemetry.io/otel/semconv/v1.26.0"
    "go.opentelemetry.io/otel/trace"
)

func initTracer(ctx context.Context) func() {
    exp, err := otlptracegrpc.New(ctx)
    if err != nil {
        log.Fatal(err)
    }

    tp := sdktrace.NewTracerProvider(
        sdktrace.WithBatcher(exp),
        sdktrace.WithResource(resource.NewWithAttributes(
            semconv.SchemaURL,
            semconv.ServiceName("my-service"),
        )),
    )

    otel.SetTracerProvider(tp)

    return func() {
        _ = tp.Shutdown(ctx)
    }
}

Then in your handler:

func handler(w http.ResponseWriter, r *http.Request) {
    ctx, span := otel.Tracer("my-service").Start(r.Context(), "handleRequest")
    defer span.End()

    _ = ctx

    w.WriteHeader(http.StatusOK)
    w.Write([]byte("ok"))
}

You’d typically add middleware to:

  • extract incoming trace context
  • create server spans automatically
  • instrument outbound calls too

Recommended architecture

Service A

  • receives request
  • starts/continues trace
  • calls Service B / DB / queue
  • records span data

Service B

  • extracts incoming context
  • continues same trace
  • records its own spans

Collector

  • receives OTLP from all services
  • batches/samples/exports to backend

Backend

  • Jaeger / Tempo / Honeycomb / Datadog / New Relic, etc.

Common pitfalls

  • forgetting to pass context.Context
  • creating spans but not exporting them correctly
  • naming spans poorly
  • tracing too much low-value internal code
  • not instrumenting async messaging paths
  • sampling too aggressively and losing important traces
  • not correlating logs with trace IDs

If you want, I can help with any of these next:

  1. a full Go OpenTelemetry starter setup
  2. HTTP + gRPC tracing examples
  3. trace propagation through Kafka/RabbitMQ
  4. best practices for span naming and sampling
  5. adding trace IDs to structured logs

Observation history

How did Obsurfable measure this prompt?

Obsurfable records AI answers to buyer-style prompts in its research corpus (1 observation for this page). Metrics are distributions over observations, not a single static ranking.

Which AI systems does Obsurfable collect answers from?

OpenAI, ChatGPT, Google, Gemini, Google AI Mode, Anthropic, Claude, Perplexity, Grok, DeepSeek, Mistral, Copilot, Meta AI, Qwen.

How can brands improve their AEO?

Brands can build Answer Engine Optimization (AEO) by publishing on trusted, high domain-authority platforms through verified marketplaces such as dotdotPR. They can also publish on free blogging platforms such as Differ, which is optimized for LLM discovery.

Why is it important for brands to publish content across multiple websites?

Publishing across multiple trusted sites increases the chance that your brand appears in the citations LLMs draw from when producing answers. Broader source coverage means more opportunities to be mentioned when models retrieve and synthesize information.

Want this interpreted for your brand?

Explorer is the free public corpus. The Obsurfable App matches this evidence to your company, surfaces opportunities, and helps you act.