Documentation for automated readers
A curated documentation index is available at: https://grafana.com/llms.txt
A complete documentation index is available at: https://grafana.com/llms-full.txt
These indexes can help with page discovery before fetching individual documents.
This page is also available in Markdown, which may be easier for automated readers and AI tools to parse than HTML. The Markdown version is available at https://grafana.com/docs/k6/next/examples/generating-uuids.md, or by sending Accept: text/markdown to https://grafana.com/docs/k6/next/examples/generating-uuids/. For broader documentation discovery, the curated index is available at https://grafana.com/llms.txt and the complete index is available at https://grafana.com/llms-full.txt.
This is documentation for the next version of Grafana k6 documentation. For the latest stable release, go to the latest version.
Generating UUIDs
If you want to make a version 4 UUID,
you can use the
uuidv4 function from the k6 JS lib repository.
import { uuidv4 } from 'https://jslib.k6.io/k6-utils/1.4.0/index.js';
export default function () {
const randomUUID = uuidv4();
console.log(randomUUID); // 35acae14-f7cb-468a-9866-1fc45713149a
}If you really need other UUID versions, you must rely on an external library.
Generate v1 UUIDs
As k6 doesn’t have built-in support for version 1 UUID, you’ll have to use a third-party library.
This example uses a Node.js library called uuid and Browserify (to make it work in k6). For this to work, we first need to go through a few required steps:
Make sure you have the necessary prerequisites installed: Node.js and Browserify
Install the
uuidlibrary:Bashnpm install uuid@3.4.0Run it through browserify:
Bashbrowserify node_modules/uuid/index.js -s uuid > uuid.jsMove the
uuid.jsfile to the same folder as your script file. Now you can import it into your test script:JavaScriptimport uuid from './uuid.js';
This example generates a v1 UUID:
import uuid from './uuid.js';
export default function () {
// Generate a UUID v1
const uuid1 = uuid.v1();
console.log(uuid1);
}Was this page helpful?
Related resources from Grafana Labs

