@pnp/sp
Version:
pnp - provides a fluent api for working with SharePoint REST
23 lines • 1.17 kB
JavaScript
export function Telemetry() {
return (instance) => {
instance.on.pre(async function (url, init, result) {
let clientTag = "PnPCoreJS:3.18.0:";
// make our best guess based on url to the method called
const { pathname } = new URL(url);
// 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
// and we want to modify any (*) calls at the end such as items(3) and items(344) so we just track "items()"
clientTag += pathname
.substring(pathname.indexOf("_api/") + 5)
.split("/")
.map((value, index, arr) => index === arr.length - 1 ? value.replace(/\(.*?$/i, "()") : value[0]).join(".");
if (clientTag.length > 32) {
clientTag = clientTag.substring(0, 32);
}
this.log(`Request Tag: ${clientTag}`, 0);
init.headers = { ...init.headers, ["X-ClientService-ClientTag"]: clientTag };
return [url, init, result];
});
return instance;
};
}
//# sourceMappingURL=telemetry.js.map