efcore icon indicating copy to clipboard operation
efcore copied to clipboard

Cosmos: Be able to access response headers

Open riley211 opened this issue 1 year ago • 1 comments

As far as I'm aware there is no way to access cosmos API response headers when using the cosmos db provider for EF. I'd like to be able to know the document size for each of my entities, which when using cosmos API directly, is in the response headers, however there is no way to access these response headers via EF.

riley211 avatar Aug 27 '24 11:08 riley211

This kind of thing generally isn't very compatible with LINQ querying, where you get back your own .NET types as output. I'll leave this open in the backlog to see if other users have this request.

Out of curiosity, why do you need to know the document size?

roji avatar Aug 27 '24 12:08 roji

We want to know the document size as we need to split our documents before they get to the cosmos 2MB limit, at the moment we have set this limit to a count of the amount of things in a document, which we have calculated to be getting close to this limit. This works, however a more elegant solution would be to split the document based on the actual size rather an an approximation.

riley211 avatar Aug 29 '24 12:08 riley211

Thanks for the context @riley211. Isn't this something that would better belong in the logs that EF emits, rather than a programmatic means which you'd then need to access around each and every query, and make sure to manually report/log somehow?

roji avatar Aug 29 '24 12:08 roji

@ajcvickers this also smells to me like possible potential for an interceptor...

roji avatar Aug 29 '24 12:08 roji

Agreed.

ajcvickers avatar Aug 29 '24 12:08 ajcvickers

@roji in our case it's something that we want to respond to in code rather than just report/log. When we are adding things to an array in a cosmos document, it is at that point we split to another document if the addition of new things into the document will hit our precalculated limit.

I'm not too familiar with interceptors but after some quick reading, this could be something suitable.

riley211 avatar Aug 29 '24 13:08 riley211