Kick off a New Relic Trace with k6

Hi,

Is it possible to kick off a New Relic trace with k6? @gspncr do you know if this is possible?

Similar to this extension, but for New Relic: GitHub - grafana/xk6-distributed-tracing: A k6 extension for distributed tracing.

Thanks

Hello @larchie! Thanks for creating a new post.

I’m Daniel, one of the devs behind that extension! xk6-distributed-tracing is vendor-agnostic, and should work with New Relic out-of-the-box.

The only thing that you need to know, is what kind of HTTP propagation format your services instrumentation understands (we support: w3c,jaeger,b3 and ot). Once you have that, you can create a new k6 binary with the extension, write a script similar to this one:

import tracing, { Http } from 'k6/x/tracing';
import { sleep } from 'k6';

export let options = {
  vus: 1,
  duration: '10s',
};

export function setup() {
  console.log(`Running xk6-distributed-tracing v${tracing.version}`, tracing);
}

export default function() {
  const http = new Http({
    propagator: "w3c",
  });
  const r = http.get('https://test-api.k6.io');
  console.log(`trace_id=${r.trace_id}`);
  sleep(1);
}

export function teardown(){
  // Cleanly shutdown and flush telemetry when k6 exits.
  tracing.shutdown();
}

And fire k6 :slight_smile:

That’s enough to kick off a new trace with k6. But, the extension also supports adding spans to the trace, from k6’s perspective (HTTP step spans → Blue ones on this image). If you care about those spans you can configure an exporter that New Relic understands (from reading their docs, zipkin or otlp) to capture them.

Hopefully, that makes some sense!

Daniel,

Thanks! Weirdly, the trace_id that the extension is coming back with doesn’t match the trace_id that’s being show in Jaeger or New Relic…

I also can’t get the exporter to work, which is frustrating.

Is there any debugging you recommend I do to see what the problem is?

It looks like something is stripping the headers from the requests I send into our environment and a new trace id is being added…

It looks like something is stripping the headers from the requests I send into our environment and a new trace id is being added…

I hope you can solve that!

I also can’t get the exporter to work, which is frustrating.

What exporter are you trying to use? I have faced some problems while trying to use the exporter functionality with multiple scenarios :sweat_smile: