1 | export function Telemetry() {
|
2 | return (instance) => {
|
3 | instance.on.pre(async function (url, init, result) {
|
4 | let clientTag = "PnPCoreJS:3.18.0:";
|
5 |
|
6 | const { pathname } = new URL(url);
|
7 |
|
8 |
|
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 |
|
\ | No newline at end of file |