# Unwanted metrics

**URL:** <https://discuss.elastic.co/t/unwanted-metrics/336885>\
**Category:** APM\
**Tags:** dotnet\
**Created:** [June 26, 2023, 9:16am UTC](https://discuss.elastic.co/t/unwanted-metrics/336885 "2023-06-26T09:16:56Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![rchmiel\_fp](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/rchmiel_fp/32/121963_2.png) [@rchmiel\_fp](https://discuss.elastic.co/u/rchmiel_fp)\
**Post date:** [June 26, 2023, 9:16am UTC](https://discuss.elastic.co/t/unwanted-metrics/336885/1 "2023-06-26T09:16:56Z")

</div>

Hello,

I have a working .NET based system utilizing APM 7.17.9 and data streams. Lastly we implemented filter to remove logging transactions for [OPTION] requests which works but we still get metrics logged for those requests. Is there any option to remove those metrics too? They make up total ~20% of all metrics we gather for requests and since we don't need to track them and want to save some space we wonder if we can somehow filter them out too.

Our system is .net based application, filter looks like below:

```auto
public static ITransaction FilterOutPreflight(ITransaction transaction)
        {
            if (transaction.Type?.ToUpperInvariant() == "REQUEST")
            {
                if (!string.IsNullOrEmpty(transaction.Name)
                    && transaction.Name.StartsWith("OPTIONS", StringComparison.InvariantCultureIgnoreCase))
                {
                    return null;
                }

                if (transaction.Context?.Request != null
                    && transaction.Context.Request.Method.Equals("OPTIONS", StringComparison.InvariantCultureIgnoreCase))
                {
                    return null;
                }
            }

            return transaction;
        }

```

And is registered using method from Elastic.Apm.Agent class

```auto
public static bool AddFilter(Func<ITransaction, ITransaction> filter);

```

That alone works but we still have tons of metric we don't really need nor want. Data is stored in .ds-traces-apm-default index and, as shown on screen there is quite a lot of it

 ![metrics](https://us1.discourse-cdn.com/elastic/original/3X/3/b/3bfae0c2746f7fb2065a7955fb0cf5bb8b1e5078.png)

What can we do about it?

---

<div class="post-metadata">

**Author:** ![carly.richmond](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/carly.richmond/32/104935_2.png) [@carly.richmond](https://discuss.elastic.co/u/carly.richmond)\
**Post date:** [June 26, 2023, 10:03am UTC](https://discuss.elastic.co/t/unwanted-metrics/336885/2 "2023-06-26T10:03:45Z")

</div>

Hi @rchmiel_fp,

Welcome to the community! Thanks for sharing your [.NET filter example](https://www.elastic.co/guide/en/apm/agent/dotnet/1.x/public-api.html#filter-api). I can think of a couple of options for you to try:

1. Similar to what you've specified and the [remove example here in the documentation](https://www.elastic.co/guide/en/apm/agent/dotnet/1.x/public-api.html#filter-api), I wonder if you could return a modified transaction with only the fields you want by modifying the above code.
2. You could also try [creating and registering a custom ingest pipeline](https://www.elastic.co/guide/en/apm/guide/current/ingest-pipelines.html#custom-ingest-pipelines) containing [`remove` processors](https://www.elastic.co/guide/en/elasticsearch/reference/current/remove-processor.html#remove-processor) to drop known fields you don't want, or conversely use the `keep` option on the `remove` processor to only retain the fields you want. If there are additional events you want to drop you can also use the [`drop` processor](https://www.elastic.co/guide/en/elasticsearch/reference/current/drop-processor.html). I would recommend having a look at [this tutorial](https://www.elastic.co/guide/en/apm/guide/current/custom-filter.html#filters-ingest-pipeline) and [this other tutorial](https://www.elastic.co/guide/en/fleet/8.8/data-streams-pipeline-tutorial.html) for a rough idea of the create and registration steps.

Hope that helps! Do let us know if you have any questions on the above.

---

<div class="post-metadata">

**Author:** ![carly.richmond](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/carly.richmond/32/104935_2.png) [@carly.richmond](https://discuss.elastic.co/u/carly.richmond)\
**Post date:** [June 26, 2023, 10:11am UTC](https://discuss.elastic.co/t/unwanted-metrics/336885/3 "2023-06-26T10:11:07Z")

</div>

You can also look at using the [`disable_metrics`](https://www.elastic.co/guide/en/apm/agent/dotnet/current/config-reporter.html#config-disable-metrics) option too. Thanks to @GregKalapos for pointing this out!

---

<div class="post-metadata">

**Author:** ![rchmiel\_fp](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/rchmiel_fp/32/121963_2.png) [@rchmiel\_fp](https://discuss.elastic.co/u/rchmiel_fp)\
**Post date:** [June 27, 2023, 1:59pm UTC](https://discuss.elastic.co/t/unwanted-metrics/336885/4 "2023-06-27T13:59:33Z")

</div>

To clarify what I want to achieve. I don't want at all to collect metrics for **requests of method type OPTIONS**. Nothing more, nothing less. Is that achievable?

---

<div class="post-metadata">

**Author:** ![carly.richmond](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/carly.richmond/32/104935_2.png) [@carly.richmond](https://discuss.elastic.co/u/carly.richmond)\
**Post date:** [June 27, 2023, 3:48pm UTC](https://discuss.elastic.co/t/unwanted-metrics/336885/5 "2023-06-27T15:48:41Z")

</div>

It looks like you can by specifying a wildcard string with `disable_metrics` setting [as per the docs](https://www.elastic.co/guide/en/apm/agent/dotnet/current/config-reporter.html#config-disable-metrics).

---

<div class="post-metadata">

**Author:** ![GregKalapos](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/gregkalapos/32/37205_2.png) [@GregKalapos](https://discuss.elastic.co/u/GregKalapos)\
**Post date:** [June 27, 2023, 6:02pm UTC](https://discuss.elastic.co/t/unwanted-metrics/336885/6 "2023-06-27T18:02:38Z")

</div>

One thing to note here is that metrics and traces are orthogonal in general. The only metrics that are tied to transactions (and spans) are the [breakdown metrics (those are the ones that power the "time spent by span type" charts)](https://www.elastic.co/guide/en/apm/agent/dotnet/current/metrics.html#metrics-application) - everything else (CPU, Memory, GC usage, etc.) is just periodically collected - regardless of the transaction type. If there is no transaction, they are still collected. So from this reason, there isn't really any way to drop metrics based on transaction type - most of the metrics aren't associated to or triggered by any transaction. We don't have a filters API for metrics, but even if we would have it, you could still not query transactions in metrics filters from reasons described before.

`disable_metrics` would stop the collection altogether and I feel that's the easiest and best you can do to save storage.

If you want to really have some advanced logic to check transactions and their type and drop metrics based on that, then you can look into ingest pipelines suggested by @carly.richmond, but that'd be a bit more work.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [July 25, 2023, 6:02pm UTC](https://discuss.elastic.co/t/unwanted-metrics/336885/7 "2023-07-25T18:02:52Z")

</div>

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