New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
yantang-msft opened this Issue Aug 31, 2018 · 0 comments

Comments

Projects
None yet
2 participants
@yantang-msft
Copy link

yantang-msft commented Aug 31, 2018

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)

vmarchaud added a commit to vmarchaud/opencensus-node that referenced this issue Feb 3, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment