Open lwmxiaobei opened 4 years ago
@lwmxiaobei use the opentracing.FORMAT_TEXT_MAP
Example:
const jaeger = require('jaeger-client');
const opentracing = require('opentracing');
const jaegerLogger = {
info(msg) {
console.log(`[jaeger-info]${msg}`);
},
error(msg) {
console.log(`[jaeger-error]${msg}`);
},
};
function createConfig(name) {
return {
disable: false,
serviceName: name,
sampler: {
type: 'const',
param: 1,
},
reporter: {
logSpans: true,
collectorEndpoint: 'http://127.0.0.1:14268/api/traces'
},
}
}
const options = {
tags: {
version: 'v1.0.0',
},
logger: jaegerLogger,
};
const parentTracer = jaeger.initTracer(createConfig('parent-tracer'), options);
const childTracer = jaeger.initTracer(createConfig('child-tracer'), options);
function createSerializedSpanContext(myTracer, mySpan) {
const obj = {};
myTracer.inject(mySpan.context(), opentracing.FORMAT_TEXT_MAP, obj);
return obj;
}
function createSpanContextFromSerializedParentContext(myTracer, obj) {
const parentSpanContext = myTracer.extract(opentracing.FORMAT_TEXT_MAP, obj);
return parentSpanContext;
}
const span = parentTracer.startSpan('parent service');
const serialized = createSerializedSpanContext(parentTracer, span);
console.log(`obj: ${JSON.stringify(serialized, null, 2)}`);
const context = createSpanContextFromSerializedParentContext(childTracer, serialized);
const childSpan = childTracer.startSpan('child service', {
childOf: context,
});
span.finish();
childSpan.finish();
Http requests should use FORMAT_HTTP_HEADERS
@yurishkuro you are right. Should I hide my comment?
I am using js-libp2p which uses no http and directly communicates over tcp. Therefore it worked for me with opentracing.FORMAT_TEXT_MAP
. Can we add an example for opentracing.FORMAT_TEXT_MAP
in the Lesson 3 (nodejs)?
If you are using non-HTTP protocol that does not impose header restrictions the way HTTP does, then you should use text map format.
I am not sure why we'd add examples for text map here since this tutorial uses only HTTP.
Overall the Node.js tutorial is under-developed, if you look at Go tutorial, its README files have a lot more narrative / explanations.
@yurishkuro can you maybe create a ticket which things are missing for the node.js tutorial? I am ready to contribute. Or should I simply compare the node.js tutorial to e.g. the Go tutorial and then add the missing things?
yes, simply compare Node.js README's with other languages, you will see that it has a low less narrative/explanations.
OpenTracing Tutorial - Node.js Lesson 3 RPC not updated yet ? I am more interested in rpc call, can you update it?