For the complete documentation index, see llms.txt. Markdown versions are available by appending .md to documentation URLs.

How to add manual instrumentation in Deno

SigNoz Cloud - This page applies to SigNoz Cloud editions.
Self-Host - This page applies to self-hosted SigNoz editions.

Manual instrumentation lets you track specific business logic, add custom attributes, and capture detailed error context in SigNoz.

Prerequisites

Step 1. Add OpenTelemetry API

Add the OpenTelemetry API package to your project:

deno add npm:@opentelemetry/api

Or import it directly in your code using npm: specifiers.

Step 2. Create manual spans

Use the API tracer to wrap important work inside custom spans:

app.ts
import { trace } from "npm:@opentelemetry/api";
 
const tracer = trace.getTracer();
 
Deno.serve(async (req) => {
  return await tracer.startActiveSpan("handle_request", async (span) => {
    try {
      span.setAttribute("http.method", req.method);
      span.setAttribute("http.url", req.url);
 
      // Simulate some work
      await new Promise((resolve) => setTimeout(resolve, 50));
 
      return new Response("Hello from SigNoz!");
    } catch (err) {
      span.recordException(err);
      throw err;
    } finally {
      span.end();
    }
  });
});

Tips:

  • Reuse tracer instances instead of creating a new one for each request.
  • Start spans with descriptive names that match business steps (checkout, fetch-user, etc.).
  • The startActiveSpan callback automatically handles span context propagation.

Step 3. Propagate context

Deno uses the same @opentelemetry/api surface as Node.js and keeps the active span in an AsyncLocalStorage context. startActiveSpan links child spans through await chains and callbacks. Two things break that chain: a span you start without activating, and another service. See Context Propagation for the concepts behind this step.

Inside your process

startActiveSpan activates the span for the duration of its callback. startSpan creates the span without activating it, so nothing nested inside becomes its child:

in-process.ts
// validateOrder's spans become children of process-order
await tracer.startActiveSpan("process-order", async (span) => {
  try {
    await validateOrder(orderId);
  } finally {
    span.end();
  }
});
 
// validateOrder's spans do NOT become children of process-order
const span = tracer.startSpan("process-order");
try {
  await validateOrder(orderId);
} finally {
  span.end();
}

To activate an existing span outside the callback form, put it on a context and run your work inside context.with():

context-with.ts
import { context, trace } from "npm:@opentelemetry/api";
 
const span = tracer.startSpan("process-order");
const ctx = trace.setSpan(context.active(), span);
 
try {
  await context.with(ctx, async () => {
    // Child spans created here attach to process-order
    await validateOrder(orderId);
  });
} finally {
  span.end();
}

Across a service boundary

Deno's built-in OpenTelemetry integration instruments fetch and Deno.serve, so those hops propagate on their own. Write the calls yourself for anything else, such as a queue or a custom protocol.

Set the span kind on both ends. SigNoz reads Client and Server to build the service map and APM metrics.

propagate.ts
import { context, propagation, SpanKind, trace } from "npm:@opentelemetry/api";
 
const tracer = trace.getTracer("order-service");
 
// Outgoing: inject writes traceparent into the carrier
async function chargeCard(payload: unknown) {
  return await tracer.startActiveSpan("charge-card", { kind: SpanKind.CLIENT }, async (span) => {
    try {
      const headers: Record<string, string> = { "content-type": "application/json" };
      propagation.inject(context.active(), headers);
 
      return await fetch("https://payments.internal/charge", {
        method: "POST",
        headers,
        body: JSON.stringify(payload),
      });
    } finally {
      span.end();
    }
  });
}
 
// Incoming: extract returns a context to start the entry span in.
// Deno.serve already parents your spans, so reach for this when the context
// arrives on something Deno does not instrument, such as a queue message.
async function handleCharge(message: { headers: Headers }) {
  const carrier: Record<string, string> = {};
  message.headers.forEach((value, key) => (carrier[key] = value));
 
  const activeContext = propagation.extract(context.active(), carrier);
 
  return await tracer.startActiveSpan("handle-charge", { kind: SpanKind.SERVER }, activeContext, async (span) => {
    try {
      // handle-charge is now a child of charge-card in the caller's trace
      return await capturePayment(message);
    } finally {
      span.end();
    }
  });
}

