Tags from checks are not reaching Datadog

Hi,

I’m testing the Datadog integration, following the documentation: Datadog (k6.io) and I’m not able to see the tags I added for the checks.

I’m able to see the tags when I add them in the “options” and in the request, so, the integration itself is working to some extent.

Here’s the script I used, it’s a demo one.

import http from "k6/http";
import { check, sleep } from "k6";

export const options = {
  discardResponseBodies: true,
  scenarios: {
    contacts: {
      executor: "per-vu-iterations",
      vus: 5,
      iterations: 20,
      maxDuration: "30s",
    },
  },
};

export default function () {
  const res = http.get("https://test.k6.io/contacts.php");
  check(
    res,
    { "status is 200": (r) => r.status === 200 },
    { "mytag": "test-tag" }
  );
  sleep(0.5);
}

I’m using Windows 10 + k6 0.42

Hi @wvargascr !

I’m not sure if I got the question :thinking: Could you please elaborate on what do you mean by:

and I’m not able to see the tags I added for the checks.

Checks validate boolean conditions in the test and it doesn’t add any new tags.

Hi @olegbespalov,

Per the documentation, we can add tags in different places of our script ( Tags and Groups (k6.io) and so, in my script, I added some tags that relates to the check. However, when I try to group by tag in DD, the tag I added is not displayed. And, keep in mind that if I add a tag at the test level, I am able to filter by that tag.

May I have a look at the script? I mean, I’d like to check how you are adding the custom tags since, for example, the script from Tags from checks are not reaching Datadog doesn’t add any new tags.

It will add the tags only if you (as you mentioned) add them to the options (example 1) or the specific request (example 2):

Example 1:

import http from "k6/http";
import { check, sleep } from "k6";

export const options = {
   tags: {
    mytag: 'test-tag',
  },
  discardResponseBodies: true,
  scenarios: {
    contacts: {
      executor: "per-vu-iterations",
      vus: 5,
      iterations: 20,
      maxDuration: "30s",
    },
  },
};

export default function () {
  const res = http.get("https://test.k6.io/contacts.php");
  check(
    res,
    { "status is 200": (r) => r.status === 200 },
    { "mytag": "test-tag" }
  );
  sleep(0.5);
}

or

Example 2:

import http from "k6/http";
import { check, sleep } from "k6";

export const options = {
  discardResponseBodies: true,
  scenarios: {
    contacts: {
      executor: "per-vu-iterations",
      vus: 5,
      iterations: 20,
      maxDuration: "30s",
    },
  },
};

export default function () {
  const res = http.get("https://test.k6.io/contacts.php", {tags: {mytag: 'test-tag'}});
  check(
    res,
    { "status is 200": (r) => r.status === 200 },
    { "mytag": "test-tag" }
  );
  sleep(0.5);
}

I’ve added the script in the initial question, and I set the custom tag only in the check. Are you saying that is required to added in the options object to be able to use it in the check? My understanding is that they were independent at all levels (options, request, check).

Actually, I was wrong, the third argument of the checks is the tags :man_facepalming:

I have no setup integration with the DataDog, but after briefly running of statsd (which is used in that integration) I can see that custom tag from checks.

Let me dig into it :thinking:

Hi @wvargascr !

So I was debugging this and currently have an assumption that the issue is in a metric name. In the case of the check k6 produces a metric as it is defined k6.check.status is 200

11 Jan 07:39:05 - DEBUG: k6.check.status is 200.pass:1|c|#scenario:contacts,check:status is 200

DataDog has a naming convention which seems doesn’t allow spaces https://docs.datadoghq.com/metrics/custom_metrics/#naming-custom-metrics

So in theory if you name your check like:

check(
    res,
    { "status_is_200": (r) => r.status === 200 }    
);

You should be able to see that metric there.

P.S. And just in case also I should mention that K6_STATSD_ENABLE_TAGS=true environment variable should be used in order to export tags to the StatsD.

Let me know if that answers,
Cheers!

1 Like

Hi @olegbespalov,

First of all, thanks for looking into this.

I have a few things:

  1. The DD documentation indicates that spaces will be converted to underscores, so that wouldn’t be a problem, and in any case the custom tag I’m using is lowercase.
  2. Per your code snippet, you changed the check property to be with underscores, not the custom tag itself.
  3. I did make sure I was using the env variable. Keep in mind that when I use the tag at the “option” level I can see it in DD with no issues.
  4. Here’s a screenshot of the tags coming to DD using the script with and without your suggestions. All of them are automatically sent by DD. I see the check property there, but not the custom tag.

image

In any case, I am rethinking my need as I write this answer. Maybe I won’t need that tag, but this would still remain an issue.

Thanks

Hey @wvargascr

I’m not sure if we’re on the same page. I was talking not about the tag name but a metric name.

So I assume that if the metric name has a space in it’s name, the datadog/agent:latest could simply drop it and, for sure, drop the tags associated with this metric ("k6.check.status is 200").

That’s why I’ve suggested renaming the check name since that way, the actual metric will also have no spaces.

check(
    res,
    { "status_is_200": (r) => r.status === 200 },
    { "mytag": "test-tag" }
  );

If that doesn’t help I’m afraid it could be something on the DD side :man_shrugging:

1 Like

hey @olegbespalov,

Yeah, I got that, and I did change the metric to not use space and got the same results. And you are probably right, there could be an issue with the integration since the tag is being generated per your screenshot.

I’ll try to see if I can DD help on this one.

Thanks

2 Likes