-
Notifications
You must be signed in to change notification settings - Fork 309
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
Custom Traces + Generated spans from integration #310
Comments
This is definitely possible, and should happen automatically for any supported module. To do it manually, you have to use the scope manager to get the scope and then add your own instrumentation. In your case for example, you would have to grab the span from the active scope in the resolver, and then add a span for the gRPC client, and propagate the context to the next service. function resolve (obj, args) {
const scope = tracer.scopeManager().active()
const childOf = scope.span()
const span = tracer.startSpan('grpc.request', { childOf })
} Since HTTP2 is not supported at the moment out of the box, you would also have to manually propagate the context using tracer.inject() in the client and tracer.extract() in the server. |
Support for gRPC has landed in #311. For completeness, here is how to do this manually with the new function resolve (obj, args) {
// tracer.trace automatically handles the span lifecycle, propagation, and errors
tracer.trace('grpc.request', () => {
// your code
})
} |
We're trying to do something like the above, but it doesn't seem to connect the Spans. In particular, we use the This is the function we use to generate a span: function startSpan(tracer, name) {
const scope = tracer.scope();
const span = scope.active();
if (span != null) {
return tracer.startSpan(
name,
{
childOf: span.context(),
}
);
}
return tracer.startSpan(name);
} And we end up with Spans for |
@joneshf-cn Can you share the code using this function? Is it only your custom spans that are not connected or is it also auto-instrumentation? |
Unfortunately, we can't share the actual code. It's some closed source code. It's also a little bit more complicated since we're calling this from PureScript and there's no DataDog package for PureScript, so we have to interact with it through the PureScript FFI. I'm about 80% sure there's something funky going on with our PureScript FFI. I can try to make as close a reproduction as possible in plain JavaScript though. Hopefully that can fill in the missing pieces. We have some functions to work with // file: datadog.js
const ddTrace = require("dd-trace");
exports.finish = function(span) {
span.finish();
};
exports.initTracer = function(options) {
return ddTrace.init(options);
};
exports.startSpan = function(tracer, name) {
const scope = tracer.scope();
const span = scope.active();
if (span != null) {
return tracer.startSpan(
name,
{
childOf: span.context(),
}
);
}
return tracer.startSpan(name);
}; We have some kind of router that handles endpoints: // file: router.js
exports.handle = function(tracer, endpoint) {
const span = datadog.startSpan(tracer, endpoint);
// hit MySQL, hit other Services, etc.
datadog.finish(span);
}; We initialize the tracer in our main: // file: main.js
const datadog = require("./datadog.js");
const router = require("./router.js");
function main() {
const tracer = datadog.initTracer({
service: "foo",
});
// Other initialization
router.handle(tracer, "/index.html")
}
main(); Hopefully that kind of explains how we're using
I'm not entirely sure if it's only custom Spans, only something with the More concretely, when we make a request to our
The |
I just re-read the getting started instructions. The second step might be the thing we're doing not quite right:
I think maybe we're not actually initializing before anything else in the actual code. In particular, this part:
I'll see if we can't move things around so we end up doing that initialization first. |
Yep. That was it! We now have
Spans all connected to the same Trace. We even got a new set of packages instrumented!
Sorry for bringing up this old Issue. |
Is it possible to use the generated spans, from the integrations for GraphQL, as parent / child spans for other custom traces ? in the graphql resolvers, I make gRPC calls out to a golang server.. I want to see the entire trace.
flame graph from Hapi GraphQL plugin integration.
The text was updated successfully, but these errors were encountered: