# Turning off SQL Query logs from settings

**URL:** <https://discuss.elastic.co/t/turning-off-sql-query-logs-from-settings/242407>\
**Category:** APM\
**Tags:** dotnet\
**Created:** [July 23, 2020, 9:13pm UTC](https://discuss.elastic.co/t/turning-off-sql-query-logs-from-settings/242407 "2020-07-23T21:13:31Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![tinonetic](https://avatars.discourse-cdn.com/v4/letter/t/848f3c/32.png) [@tinonetic](https://discuss.elastic.co/u/tinonetic)\
**Post date:** [July 23, 2020, 9:13pm UTC](https://discuss.elastic.co/t/turning-off-sql-query-logs-from-settings/242407/1 "2020-07-23T21:13:31Z")

</div>

Hi,

We have an elastic setup that's working well in .NET Core (Elastic Search + Kibana + APM) for our microservices

But now we have an application that is logging alot of SQL Queries that are spamming the "observability".

We are using EF Core as our ORM

**Is there a way of turning off SQL Query logging through config?** We don't want totally remove the span as it may be useful in future troubleshooting and it gives us a view of which process is running at a given time, as well as the intstrumentation that APM does so well.

**Packages:**

Elastic.Apm.NetCoreAll 1.5.1  
Elastic.Apm.SerilogEnricher 1.5.0

**Code:**

```auto
           var transaction = Agent.Tracer.CurrentTransaction;
            await transaction.CaptureSpan("Getting DeActivated Items", ApiConstants.TypeRequest, async () =>
            {
                deActivatedItems = await _myRepository
                         .Where(x => !x.Activated) 
                         .ToListAsync();

            });    

```

The _ **appsettings.json** _ with the config:

```auto
  "ElasticApm": {
    "ServiceName": "myService",
    "ServerUrls": "http://my_url:8200",
    "TransactionSampleRate": 1.0,
    "ServiceVersion": "1.0.0",
    "Environment": "Development",
    "TransactionMaxSpans": 500,
    "SecretToken": "SomeSecret",
    "LogLevel": "Error"
  },
  "Logging": {
    "LogLevel": {
      "Default": "Warning",
      "Microsoft": "Warning",
      "System": "Information",
      "Elastic.Apm": "Error"
    }
  },
  "Serilog": {
    "MinimumLevel": {
      "Default": "Warning",
      "Override": {
        "Microsoft": "Warning",
        "IdentityServer4": "Information",
        "Hangfire": "Information",
        "Volo": "Information",
        "System": "Information",
        "Elastic.Apm": "Error"
      }
    }
  }

```

**What do I need to do to turn of SQL Query logging without having to remove the Span?**

---

<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:** [July 28, 2020, 10:05am UTC](https://discuss.elastic.co/t/turning-off-sql-query-logs-from-settings/242407/2 "2020-07-28T10:05:37Z")

</div>

Hi @tinonetic, welcome on discuss.

You have a couple of options here.

You can use the [Filter API](https://www.elastic.co/guide/en/apm/agent/dotnet/current/public-api.html#filter-api) and do something like this:

```auto
Agent.AddFilter((ISpan span) =>
{
	if (span.Context?.Db != null // only true for db spans
		&& span.Duration < 100) // filter based on duration
		return null; // if it's a db span and less than 100 milliseconds, we drop it
	return span;
});

```

You have access to other properties as well, so you can also filter based on something other than duration and you can also implement more complex logic in the filter.

Another options would be to completely turn off database capturing. By default the `Elastic.Apm.NetCoreAl` turns on everything, so you'll need to configure the agent this way:

```auto
using Elastic.Apm.AspNetCore;

//...in the Configure method:
app.UseElasticApm( Configuration,new HttpDiagnosticsSubscriber() /* turn off:, new EfCoreDiagnosticsSubscriber(),
new SqlClientDiagnosticSubscriber() */, new ElasticsearchDiagnosticsSubscriber());

```

I also opened an [issue](https://github.com/elastic/apm-agent-dotnet/issues/917) in the .NET APM Agent repo - this is not implemented yet, but the idea is to cut spans automatically based on duration with a setting. The Java agent already has this setting and the motivation was to solve something similar to your issue, so maybe it's worth following that issue as well.

---

<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:** [August 18, 2020, 6:05am UTC](https://discuss.elastic.co/t/turning-off-sql-query-logs-from-settings/242407/3 "2020-08-18T06:05:44Z")

</div>

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