We're trying to integrate the prometheus scrape endpoint with an existing ASP.NET Core site which hosts a Web API.
Here's how the middleware is configured (showing only the important part):
app.UseAuthentication();
app.UseAuthorization();
app.UseOpenTelemetryPrometheusScrapingEndpoint(
predicate: ctx => ctx.User.Identity.IsAuthenticated);
app.MapControllers();
app.Run();
Internally, UseOpenTelemtryPrometheusScrappingEndpoint ends up calling the MapWhen which uses the predicate to decide if the custom branch that returns the metrics should be following.
In this case, the web site is protected with bearer token generated by Azure AD. Prometheus has been configured to use OAuth2 and I can see that when it tries to access the metrics endpoint, it's able to get a valid access token which is mapped into a valid user (there's a transform call on the web site which maps the client id+secret into a special user).
Unfortunately, and even thought there's a "valid" user, the ctx.User property in the predicate is always "empty" (ex.: IsAuthenticated returns false always). I'm surely missing something, but what?
Thanks