Prompt

How do I add OpenTelemetry tracing to a backend app

Technology / Observability1 observationLast seen Oct 28, 2026

Latest observation

Oct 28, 2026OpenAI APIWeb search: off

Adding OpenTelemetry tracing to a backend app usually involves 4 steps:

  1. Add the OpenTelemetry SDK/dependencies
  2. Configure a tracer provider and exporter
  3. Instrument your framework and libraries
  4. Send traces to an observability backend

Here’s the general approach, then I’ll show a small example.


1) Pick where traces will go

Common choices:

  • OTLP collector (recommended)
  • Jaeger
  • Zipkin
  • Datadog / New Relic / Honeycomb / Grafana Tempo, etc.

Most teams use an OpenTelemetry Collector as a middle layer, then forward to their vendor/backend.


2) Install OpenTelemetry packages

Examples by language

  • Node.js: @opentelemetry/sdk-node, instrumentations for HTTP/Express/DBs
  • Python: opentelemetry-sdk, opentelemetry-exporter-otlp, instrumentations
  • Java: OpenTelemetry Java agent or SDK
  • Go: go.opentelemetry.io/otel, exporters, instrumentations
  • .NET: OpenTelemetry, OpenTelemetry.Exporter.OpenTelemetryProtocol

3) Initialize tracing early in app startup

You generally want tracing initialized before your app creates the HTTP server or loads libraries you want auto-instrumented.

Key configuration items:

  • Service name: e.g. orders-api
  • Exporter endpoint: collector/backend URL
  • Sampling: always, probabilistic, parent-based, etc.
  • Resource attributes: environment, version, region, etc.

4) Auto-instrument common libraries

OpenTelemetry can automatically create spans for:

  • Incoming HTTP requests
  • Outgoing HTTP calls
  • Database queries
  • Message queue operations
  • Framework handlers

You can also create manual spans for important business operations.


Minimal example

Node.js example

// tracing.js
const { NodeSDK } = require('@opentelemetry/sdk-node');
const { getNodeAutoInstrumentations } = require('@opentelemetry/auto-instrumentations-node');
const { OTLPTraceExporter } = require('@opentelemetry/exporter-trace-otlp-http');

const sdk = new NodeSDK({
  traceExporter: new OTLPTraceExporter({
    url: 'http://localhost:4318/v1/traces',
  }),
  instrumentations: [getNodeAutoInstrumentations()],
});

sdk.start();

Then import this before your app starts:

require('./tracing');

const express = require('express');
const app = express();

app.get('/hello', (req, res) => {
  res.send('hello');
});

app.listen(3000);

Python example

# tracing.py
from opentelemetry import trace
from opentelemetry.sdk.resources import Resource
from opentelemetry.sdk.trace import TracerProvider
from opentelemetry.sdk.trace.export import BatchSpanProcessor
from opentelemetry.exporter.otlp.proto.http.trace_exporter import OTLPSpanExporter

resource = Resource.create({"service.name": "orders-api"})
provider = TracerProvider(resource=resource)
processor = BatchSpanProcessor(OTLPSpanExporter(endpoint="http://localhost:4318/v1/traces"))
provider.add_span_processor(processor)
trace.set_tracer_provider(provider)

Then in your app:

import tracing
from fastapi import FastAPI

app = FastAPI()

@app.get("/hello")
def hello():
    return {"message": "hello"}

For FastAPI/Flask/Django you’d usually also add auto-instrumentation.


Manual spans

Use manual spans for custom work that auto-instrumentation won’t capture well:

const tracer = opentelemetry.trace.getTracer('my-service');

async function processOrder(orderId) {
  return tracer.startActiveSpan('process-order', async (span) => {
    try {
      // business logic
      span.setAttribute('order.id', orderId);
      return { ok: true };
    } catch (err) {
      span.recordException(err);
      span.setStatus({ code: 2, message: err.message });
      throw err;
    } finally {
      span.end();
    }
  });
}

Best practices

  • Use a collector instead of sending directly to a vendor when possible
  • Initialize tracing at process startup
  • Propagate context across services using W3C Trace Context
  • Set meaningful span names
  • Add attributes for key business fields, but avoid sensitive data
  • Sample appropriately in production
  • Avoid high-cardinality attributes like raw user IDs in tags if they explode metrics/search

What you’ll typically need in production

  • OpenTelemetry SDK
  • Auto-instrumentation for your framework
  • OTLP exporter
  • OpenTelemetry Collector
  • Backend like Tempo/Jaeger/Honeycomb/Datadog/New Relic

If you want, I can give you a ready-to-run setup for a specific stack like Node/Express, Python/FastAPI, Java/Spring, Go, or .NET.

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.