The third argument to startActiveSpan is the parent context. Leave it out and the entry span takes whatever is active. At the edge of your service that is nothing, so the span starts a fresh trace.

Step 4. Add attributes and events

Attributes show up as key-value pairs in SigNoz so you can filter and aggregate spans. Events capture notable moments inside a span.

services/order.ts
import { trace } from "npm:@opentelemetry/api";
 
const tracer = trace.getTracer();
 
async function processOrder(orderId: string, amount: number) {
  return await tracer.startActiveSpan("process-order", async (span) => {
    try {
      span.setAttribute("order.id", orderId);
      span.setAttribute("order.amount", amount);
 
      // Validate the order
      await validateOrder(orderId);
      span.addEvent("order.validated");
 
      // Charge payment
      const txnId = await chargePayment(orderId, amount);
      span.addEvent("payment.charged", { "transaction.id": txnId });
 
      return txnId;
    } finally {
      span.end();
    }
  });
}
  • Keep attribute keys consistent (use semantic conventions when possible).
  • Use events to mark retries, cache hits/misses, queue waits, and similar milestones.

Step 5. Record errors

Flag failures on the span so they are easy to query in SigNoz.

services/risky.ts
import { trace, SpanStatusCode } from "npm:@opentelemetry/api";
 
const tracer = trace.getTracer();
 
async function riskyOperation() {
  return await tracer.startActiveSpan("risky-operation", async (span) => {
    try {
      await doSomethingRisky();
      span.setStatus({ code: SpanStatusCode.OK });
    } catch (err) {
      span.recordException(err);
      span.setStatus({ code: SpanStatusCode.ERROR, message: err.message });
      throw err;
    } finally {
      span.end();
    }
  });
}
  • recordException attaches stack trace and message details.
  • Setting status to ERROR surfaces the span in SigNoz error views and alerts.
  • Continue propagating the error upstream so calling code can respond.

Validate

  1. Trigger the code paths that emit manual spans.
  2. In SigNoz Traces, filter by service.name or your span name.
  3. Open a trace and verify attributes, events, and error status.
  4. Check the Errors view to confirm failures show up with recorded exceptions.

Troubleshooting

Still not seeing data in SigNoz? Work through Debug missing traces, logs, and metrics, which covers SDK diagnostics, Collector connectivity, and the common ingestion errors for all three signals.

Why don't I see my custom spans in SigNoz?

  • Confirm OTEL_DENO=true is set and the endpoint/ingestion key are configured correctly.
  • Verify traffic hits the functions where you inserted spans.
  • Ensure your application runs long enough for batched exports to flush.

Why are child spans missing even though I create them?

  • Use startActiveSpan to ensure the span context is propagated correctly to child operations.
  • When calling external services, the instrumentation must propagate context through request headers.

Why does the downstream service start its own trace?

  • Make sure that the caller runs propagation.inject and that the outgoing request carries a traceparent header.
  • Make sure that the receiver passes the extracted context as the third argument to startActiveSpan(name, options, ctx, fn).
  • Copy Request.headers into a plain object before calling extract. The default getter cannot read a Headers instance.
  • Make sure that both services register the same propagator format. See Context Propagation.

Why don't attributes or events appear on the span?

  • Attribute values must be strings, numbers, booleans, or arrays of these types.
  • Call setAttribute or addEvent before calling span.end(). Post-end mutations are ignored.

Next steps

Get Help

If you need help with the steps in this topic, please reach out to us on SigNoz Community Slack. If you are a SigNoz Cloud user, please use in product chat support located at the bottom right corner of your SigNoz instance or contact us at cloud-support@signoz.io.

Is this page helpful

Last updated—September 03, 2026