gsscoder
gsscoder

Reputation: 3392

Logging from APIM to Event HUB seems not working properly

I've followed instructions in MS docs.

I've created an Event Hub namespace that hosts an hub called clicks-hub secured by a policy called ClicksLoggingPolicy with Send claim only.

Then I've added the logger to my APIM service using this URL: https://management.azure.com/subscriptions/MY_SUBS/resourceGroups/MY_RESGROUP/providers/Microsoft.ApiManagement/service/MY_APIM/loggers/clicksLogger?api-version=2019-12-01

with this payload:

{
    "properties": {
      "loggerType": "azureEventHub",
      "description": "Logger for click events",
      "credentials": {
        "name": "clicks-hub",
        "connectionString": "Endpoint=sb://myapim.servicebus.windows.net/;SharedAccessKeyName=ClicksLoggingPolicy;SharedAccessKey=****************"
      }
    }
}

After sending the PUT request I got 201 created.

I've configured an APIM API with this POST operation. It follows the XML policy:

<policies>
    <inbound>
        <log-to-eventhub logger-id="clicksLogger">@( "LOGGING_FROM_AZURE_APIM" )</log-to-eventhub>
        <mock-response status-code="200" content-type="application/json" />
        <base />
    </inbound>
    <backend>
        <base />
    </backend>
    <outbound>
        <base />
    </outbound>
    <on-error>
        <base />
    </on-error>
</policies>

I triggered various requests using the APIM Test panel and I can see requests on Metrics: enter image description here

but nothing where when I quert the hub:

SELECT
    *
INTO
    [OutputAlias]
FROM
    [clicks-hub]

enter image description here

I tried to ingest some test data using this tool and I can see the messages.

Any idea about what I'm missing?

Thanks in advance to anyone who'll try to help.

Regards, Giacomo S. S.

Upvotes: 0

Views: 673

Answers (1)

Kai Walter
Kai Walter

Reputation: 4001

It seems you can only query when the EventHub message is an object / is JSON:

From this policy

<policies>
    <inbound>
        <log-to-eventhub logger-id="kai-logger">@( "LOGGING_FROM_AZURE_APIM1" )</log-to-eventhub>
        <log-to-eventhub logger-id="kai-logger">@( "{'message':'LOGGING_FROM_AZURE_APIM2'}" )</log-to-eventhub>
        <mock-response status-code="200" content-type="application/json" />
        <base />
    </inbound>
    <backend>
        <base />
    </backend>
    <outbound>
        <base />
    </outbound>
    <on-error>
        <base />
    </on-error>
</policies>

only the messages with LOGGING_FROM_AZURE_APIM2 show in the query.

enter image description here

Upvotes: 1

Related Questions