168
169
export function validateTelemetryData(data?: unknown): { properties: Properties; measurements: Measurements } {
171
>
const properties: Properties = {};
172
>
const measurements: Measurements = {};
173
>
174
>
const flat: Record<string, unknown> = {};
175
>
flatten(data, flat);
176
>
177
>
for (let prop in flat) {
178
>
// enforce property names less than 150 char, take the last 150 char
179
>
prop = prop.length > 150 ? prop.substr(prop.length - 149) : prop;
180
>
const value = flat[prop];
181
>
182
>
if (typeof value === 'number') {
183
>
measurements[prop] = value;
184
>
185
>
} else if (typeof value === 'boolean') {
186
>
measurements[prop] = value ? 1 : 0;
187
>
188
>
} else if (typeof value === 'string') {
189
>
if (value.length > 8192) {
190
console.warn(`Telemetry property: ${prop} has been trimmed to 8192, the original length is ${value.length}`);
191
}
192
>
//enforce property value to be less than 8192 char, take the first 8192 char
telemetryUtils.ts
193
>
// https://docs.microsoft.com/en-us/azure/azure-monitor/app/api-custom-events-metrics#limits
194
>
properties[prop] = value.substring(0, 8191);
195
>
196
>
} else if (typeof value !== 'undefined' && value !== null) {
197
properties[prop] = String(value);
198
}
200
>
201
>
return {
202
>
properties,
203
>
measurements
204
>
};
205
>
}
206
207
interface IRemoteAuthoringConfig {