admin管理员组文章数量:1391937
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"
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"
Share Improve this question asked Jul 15, 2019 at 13:47 JhanzJhanz 1573 gold badges4 silver badges12 bronze badges 2- You have to add more info so we can help you, could you upload some code ? – Nullpointer13 Commented Nov 12, 2019 at 2:24
-
Postman uses node.js, you may try to get the key in lowercase:
request.headers["x-trace-id"]
– Gabriel Anderson Commented Dec 29, 2019 at 21:19
1 Answer
Reset to default 1The 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).
本文标签: javascriptHow to log a http request header (XTraceId) in PostmanStack Overflow
版权声明:本文标题:javascript - How to log a http request header (X-Trace-Id) in Postman - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744716421a2621431.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论