@pnp/sp
Version:
pnp - provides a fluent api for working with SharePoint REST
24 lines • 1.26 kB
JavaScript
import { stringIsNullOrEmpty } from "@pnp/core";
export function Telemetry() {
return (instance) => {
instance.on.pre(async function (url, init, result) {
let clientTag = "PnPCoreJS:4.8.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.split("/")
.filter((v) => !stringIsNullOrEmpty(v) && ["_api", "v2.1", "v2.0"].indexOf(v) < 0)
.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