question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[BUG] Issues with EventHub Logger configured using System Assigned Managed Identity

See original GitHub issue

Release version

v4.5.0

Describe the bug

We have configured the event hub logger for apim using the system-assigned identity. While running the Publisher to Dev environment is failing with the below exception on the EH logger. I could not able to find any reference in the documentation around eventhub setup using system identity; the wiki and few other issues reported on logger were talking about the logger configured using the connectionString.

exception log:

System.Net.Http.HttpRequestException: HTTP request to URI https://management.azure.com/subscriptions/***/resourceGroups/**-int-dv-apim-rg/providers/Microsoft.ApiManagement/service/**-int-dv-apim/loggers/apim-dv-eventhub-logger?api-version=2022-04-01-preview failed with status code 400. Content is ‘{“error”:{“code”:“ValidationError”,“message”:“One or more fields contain incorrect values:”,“details”:[{“code”:“ValidationError”,“target”:"One or more Properties [’{0}‘] specified are missing.",“message”:“64c7d150fb42680fe*******”}]}}’.

We noticed when the extractor ran that the associated extracted json for the logger only contains the following loggerInformation.json, but it was missing the other properties within the credentials.

`{
  "properties": {
    "credentials": {
      "name": "i**-mgmt-pr-evh-02"
    },
    "description": "adding a new logger with system assigned managed identity",
    "isBuffered": true,
    "loggerType": "azureEventHub"
  }
}`

With the above-extracted json, we noticed the publisher to dev was failing with the missing connectionString property was missing; since we did not use connectionstring to set up the logger and it was using the system identity. I tried to update the JSON logger as below by adding the endpoint and identityClientID (generated named value for the logger), but it failed with the error mentioned in the exception log above.

loggerInformation_manual_update.json


`{
  "properties": {
    "credentials": {
      "identityClientId": "{{64c7d150fb42680**********}}",
      "name": "***-mgmt-pr-evh-02",
      "endpointAddress": "***-mgmt-pr-evhns.servicebus.windows.net/***-mgmt-pr-evh-02"
    },
    "description": "adding a new logger with system assigned managed identity",
    "isBuffered": true,
    "loggerType": "azureEventHub"
  }
}`

Documentation referred for setting up EH logger using system identity https://learn.microsoft.com/en-us/azure/api-management/api-management-howto-log-event-hubs?tabs=PowerShell#logger-with-system-assigned-managed-identity-credentials

a

Expected behavior

We expect the publisher to dev environment should not fail while pushing the changes back to Dev environment and eventually to higher environments

Actual behavior

System.Net.Http.HttpRequestException: HTTP request to URI https://management.azure.com/subscriptions/***/resourceGroups/gi-int-dv-apim-rg/providers/Microsoft.ApiManagement/service/gi-int-dv-apim/loggers/apim-dv-eventhub-logger?api-version=2022-04-01-preview failed with status code 400. Content is ‘{“error”:{“code”:“ValidationError”,“message”:“One or more fields contain incorrect values:”,“details”:[{“code”:“ValidationError”,“target”:"One or more Properties [’{0}‘] specified are missing.",“message”:“64c7d150fb42680fe4*****”}]}}’.

Reproduction Steps

  1. EH logger added using system identity for steps mentioned here https://learn.microsoft.com/en-us/azure/api-management/api-management-howto-log-event-hubs?tabs=PowerShell#logger-with-system-assigned-managed-identity-credentials
  2. Ran extractor and publisher job. Publisher was using the json file loggerInformation.json, where the publisher fails on missing connectionstring property
  3. Manually updated the loggerInformation.json, see above mentioned block for loggerInformation_manual_update.json, where with this config, publisher has failed with the exception as provided above

Issue Analytics

  • State:open
  • Created 2 months ago
  • Comments:7 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
guythetechiecommented, Aug 8, 2023

@Mohid-A - I don’t think we’ve tested this scenario specifically (Event Hubs with managed identities). I’ll test tomorrow and respond.

