UNPKG

1.17 kBJavaScriptView Raw
1export function Telemetry() {
2 return (instance) => {
3 instance.on.pre(async function (url, init, result) {
4 let clientTag = "PnPCoreJS:3.9.0:";
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 // and we want to modify any (*) calls at the end such as items(3) and items(344) so we just track "items()"
9 clientTag += pathname
10 .substring(pathname.indexOf("_api/") + 5)
11 .split("/")
12 .map((value, index, arr) => index === arr.length - 1 ? value.replace(/\(.*?$/i, "()") : value[0]).join(".");
13 if (clientTag.length > 32) {
14 clientTag = clientTag.substring(0, 32);
15 }
16 this.log(`Request Tag: ${clientTag}`, 0);
17 init.headers = { ...init.headers, ["X-ClientService-ClientTag"]: clientTag };
18 return [url, init, result];
19 });
20 return instance;
21 };
22}
23//# sourceMappingURL=telemetry.js.map
\No newline at end of file