UNPKG

971 BJavaScriptView Raw
1export function Telemetry() {
2 return (instance) => {
3 instance.on.pre(async function (url, init, result) {
4 let clientTag = "PnPCoreJS:3.4.1:";
5 // make our best guess based on url to the method called
6 const { pathname } = new URL(url);
7 // remove anything before the _api as that is potentially PII and we don't care, just want to get the called path to the REST API
8 clientTag += pathname.substring(pathname.indexOf("_api/") + 5).split("/").map((value, index, arr) => index === arr.length - 1 ? value : value[0]).join(".");
9 if (clientTag.length > 32) {
10 clientTag = clientTag.substring(0, 32);
11 }
12 this.log(`Request Tag: ${clientTag}`, 0);
13 init.headers = { ...init.headers, ["X-ClientService-ClientTag"]: clientTag };
14 return [url, init, result];
15 });
16 return instance;
17 };
18}
19//# sourceMappingURL=telemetry.js.map
\No newline at end of file