“204 No Content” returned in Postman when attempting to write logs to a data collection endpoint with a data collection rule for Log Analytics custom log ingestion

I’ve been working on my Part 2 of 2 post to demonstrate how we can use Event Hubs to capture the identity of incoming API access for the Azure OpenAI service published by an API Management and while doing so, noticed an odd behavior when attempting to use the Log Ingestion API as demonstrated outlined here:

Logs Ingestion API in Azure Monitor
https://learn.microsoft.com/en-us/azure/azure-monitor/logs/logs-ingestion-api-overview

Azure Monitor

I configured all of the required components and wanted to test with Postman before updating the Python script I had for ingesting Event Hub logs but noticed that I would constantly get a 204 No Content status return with no entries added to the Log Analytics table I had set up. To make a long story short, the issue was because the JSON body I was submitting was not enclosed with square brackets [] and further tests show that regardless of whether the accepted format (with square brackets) was submitted or not, the same 204 No Content would be returned.

The following is a demonstration of this in Postman.

The variables I have defined in Postman are:

  • Data_Collection_Endpoint_URI
  • DCR_Immutable_ID
  • client_id_Log_Analytics
  • client_secret_Log_Analytics

The following are where we can retrieve the values:

The Data_Collection_Endpoint_URI can be retrieved by navigating to the Data collection endpoint you had setup:

The DCR_Immutable_ID can be retrieved in the JSON view of the Data collection rule that was setup:

Immutable

The client_id_Log_Analytics is located in the App Registration object:

App Registration

The client_secret_Log_Analytics is the secret setup for the App Registration:

secret

You’ll also need your tenant ID for the tenantId variable.

Set up the authorization tab in Postman with the following configuration:

Type: OAuth 2.0

Add authorization data to: Request Headers

Token: Available Tokens

Header Prefix: Bearer

Token Name: <Name of preference>

Grant type: Client Credentials

Access Token URL: https://login.microsoftonline.com/{{tenant_id}}/oauth2/v2.0/token

Client ID: {{client_id_Log_Analytics}}

Client Secret: {{client_secret_Analytics }}

Scope: https://monitor.azure.com/.default

Client Authentication: Send as Basic Auth header

Leave the rest as default and click on Get New Access Token:

Get New AccessGet New Access II

The token should be successfully retrieved:

retrieved

Click on Use Token:

Use Token

Configure a POST request with the following URL:

https://{{Data_Collection_Endpoint_URI}}/dataCollectionRules/{{DCR_Immutable_ID}}/streams/Custom-APIMOpenAILogs_CL?api-version=2021-11-01-preview

The Custom-APIMOpenAILogs_CL value can be retrieved in the JSON View of the Data collection rule:

Custom

Proceed to configure the following for the Params tab:

api-version: 2021-11-01-preview

api version

The Authorization key should be filled out with the token that was retrieved.

Set the Content-Type to application/json.

For the body, let’s test with the JSON content WITHOUT the square brackets:

{

“EventTime”: “11/24/2023 8:19:57 PM”,

“ServiceName”: “dev-openai-apim.azure-api.net”,

“RequestId”: “91ff7b54-a0eb-4ada-8d27-6081f71e44a3”,

“RequestIp”: “74.114.240.15”,

“OperationName”: “Creates a completion for the chat message”,

“apikey”: “6f82e8f56e604e6cae6e0999e6bdc013”,

“requestbody”: {

“messages”: [

            {

“role”: “user”,

“content”: “Testing without brackets.”

            }

        ],

“temperature”: 0.7,

“top_p”: 0.95,

“frequency_penalty”: 0,

“presence_penalty”: 0,

“max_tokens”: 800,

“stop”: null

    },

“JWTToken”: “bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiIsIng1dCI6IlQxU3QtZExUdnlXUmd4Ql82NzZ1OGtyWFMtSSIsImtpZCI6IlQxU3QtZExUdnlXUmd4Ql82NzZ1OGtyWFMtSSJ9.eyJhdWQiOiJhcGk6Ly8xMmJjY2MyNi1iNzc4LTRhMmQtYWU3YS00ZjU3MzJlN2E3OWQiLCJpc3MiOiJodHRwczovL3N0cy53aW5kb3dzLm5ldC84NGY0NDcwYi0zZjFlLTQ4ODktOWY5NS1hYjBmNTE0MzAyNGYvIiwiaWF0IjoxNzAwODU2MzQ4LCJuYmYiOjE3MDA4NTYzNDgsImV4cCI6MTcwMDg2MTMyNSwiYWNyIjoiMSIsImFpbyI6IkFUUUF5LzhWQUFBQUN5NDZNdUg4VG0yWTF3VDkvazZWVjFzcU9oUWZaOFU5N0ExcWRyT0FMYThGcVVsTEhRclN2OVlwNU5hUE94QnMiLCJhbXIiOlsicHdkIl0sImFwcGlkIjoiMTJiY2NjMjYtYjc3OC00YTJkLWFlN2EtNGY1NzMyZTdhNzlkIiwiYXBwaWRhY3IiOiIx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-4557-b2ab-c911f451d5c8”,

“Name”: “Terence Luk”

    }

Terence Luk

Notice the returned 204 status:

204 No Content

The server successfully processed the request, but is not returning any content.

Waiting for an indefinite time will show that the log is not written to Log Analytics.

Waiting

Now WITH square brackets:

WITH

Notice the same 204 status is returned:

204

However, using the square brackets show that the log entry is successfully written:

However

All the GitHub and forum posts have others indicating this appears to be the expected behavior so the entry will be written as long as the square brackets are included.

I will be including the instructions on setting up the App Registration, Data Collection Endpoint, Data Collection Rule, and other components in my part 2 of 2 post for logging the identity of an OpenAI call through the API Management.