Reputation: 157
I am trying to add logging to my requests (I have over 150 requests). I am doing this by adding Trace-Id in headers for the requests. This is what I am doing at the moment.
I have added a new header called "X-Trace-Id" and the value for this header is "test {{$guid}}" - which generates this output "test 4b048ed5-3c6f-4f7f-880e-39218cca2e74". I would like to log this value after each request run.
console.log("header : " + request.headers["X-Trace-Id"]);
I tried above logging, however, I got this in the console "header : undefined"
Upvotes: 1
Views: 19086
Reputation: 412
The correct syntax is
console.log('header : ' + pm.request.headers.get('X-Trace-Id'));
(tested in 8.2.0 and 8.5.1). The header string is not case sensitive.
Side note: you mention a header named X-Trace-Id, do you mean X-B3-TraceId? If you are talking about the Open Zipkin trace id header (besides a name correction) you'll need to correct the format. X-B3-TraceId must be 32 or 16 lower-hex characters which a UUID is not (Postman's $guid generates a random UUID). Unfortunately Postman currently doesn't have a way to generate a valid span/trace id so as a work around you can use
{{$randomBankAccount}}{{$randomBankAccount}}
to generate 16 random numbers (which is valid hex).
Upvotes: 1