Skip to content

Commit

Permalink
Updating custom event
Browse files Browse the repository at this point in the history
  • Loading branch information
frasermolyneux committed Nov 7, 2023
1 parent 4c554da commit 6ec683b
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 11 deletions.
5 changes: 4 additions & 1 deletion src/abstractions/Models/ApimCustomEvent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@ namespace Company.Abstractions.Models
{
public class ApimCustomEvent
{
public string InterfaceId { get; set; }
public string OperationId { get; set; }

Check warning on line 10 in src/abstractions/Models/ApimCustomEvent.cs

View workflow job for this annotation

GitHub Actions / func-apps-ci (func-app-sub)

Non-nullable property 'OperationId' must contain a non-null value when exiting constructor. Consider declaring the property as nullable.

Check warning on line 10 in src/abstractions/Models/ApimCustomEvent.cs

View workflow job for this annotation

GitHub Actions / func-apps-ci (func-app-bus)

Non-nullable property 'OperationId' must contain a non-null value when exiting constructor. Consider declaring the property as nullable.

Check warning on line 10 in src/abstractions/Models/ApimCustomEvent.cs

View workflow job for this annotation

GitHub Actions / func-apps-ci (func-app-pub)

Non-nullable property 'OperationId' must contain a non-null value when exiting constructor. Consider declaring the property as nullable.
public string ServiceId { get; set; }

Check warning on line 11 in src/abstractions/Models/ApimCustomEvent.cs

View workflow job for this annotation

GitHub Actions / func-apps-ci (func-app-sub)

Non-nullable property 'ServiceId' must contain a non-null value when exiting constructor. Consider declaring the property as nullable.

Check warning on line 11 in src/abstractions/Models/ApimCustomEvent.cs

View workflow job for this annotation

GitHub Actions / func-apps-ci (func-app-bus)

Non-nullable property 'ServiceId' must contain a non-null value when exiting constructor. Consider declaring the property as nullable.

Check warning on line 11 in src/abstractions/Models/ApimCustomEvent.cs

View workflow job for this annotation

GitHub Actions / func-apps-ci (func-app-pub)

Non-nullable property 'ServiceId' must contain a non-null value when exiting constructor. Consider declaring the property as nullable.
public string ServiceName { get; set; }

Check warning on line 12 in src/abstractions/Models/ApimCustomEvent.cs

View workflow job for this annotation

GitHub Actions / func-apps-ci (func-app-sub)

Non-nullable property 'ServiceName' must contain a non-null value when exiting constructor. Consider declaring the property as nullable.

Check warning on line 12 in src/abstractions/Models/ApimCustomEvent.cs

View workflow job for this annotation

GitHub Actions / func-apps-ci (func-app-bus)

Non-nullable property 'ServiceName' must contain a non-null value when exiting constructor. Consider declaring the property as nullable.

Check warning on line 12 in src/abstractions/Models/ApimCustomEvent.cs

View workflow job for this annotation

GitHub Actions / func-apps-ci (func-app-pub)

Non-nullable property 'ServiceName' must contain a non-null value when exiting constructor. Consider declaring the property as nullable.
public string EventName { get; set; }

Check warning on line 13 in src/abstractions/Models/ApimCustomEvent.cs

View workflow job for this annotation

GitHub Actions / func-apps-ci (func-app-sub)

Non-nullable property 'EventName' must contain a non-null value when exiting constructor. Consider declaring the property as nullable.

Check warning on line 13 in src/abstractions/Models/ApimCustomEvent.cs

View workflow job for this annotation

GitHub Actions / func-apps-ci (func-app-bus)

Non-nullable property 'EventName' must contain a non-null value when exiting constructor. Consider declaring the property as nullable.

Check warning on line 13 in src/abstractions/Models/ApimCustomEvent.cs

View workflow job for this annotation

GitHub Actions / func-apps-ci (func-app-pub)

Non-nullable property 'EventName' must contain a non-null value when exiting constructor. Consider declaring the property as nullable.
public Dictionary<string, string> CustomDimensions { get; set; }

Check warning on line 14 in src/abstractions/Models/ApimCustomEvent.cs

View workflow job for this annotation

GitHub Actions / func-apps-ci (func-app-sub)

Non-nullable property 'CustomDimensions' must contain a non-null value when exiting constructor. Consider declaring the property as nullable.

Check warning on line 14 in src/abstractions/Models/ApimCustomEvent.cs

View workflow job for this annotation

GitHub Actions / func-apps-ci (func-app-bus)

Non-nullable property 'CustomDimensions' must contain a non-null value when exiting constructor. Consider declaring the property as nullable.

Check warning on line 14 in src/abstractions/Models/ApimCustomEvent.cs

View workflow job for this annotation

GitHub Actions / func-apps-ci (func-app-pub)

Non-nullable property 'CustomDimensions' must contain a non-null value when exiting constructor. Consider declaring the property as nullable.
}
}
8 changes: 4 additions & 4 deletions src/func-app-sub/AppInsightsCustomEvents.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,10 @@ public async Task RunAppInsightsCustomEventsTrigger([EventHubTrigger("appinsight
continue;
}

TelemetryClient.TrackEvent(messageData.EventName, new Dictionary<string, string>()
{
{"InterfaceId", messageData.InterfaceId}
});
TelemetryClient.Context.Operation.Id = messageData.OperationId;
TelemetryClient.Context.Operation.Name = messageData.EventName;

TelemetryClient.TrackEvent(messageData.EventName, messageData.CustomDimensions);
}
}
}
Expand Down
23 changes: 17 additions & 6 deletions terraform/api-management-api-func.tf
Original file line number Diff line number Diff line change
Expand Up @@ -99,12 +99,23 @@ resource "azurerm_api_management_api_policy" "funcapp_backend" {
<set-backend-service backend-id="${azurerm_api_management_backend.funcapp_backend[each.key].name}" />
<log-to-eventhub logger-id="${azurerm_api_management_logger.apim_eh_logger[each.value.location].name}">
@{
return new JObject(
new JProperty("InterfaceId", "ID_VehicleTollBooth"),
new JProperty("EventName", context.Operation.Name),
new JProperty("EventTime", DateTime.UtcNow.ToString()),
new JProperty("ServiceName", context.Deployment.ServiceName)
).ToString();
dynamic requestData = JsonConvert.DeserializeObject(context.Request.Body.As<string>());
var customDimensions = new Dictionary<string, string>() {
{"InterfaceId", "ID_VehicleTollBooth"},
{"TollId", requestData?.TollId},
{"LicensePlate", requestData?.LicensePlate}
};
var customEvent = new {
OperationId = context.Operation.Id,
ServiceId = context.Deployment.ServiceId,
ServiceName = context.Deployment.ServiceName,
EventName = context.Operation.Name,
CustomDimensions = customDimensions
};
return JsonConvert.SerializeObject(customEvent);
}
</log-to-eventhub>
</inbound>
Expand Down

0 comments on commit 6ec683b

Please sign in to comment.