From 710fc35a4e338506bdda529f8804c6079da63f94 Mon Sep 17 00:00:00 2001 From: Hemal Shah Date: Fri, 5 Jun 2026 22:32:44 +0100 Subject: [PATCH] feat: Add option to create api management logging with app insights and/or az monitor --- .changeset/thick-coats-worry.md | 5 ++++ packages/azure/src/construct/rest-api/main.ts | 30 ++++++++++++++----- .../azure/src/construct/rest-api/types.ts | 3 +- 3 files changed, 29 insertions(+), 9 deletions(-) create mode 100644 .changeset/thick-coats-worry.md diff --git a/.changeset/thick-coats-worry.md b/.changeset/thick-coats-worry.md new file mode 100644 index 00000000..bed01756 --- /dev/null +++ b/.changeset/thick-coats-worry.md @@ -0,0 +1,5 @@ +--- +'@gradientedge/cdk-utils-azure': minor +--- + +Add option to create api management logging with app insights and/or az monitor diff --git a/packages/azure/src/construct/rest-api/main.ts b/packages/azure/src/construct/rest-api/main.ts index 4ce16ae7..8694bb19 100644 --- a/packages/azure/src/construct/rest-api/main.ts +++ b/packages/azure/src/construct/rest-api/main.ts @@ -252,7 +252,7 @@ export class AzureRestApi extends CommonAzureConstruct { * @summary Method to create the API Management logger with Application Insights integration */ protected createApiManagementLogger() { - if (this.props.apiManagement.useExistingApiManagement) return + if (this.props.apiManagement.useExistingApiManagement && !this.props.apiManagementDiagnosticAppInsights) return const apiAppNamedValue = this.apiManagementManager.createNamedValue(`${this.id}-am-nv`, this, { displayName: this.applicationInsights.name, @@ -288,13 +288,27 @@ export class AzureRestApi extends CommonAzureConstruct { protected createApiDiagnostic() { if (this.props.apiManagement.useExistingApiManagement) return - this.apiManagementManager.createApiDiagnostic(`${this.id}-all-apis`, this, { - ...this.props.apiManagementDiagnostic, - apiId: this.api.apim.id, - resourceGroupName: this.resourceGroup.name, - serviceName: this.api.apim.name, - loggerId: this.api.logger.id, - }) + if (this.props.apiManagementDiagnosticAppInsights) { + this.apiManagementManager.createApiDiagnostic(`${this.id}-all-apis-app-insights`, this, { + ...this.props.apiManagementDiagnosticAppInsights, + diagnosticId: 'applicationinsights', + apiId: this.api.apim.id, + resourceGroupName: this.resourceGroup.name, + serviceName: this.api.apim.name, + loggerId: this.api.logger.id, + }) + } + + if (this.props.apiManagementDiagnosticAzMonitor) { + this.apiManagementManager.createApiDiagnostic(`${this.id}-all-apis-az-monitor`, this, { + ...this.props.apiManagementDiagnosticAzMonitor, + diagnosticId: 'azuremonitor', + apiId: this.api.apim.id, + resourceGroupName: this.resourceGroup.name, + serviceName: this.api.apim.name, + loggerId: pulumi.interpolate`${this.api.apim.id}/loggers/azuremonitor`, + }) + } } /** diff --git a/packages/azure/src/construct/rest-api/types.ts b/packages/azure/src/construct/rest-api/types.ts index 05444862..d2b60906 100644 --- a/packages/azure/src/construct/rest-api/types.ts +++ b/packages/azure/src/construct/rest-api/types.ts @@ -31,7 +31,8 @@ export interface AzureRestApiProps extends CommonAzureStackProps { /** API Management service properties */ apiManagement: ApiManagementProps /** API diagnostic properties for logging */ - apiManagementDiagnostic: ApiDiagnosticProps + apiManagementDiagnosticAppInsights: ApiDiagnosticProps + apiManagementDiagnosticAzMonitor: ApiDiagnosticProps /** Monitor diagnostic settings for the API Management service */ apiManagementDiagnosticSettings: MonitorDiagnosticSettingProps }