Can I add tags to parent span Datadog

Viewed 273

I'm working with express + graphql environment. I want to add tags to express span with the value I derive while resolving the graphql query. Currently, tags get added to the graphql span with the following code.

let span = tracer.scope().active();
  if (span !== null) {
    span.setTag('queryname', queryName);
  } 

Let me know if there is a way to add these tags to the parent span instead of the current span. This is required as I don't want to enable analytics on graphql since I already have it enabled in the express app.

Basically I want tags to root trace(express) instead of current span(graphql.execute).

1 Answers

This way my way to get parentSpan:

import tracer from "dd-trace";
import opentracing from "opentracing";

let span = tracer.scope().active();
if (span) {
  const parentContext = span
    .tracer()
    .extract(opentracing.FORMAT_HTTP_HEADERS, req.headers);
  if (parentContext) {
    span
      .tracer()
      .inject(
        parentContext,
        opentracing.FORMAT_HTTP_HEADERS,
        context.req.headers
      );
  }
}
Related