Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

227
Visualizações
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?

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

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();
});

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda