This is documentation for the next version of Grafana k6 documentation. For the latest stable release, go to the latest version.

Open source

HTTP debugging

Things don’t always work as expected. For those cases, enabling the –http-debug option will log HTTP requests and responses to help you debugging the script.

  • --http-debug logs the HTTP requests and responses, skipping the body.
  • --http-debug="full" logs the HTTP requests and responses, including the full body.
  • Adding --http-debug-redact to either of them masks credential headers in the output.

Credential masking

By default, the debug output shows credential headers in plain text. To mask them, add the --http-debug-redact option to your command:

sh
k6 run --http-debug=full --http-debug-redact script.js

You can also set the K6_HTTP_DEBUG_REDACT environment variable to true, or the httpDebugRedact option in your script.

k6 replaces the secret part of each credential header with ***REDACTED***. This applies to both requests and responses, including:

  • The Authorization header that k6 adds for URL credentials (http://user:pass@host) and digest authentication.
  • Cookies from the cookie jar.

Masked headers

k6 masks the following headers. Header names are case-insensitive.

HeaderWhat k6 masksExample
Authorization, Proxy-AuthorizationThe credentials. k6 keeps the auth scheme if it’s a standard one, such as Bearer or Basic. Otherwise, k6 masks the whole value.Authorization: Bearer ***REDACTED***
CookieThe cookie values. k6 keeps the cookie names.Cookie: session=***REDACTED***; theme=***REDACTED***
Set-CookieThe cookie value. k6 keeps the cookie name and attributes.Set-Cookie: sid=***REDACTED***; Path=/; HttpOnly
X-Api-Key, X-Auth-Token, X-Amz-Security-TokenThe whole value.X-Api-Key: ***REDACTED***

If k6 can’t parse a cookie value, it masks the whole value.

gRPC

For gRPC, --http-debug also controls debug logging, and --http-debug-redact masks gRPC metadata with the same names, for example, authorization. full still controls whether k6 logs gRPC payloads.

Caution

--http-debug-redact only masks headers. It doesn’t mask secrets in URL query strings or in request and response bodies, which k6 logs when you use --http-debug=full. For k6 cloud run, k6 also sends the debug output to the cloud logs, so check what your test logs before you share it.

Example

Given the following script:

JavaScript
import http from "k6/http";

export default function () {
      http.get("https://google.com/");
}

If we run it using k6 run --http-debug script.js we get output that looks like this:

Bash
          /\      |‾‾|  /‾‾/  /‾/
     /\  /  \     |  |_/  /  / /
    /  \/    \    |      |  /  ‾‾\
   /          \   |  |‾\  \ | (_) |
  / __________ \  |__|  \__\ \___/ .io

   execution: local
      output: -
      script: script.js

    duration: -,  iterations: 1
         vus: 1, max: 1

Request: [----------------------------------------------------------] starting

GET / HTTP/1.1
Host: google.com
User-Agent: k6/0.20.0 (https://k6.io/);
Accept-Encoding: gzip


RedirectResponse:
HTTP/2.0 302 Found
Content-Length: 267
Alt-Svc: hq=":443"; ma=2592000; quic=51303432; quic=51303431; quic=51303339; quic=51303335,quic=":443"; ma=2592000; v="42,41,39,35"
Cache-Control: private
Content-Type: text/html; charset=UTF-8
Date: Thu, 22 Mar 2018 13:39:44 GMT
Location: https://www.google.se/?gfe_rd=cr&dcr=0&ei=ILKzWqiODOaxX_LBi5AG
Referrer-Policy: no-referrer


RedirectRequest:
GET /?gfe_rd=cr&dcr=0&ei=ILKzWqiODOaxX_LBi5AG HTTP/1.1
Host: www.google.se
User-Agent: k6/0.19.0 (https://k6.io/);
Referer: https://google.com/
Accept-Encoding: gzip


Response:
HTTP/2.0 200 OK
Connection: close
Accept-Ranges: none
Alt-Svc: hq=":443"; ma=2592000; quic=51303432; quic=51303431; quic=51303339; quic=51303335,quic=":443"; ma=2592000; v="42,41,39,35"
Cache-Control: private, max-age=0
Content-Type: text/html; charset=ISO-8859-1
Date: Thu, 22 Mar 2018 13:39:44 GMT
Expires: -1
P3p: CP="This is not a P3P policy! See g.co/p3phelp for more info."
Server: gws
Set-Cookie: 1P_JAR=2018-03-22-13; expires=Sat, 21-Apr-2018 13:39:44 GMT; path=/; domain=.google.se
Set-Cookie: NID=126=asTcm5s3-jMa1-pquG09m9lpUrowy-OtzZ9cUomBuKeJePbvwJAZe5wCtiyLITj9_RrlWLf6DTQ8ufpdB39MCRV-zUpfXAUw8XUVMWtgdU1gbtnQ9rssin56333g9Hyo; expires=Fri, 21-Sep-2018 13:39:44 GMT; path=/; domain=.google.se; HttpOnly
Vary: Accept-Encoding
X-Frame-Options: SAMEORIGIN
X-Xss-Protection: 1; mode=block

...

Read more