Skip to content
This repository has been archived by the owner on Oct 3, 2023. It is now read-only.

Can't propogate trace context with http instrumentation? #117

Closed
yantang-msft opened this issue Aug 31, 2018 · 1 comment
Closed

Can't propogate trace context with http instrumentation? #117

yantang-msft opened this issue Aug 31, 2018 · 1 comment
Labels

Comments

@yantang-msft
Copy link

I'm playing with this library and see how the correlation context is propagated through http request.
Here is the snippet

const tracing = require('@opencensus/nodejs');
const ConsoleExporter = require('@opencensus/core');
const propagation = require('@opencensus/propagation-tracecontext');

const traceContext = new propagation.TraceContextFormat();

const tracer = tracing.start({propagation: traceContext}).tracer;
const exporter = new ConsoleExporter.ConsoleExporter({
    bufferSize: 1,
    bufferTimeout: 1,
    logger: console
});
tracing.registerExporter(exporter);

const http = require('http');

http.get('http://www.google.com', (resp) => {
    let data = '';
    resp.on('data', (chunk) => {
        data += chunk;
    });

    resp.on('end', () => {
        console.log(`Response end, data length is ${data.length}`);
    });
}).on("error", (err) => {
    console.log("Error: " + err.message);
});

const stdin = process.openStdin();
stdin.addListener("data", () => {});

If I don't add the propagation context, the http instrumentation would successfully create a span for the outgoing request. But if I add the propagation context, it gives me this error. Did I missed anything?

Error [ERR_HTTP_HEADERS_SENT]: Cannot set headers after they are sent to the client
    at ClientRequest.setHeader (_http_outgoing.js:469:11)
    at Object.setHeader (D:\OpenCensus\node\node_modules\@opencensus\instrumentation-http\build\src\http.js:182:29)
    at TraceContextFormat.inject (D:\OpenCensus\node\node_modules\@opencensus\propagation-tracecontext\build\src\tracecontext-format.js:109:20)
    at D:\OpenCensus\node\node_modules\@opencensus\instrumentation-http\build\src\http.js:187:29
    at contextManager.runAndReturn (D:\OpenCensus\node\node_modules\@opencensus\core\build\src\trace\model\tracer.js:111:20)
    at AsyncHooksNamespace.runAndReturn (D:\OpenCensus\node\node_modules\@opencensus\core\build\src\internal\cls-ah.js:51:21)
    at CoreTracer.startRootSpan (D:\OpenCensus\node\node_modules\@opencensus\core\build\src\trace\model\tracer.js:84:36)
    at Object.outgoingRequest [as get] (D:\OpenCensus\node\node_modules\@opencensus\instrumentation-http\build\src\http.js:159:42)
    at Object.<anonymous> (D:\OpenCensus\node\test.js:17:6)
    at Module._compile (internal/modules/cjs/loader.js:689:30)
mayurkale22 pushed a commit that referenced this issue Feb 18, 2019
* fixes http.get patches for header propagation #117

* fix linter
@mayurkale22
Copy link
Member

Closed in #324, Will have an example for this soon #369 (PR in review)

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

2 participants