How to disable capturing of specific headers only

I would like to skip capturing of some of the request headers. I am aware of of the settings:

<add key="ElasticApm:CaptureHeaders" value="false"/>

But this disables capturing of all headers, after that I don't have for example user_agent.

I would like to skip capturing of only the subset of headers - I would like to remove the Cookie header.

Is it possible to achieve this?

APM agent dotnet 1.7.1:

Hi @kbalys,

yes, you can do this. Use the the SanitizeFieldNames setting for this.

1 Like

Hi @GregKalapos,

thank you for the answer. As far as I know SanitizeFieldNames setting replaces a value with a placeholder for example I have:
"http.request.headers.Accesstoken [REDACTED]"
and this value is sent to the index by the agent.

My assumption is that sanitizing fields does not improve performance as much as removing most of the headers?

As far as I know SanitizeFieldNames setting replaces a value with a placeholder for example I have:
"http.request.headers.Accesstoken [REDACTED]"
and this value is sent to the index by the agent.
My assumption is that sanitizing fields does not improve performance as much as removing most of the headers?

That's right, with this you just mask the values, but it won't help you with performance. If the goal is to minimize runtime overhead then only setting CaptureHeaders to false will help, there is not setting to only read specific headers or skip reading specific ones. On the other hand if you want to minimize storage and network traffic you could use the Filter API - with a little bit of a C# code you can manually remove specific headers and those won't be sent to APM server. But those will still be captured by the agent, so in terms of runtime overhead this won't help.

I hope this helps a bit.

This topic was automatically closed 20 days after the last reply. New replies are no longer allowed.