Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

373
Views
How to manually extract context or span from incoming http request in NodeJS?

I trying to migrate my Node.js application from jaeger-client to @opentelemetry/* packages

In my Node.js application i have a simple http server and i want to create span on each response.

With jaeger-client i did it in the following way:

import { FORMAT_HTTP_HEADERS } from 'opentracing';
import { initTracerFromEnv } from 'jaeger-client';

const tracer = initTracerFromEnv(/* some options here */);

// app is expressjs app
app.get('/home', req => {
  const rootSpan = tracer.startSpan('response', {
    childOf: tracer.extract(FORMAT_HTTP_HEADERS, req.headers),
  });

  // ...make child spans of rootSpan
});

I want to connect my root span of response with spans from other application, that performs request to my Node.js application server. About the same as I would do it with jaeger-client.

How can i make it with OpenTelemetry instead of jeager-client and opentracing? Is it possible to create child spans manually, without auto instrumentations?

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

You can do the Context Propagation by extracting the parent context from the request headers and creating the child span with it, as follows:

const opentelemetry = require('@opentelemetry/api');
const {SpanKind, ROOT_CONTEXT} = require("@opentelemetry/api");


app.get('/home', req => {
  // Get incoming context from headers
  const remoteCtx = opentelemetry.propagation.extract(ROOT_CONTEXT, req.headers);

  // ...make child spans of remoteSpan

  // Create child span passing parent context 
  const childSpan = tracer.startSpan(
    'childSpan',
    remoteCtx
  );

  // ... Do important stuff

  
  // End the span
  childSpan.end();
});

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!