Skip to content

Commit

Permalink
Fix: Allow telemetry queue to be directly in request body
Browse files Browse the repository at this point in the history
  • Loading branch information
antross authored Aug 20, 2020
1 parent 06febfe commit 2c84e88
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions src/telemetry-api/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,22 @@ import { AzureFunction, Context, HttpRequest } from '@azure/functions';
import { sendPendingData, addToAppInsights } from '../common/analytics';

export const run: AzureFunction = async (context: Context, req: HttpRequest): Promise<void> => {
const telemetryQueue = req.body?.data || req.body;

context.log('Processing telemetry log request');

if (!req.body || !req.body.data) {
if (!Array.isArray(telemetryQueue)) {
context.res = {
body: 'Invalid request',
status: 400
};
context.done();

return;
}

try {
for (const telemetry of req.body.data) {
for (const telemetry of telemetryQueue) {
addToAppInsights(telemetry.data.name, telemetry.data.properties, telemetry.data.measurements, new Date(telemetry.time));
}

Expand Down

0 comments on commit 2c84e88

Please sign in to comment.