0reactions
Mohid-Acommented, Aug 15, 2023

@guythetechie I tried with suggested approach still resulted in failure. I have set the logging levels to DEBUG, still see no information around the root cause of the internal server error.

Here’s the updated loggerInformation.json I tried on the publish-to-dev job, also tried removing the logger name and id in the subsequent runs too

{
  "properties": {
    "credentials": {
      "endpointAddress": "ioa-mgmt-pr-evhns.servicebus.windows.net",
      "identityClientId": "SystemAssigned",
      "name": "ioa-mgmt-pr-evh-02"
    },
    "description": "adding a new logger with system assigned managed identity",
    "isBuffered": true,
    "loggerType": "azureEventHub",
  "name": "apim-eventhub-logger",
  "id": "/subscriptions/************/resourceGroups/gi-int-dv-apim-rg/providers/Microsoft.ApiManagement/service/gi-int-dv-apim/loggers/apim-eventhub-logger"
  }
}

Exception logs

2023-08-14T23:43:20.5609290Z dbug: Microsoft.Extensions.Hosting.Internal.Host[1]
2023-08-14T23:43:20.5610083Z       Hosting starting
2023-08-14T23:43:20.6771763Z info: Publisher[0]
2023-08-14T23:43:20.6772684Z       Beginning execution...
2023-08-14T23:43:20.6892784Z info: Publisher[0]
2023-08-14T23:43:20.6893427Z       Getting files from commit ID 98a0138745f6f1ea41a426da6c4c92c9126a124f...
2023-08-14T23:43:20.7315877Z info: Microsoft.Hosting.Lifetime[0]
2023-08-14T23:43:20.7316613Z       Application started. Press Ctrl+C to shut down.
2023-08-14T23:43:20.7322221Z info: Microsoft.Hosting.Lifetime[0]
2023-08-14T23:43:20.7322904Z       Hosting environment: Production
2023-08-14T23:43:20.7327575Z info: Microsoft.Hosting.Lifetime[0]
2023-08-14T23:43:20.7327822Z       Content root path: /home/vsts/work/1/s
2023-08-14T23:43:20.7338832Z dbug: Microsoft.Extensions.Hosting.Internal.Host[2]
2023-08-14T23:43:20.7339439Z       Hosting started
2023-08-14T23:43:20.8201185Z info: Publisher[0]
2023-08-14T23:43:20.8201923Z       Processing modified files in commit ID...
2023-08-14T23:43:20.8960155Z info: Publisher[0]
2023-08-14T23:43:20.8962475Z       Putting logger apim-eventhub-logger...
2023-08-14T23:43:20.9041142Z dbug: PutRestResource[0]
2023-08-14T23:43:20.9042439Z       Beginning request to put REST resource URI https://management.azure.com/subscriptions/***/resourceGroups/gi-int-dv-apim-rg/providers/Microsoft.ApiManagement/service/gi-int-dv-apim/loggers/apim-eventhub-logger?api-version=2022-04-01-preview...
2023-08-14T23:43:31.5581855Z crit: Publisher[0]
2023-08-14T23:43:31.5583874Z       System.Net.Http.HttpRequestException: HTTP request to URI https://management.azure.com/subscriptions/***/resourceGroups/gi-int-dv-apim-rg/providers/Microsoft.ApiManagement/service/gi-int-dv-apim/loggers/apim-eventhub-logger?api-version=2022-04-01-preview failed with status code 500. Content is '{"error":{"code":"InternalServerError","message":"Request processing failed due to internal error.","details":null}}'.
2023-08-14T23:43:31.5584745Z          at common.HttpPipelineExtensions.Validate(Response response, Uri requestUri)
2023-08-14T23:43:31.5585496Z          at common.HttpPipelineExtensions.PutResource(HttpPipeline pipeline, Uri uri, JsonObject resource, CancellationToken cancellationToken)
2023-08-14T23:43:31.5585905Z          at publisher.Program.<>c__DisplayClass12_0.<<GetPutRestResource>b__0>d.MoveNext()
2023-08-14T23:43:31.5586369Z       --- End of stack trace from previous location ---
2023-08-14T23:43:31.5586764Z          at publisher.Logger.PutLogger(LoggerName loggerName, JsonObject json, ServiceUri serviceUri, PutRestResource putRestResource, ILogger logger, CancellationToken cancellationToken)
2023-08-14T23:43:31.5587131Z          at publisher.Logger.<>c__DisplayClass8_0.<<ProcessArtifactsToPut>b__0>d.MoveNext()
2023-08-14T23:43:31.5587453Z       --- End of stack trace from previous location ---
2023-08-14T23:43:31.5587712Z          at System.Threading.Tasks.Parallel.<>c__50`1.<<ForEachAsync>b__50_0>d.MoveNext()
2023-08-14T23:43:31.5588011Z       --- End of stack trace from previous location ---
2023-08-14T23:43:31.5588297Z          at common.IEnumerableExtensions.ForEachParallel[T](IEnumerable`1 enumerable, Func`2 action, CancellationToken cancellationToken)
2023-08-14T23:43:31.5588747Z          at publisher.Logger.ProcessArtifactsToPut(IReadOnlyCollection`1 files, JsonObject configurationJson, ServiceDirectory serviceDirectory, ServiceUri serviceUri, PutRestResource putRestResource, ILogger logger, CancellationToken cancellationToken)
2023-08-14T23:43:31.5590296Z          at publisher.Service.ProcessArtifactsToPut(IReadOnlyCollection`1 files, JsonObject configurationJson, ServiceDirectory serviceDirectory, ServiceUri serviceUri, ListRestResources listRestResources, PutRestResource putRestResource, DeleteRestResource deleteRestResource, ILogger logger, CancellationToken cancellationToken)
2023-08-14T23:43:31.5590832Z          at publisher.Publisher.ProcessCommitIdFilesToPut(IReadOnlyCollection`1 commitIdFilesToPut, CancellationToken cancellationToken)
2023-08-14T23:43:31.5591175Z          at publisher.Publisher.RunWithCommitId(CommitId commitId, CancellationToken cancellationToken)
2023-08-14T23:43:31.5591542Z          at publisher.Publisher.Run(CancellationToken cancellationToken)
2023-08-14T23:43:31.5591796Z          at publisher.Publisher.ExecuteAsync(CancellationToken cancellationToken)
2023-08-14T23:43:31.5624080Z info: Microsoft.Hosting.Lifetime[0]
2023-08-14T23:43:31.5624537Z       Application is shutting down...
2023-08-14T23:43:31.5627631Z fail: Microsoft.Extensions.Hosting.Internal.Host[9]
2023-08-14T23:43:31.5628412Z       BackgroundService failed
2023-08-14T23:43:31.5630345Z       System.Net.Http.HttpRequestException: HTTP request to URI https://management.azure.com/subscriptions/***/resourceGroups/gi-int-dv-apim-rg/providers/Microsoft.ApiManagement/service/gi-int-dv-apim/loggers/apim-eventhub-logger?api-version=2022-04-01-preview failed with status code 500. Content is '{"error":{"code":"InternalServerError","message":"Request processing failed due to internal error.","details":null}}'.
2023-08-14T23:43:31.5630985Z          at common.HttpPipelineExtensions.Validate(Response response, Uri requestUri)
2023-08-14T23:43:31.5631303Z          at common.HttpPipelineExtensions.PutResource(HttpPipeline pipeline, Uri uri, JsonObject resource, CancellationToken cancellationToken)
2023-08-14T23:43:31.5631866Z          at publisher.Program.<>c__DisplayClass12_0.<<GetPutRestResource>b__0>d.MoveNext()
2023-08-14T23:43:31.5632220Z       --- End of stack trace from previous location ---
2023-08-14T23:43:31.5632556Z          at publisher.Logger.PutLogger(LoggerName loggerName, JsonObject json, ServiceUri serviceUri, PutRestResource putRestResource, ILogger logger, CancellationToken cancellationToken)
2023-08-14T23:43:31.5632910Z          at publisher.Logger.<>c__DisplayClass8_0.<<ProcessArtifactsToPut>b__0>d.MoveNext()
2023-08-14T23:43:31.5633227Z       --- End of stack trace from previous location ---
2023-08-14T23:43:31.5633531Z          at System.Threading.Tasks.Parallel.<>c__50`1.<<ForEachAsync>b__50_0>d.MoveNext()
2023-08-14T23:43:31.5633849Z       --- End of stack trace from previous location ---
2023-08-14T23:43:31.5634135Z          at common.IEnumerableExtensions.ForEachParallel[T](IEnumerable`1 enumerable, Func`2 action, CancellationToken cancellationToken)
2023-08-14T23:43:31.5634588Z          at publisher.Logger.ProcessArtifactsToPut(IReadOnlyCollection`1 files, JsonObject configurationJson, ServiceDirectory serviceDirectory, ServiceUri serviceUri, PutRestResource putRestResource, ILogger logger, CancellationToken cancellationToken)
2023-08-14T23:43:31.5635194Z          at publisher.Service.ProcessArtifactsToPut(IReadOnlyCollection`1 files, JsonObject configurationJson, ServiceDirectory serviceDirectory, ServiceUri serviceUri, ListRestResources listRestResources, PutRestResource putRestResource, DeleteRestResource deleteRestResource, ILogger logger, CancellationToken cancellationToken)
2023-08-14T23:43:31.5635687Z          at publisher.Publisher.ProcessCommitIdFilesToPut(IReadOnlyCollection`1 commitIdFilesToPut, CancellationToken cancellationToken)
2023-08-14T23:43:31.5636009Z          at publisher.Publisher.RunWithCommitId(CommitId commitId, CancellationToken cancellationToken)
2023-08-14T23:43:31.5636278Z          at publisher.Publisher.Run(CancellationToken cancellationToken)
2023-08-14T23:43:31.5636539Z          at publisher.Publisher.ExecuteAsync(CancellationToken cancellationToken)
2023-08-14T23:43:31.5636973Z          at Microsoft.Extensions.Hosting.Internal.Host.TryExecuteBackgroundServiceAsync(BackgroundService backgroundService)
2023-08-14T23:43:31.5637240Z dbug: Microsoft.Extensions.Hosting.Internal.Host[3]
2023-08-14T23:43:31.5637430Z       Hosting stopping
2023-08-14T23:43:31.5652943Z crit: Microsoft.Extensions.Hosting.Internal.Host[10

Also for your testing, did you create the logger as mentioned here https://learn.microsoft.com/en-us/azure/api-management/api-management-howto-log-event-hubs?tabs=PowerShell#logger-with-system-assigned-managed-identity-credentials

Read more comments on GitHub >

github_iconTop Results From Across the Web

We are not able to connect to eventhub using system ...
We are trying to connect to event hub using managed identity but not able to find the connection string to use for Managed...
Read more >
BUG In Azure Function Trigger with Managed Identity #26663
I think there is a bug in the use of Azure Function Trigger Bindings on the Connection value when a Managed Identity is...
Read more >
Trouble Configuring Azure Event Grid Topic to Event Hub ...
I granted the Data Sender permission with the Event Hub Namespace as the designated scope. Detailed guidance on this can be found in...
Read more >
Troubleshooting
This error occurs when there is no authentication configured. When using Managed Identity, verify that you have actually assigned the identity to your...
Read more >
Troubleshoot Azure and Event Hub
Open the Event Hub Namespace. · In the Show Metrics options, select Messages. · If the Incoming Messages is 0, no logs have...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found