# Unable to disable APM via environment variable

**URL:** <https://discuss.elastic.co/t/unable-to-disable-apm-via-environment-variable/180558>\
**Category:** APM\
**Tags:** java\
**Created:** [May 10, 2019, 12:35pm UTC](https://discuss.elastic.co/t/unable-to-disable-apm-via-environment-variable/180558 "2019-05-10T12:35:25Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![jaks](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jaks/32/38097_2.png) [@jaks](https://discuss.elastic.co/u/jaks)\
**Post date:** [May 10, 2019, 12:35pm UTC](https://discuss.elastic.co/t/unable-to-disable-apm-via-environment-variable/180558/1 "2019-05-10T12:35:25Z")

</div>

We are using the APM in production & pre-prod. For dev services, we want to disable the APM, for this we are trying to set via Environment variables. Currently using Java agent 1.6.1.

Here are the kubernetes pod details,

> Environment:  
> PROFILE: dev  
> ELASTIC\_APM\_ACTIVE: false  
> ELASTIC\_APM\_INSTRUMENT: false

elasticapm.properties:

> service\_name=super-user-service  
> application\_packages=com.jay  
> disable\_instrumentations=none  
> transaction\_sample\_rate=0.1

With the above configuration agent is active,

> 2019-05-10 17:56:08.767 [main] INFO co.elastic.apm.agent.configuration.StartupInfo - Starting Elastic APM 1.6.1 as super-user-service on Java 1.8.0\_201 (Oracle Corporation) Linux 4.4.148-k8s  
> 2019-05-10 17:56:09.364 [apm-server-healthcheck] WARN co.elastic.apm.agent.report.ApmServerHealthChecker - Elastic APM server is not available (Connection refused (Connection refused))  
> 2019-05-10 17:56:39.059 [apm-reporter] ERROR co.elastic.apm.agent.report.IntakeV2ReportingEventHandler - Failed to handle event of type METRICS with this error: Connection refused (Connection refused)  
> 2019-05-10 17:56:39.059 [apm-reporter] INFO co.elastic.apm.agent.report.IntakeV2ReportingEventHandler - Backing off for 0 seconds (+/-10%)

How to disable via environment variable? because this way, code or other property files need not be changed

---

<div class="post-metadata">

**Author:** ![felixbarny](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/felixbarny/32/27341_2.png) [@felixbarny](https://discuss.elastic.co/u/felixbarny)\
**Post date:** [May 10, 2019, 12:49pm UTC](https://discuss.elastic.co/t/unable-to-disable-apm-via-environment-variable/180558/2 "2019-05-10T12:49:10Z")

</div>

Hi and thanks for the question. Could you send me the debug logs from the startup?

---

<div class="post-metadata">

**Author:** ![jaks](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jaks/32/38097_2.png) [@jaks](https://discuss.elastic.co/u/jaks)\
**Post date:** [May 10, 2019, 1:20pm UTC](https://discuss.elastic.co/t/unable-to-disable-apm-via-environment-variable/180558/3 "2019-05-10T13:20:32Z")

</div>

@felixbarny Here are the debug logs,

> 2019-05-10 18:41:26.961 [apm-server-healthcheck] DEBUG co.elastic.apm.agent.report.ApmServerHealthChecker - Starting healthcheck to [http://localhost:8200/](http://localhost:8200/)  
> 2019-05-10 18:41:27.269 [main] DEBUG co.elastic.apm.agent.impl.payload.SystemInfo - Found Kubernetes pod UID: 1be1f96c-7325-11e9-bdde-023344833348  
> 2019-05-10 18:41:27.270 [main] DEBUG co.elastic.apm.agent.impl.payload.SystemInfo - container ID is 85ff941bd2f32b8cd986cf9608d4236a123180d139564a8fbcd7f17e467e5fe3  
> 2019-05-10 18:41:27.467 [main] INFO co.elastic.apm.agent.configuration.StartupInfo - Starting Elastic APM 1.6.1 as super-user-service on Java 1.8.0\_201 (Oracle Corporation) Linux 4.4.148-k8s  
> 2019-05-10 18:41:27.468 [main] DEBUG co.elastic.apm.agent.configuration.StartupInfo - active: 'false' (source: Environment Variables)  
> 2019-05-10 18:41:27.468 [main] DEBUG co.elastic.apm.agent.configuration.StartupInfo - instrument: 'false' (source: Environment Variables)  
> 2019-05-10 18:41:27.468 [main] DEBUG co.elastic.apm.agent.configuration.StartupInfo - transaction\_sample\_rate: '0.1' (source: [//elasticapm.properties](https://elasticapm.properties))  
> 2019-05-10 18:41:27.468 [main] DEBUG co.elastic.apm.agent.configuration.StartupInfo - disable\_instrumentations: 'none' (source: [//elasticapm.properties](https://elasticapm.properties))  
> 2019-05-10 18:41:27.468 [main] DEBUG co.elastic.apm.agent.configuration.StartupInfo - application\_packages: 'com.jay' (source: [//elasticapm.properties](https://elasticapm.properties))  
> 2019-05-10 18:41:27.468 [main] DEBUG co.elastic.apm.agent.configuration.StartupInfo - log\_level: 'DEBUG' (source: [//elasticapm.properties](https://elasticapm.properties))  
> 2019-05-10 18:41:27.866 [apm-server-healthcheck] WARN co.elastic.apm.agent.report.ApmServerHealthChecker - Elastic APM server is not available (Connection refused (Connection refused))  
> 2019-05-10 18:41:28.060 [main] DEBUG co.elastic.apm.agent.bci.ElasticApmAgent - Applying advice co.elastic.apm.agent.plugin.api.ElasticApmApiInstrumentation$StartTransactionInstrumentation  
> 2019-05-10 18:41:28.066 [main] DEBUG co.elastic.apm.agent.bci.ElasticApmAgent - Applying advice co.elastic.apm.agent.plugin.api.ElasticApmApiInstrumentation$StartTransactionWithRemoteParentInstrumentation  
> 2019-05-10 18:41:28.067 [main] DEBUG co.elastic.apm.agent.bci.ElasticApmAgent - Applying advice co.elastic.apm.agent.plugin.api.ElasticApmApiInstrumentation$CurrentTransactionInstrumentation  
> 2019-05-10 18:41:28.067 [main] DEBUG co.elastic.apm.agent.bci.ElasticApmAgent - Applying advice co.elastic.apm.agent.plugin.api.ElasticApmApiInstrumentation$CurrentSpanInstrumentation  
> 2019-05-10 18:41:28.067 [main] DEBUG co.elastic.apm.agent.bci.ElasticApmAgent - Applying advice co.elastic.apm.agent.plugin.api.ElasticApmApiInstrumentation$CaptureExceptionInstrumentation  
> 2019-05-10 18:41:28.067 [main] DEBUG co.elastic.apm.agent.bci.ElasticApmAgent - Applying advice co.elastic.apm.agent.plugin.api.TransactionInstrumentation$SetUserInstrumentation  
> 2019-05-10 18:41:28.067 [main] DEBUG co.elastic.apm.agent.bci.ElasticApmAgent - Applying advice co.elastic.apm.agent.plugin.api.TransactionInstrumentation$EnsureParentIdInstrumentation  
> 2019-05-10 18:41:28.068 [main] DEBUG co.elastic.apm.agent.bci.ElasticApmAgent - Applying advice co.elastic.apm.agent.plugin.api.TransactionInstrumentation$SetResultInstrumentation  
> 2019-05-10 18:41:28.068 [main] DEBUG co.elastic.apm.agent.bci.ElasticApmAgent - Applying advice co.elastic.apm.agent.plugin.api.AbstractSpanInstrumentation$SetNameInstrumentation  
> 2019-05-10 18:41:28.068 [main] DEBUG co.elastic.apm.agent.bci.ElasticApmAgent - Applying advice co.elastic.apm.agent.plugin.api.AbstractSpanInstrumentation$SetTypeInstrumentation  
> 2019-05-10 18:41:28.068 [main] DEBUG co.elastic.apm.agent.bci.ElasticApmAgent - Applying advice co.elastic.apm.agent.plugin.api.AbstractSpanInstrumentation$SetTypesInstrumentation  
> 2019-05-10 18:41:28.068 [main] DEBUG co.elastic.apm.agent.bci.ElasticApmAgent - Applying advice co.elastic.apm.agent.plugin.api.AbstractSpanInstrumentation$DoCreateSpanInstrumentation

...

> 2019-05-10 18:41:28.078 [main] DEBUG co.elastic.apm.agent.bci.ElasticApmAgent - Applied 47 advices  
> 2019-05-10 18:41:57.761 [apm-reporter] DEBUG co.elastic.apm.agent.report.IntakeV2ReportingEventHandler - Receiving METRICS event (sequence 0)  
> 2019-05-10 18:41:57.761 [apm-reporter] DEBUG co.elastic.apm.agent.report.IntakeV2ReportingEventHandler - Starting new request to [http://localhost:8200/intake/v2/events](http://localhost:8200/intake/v2/events)  
> 2019-05-10 18:41:57.762 [apm-reporter] ERROR co.elastic.apm.agent.report.IntakeV2ReportingEventHandler - Failed to handle event of type METRICS with this error: Connection refused (Connection refused)

---

<div class="post-metadata">

**Author:** ![Eyal\_Koren](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/eyal_koren/32/36830_2.png) [@Eyal\_Koren](https://discuss.elastic.co/u/Eyal_Koren)\
**Post date:** [May 13, 2019, 1:13pm UTC](https://discuss.elastic.co/t/unable-to-disable-apm-via-environment-variable/180558/4 "2019-05-13T13:13:55Z")

</div>

The `active` and `instrument` flags are mostly used to disable instrumentation.  
In this case, the agent still tries to establish a connection with the APM server and collect and send metrics. I believe this shouldn't affect your dev env, it only writes to the log.

If you add `ELASTIC_APM_METRICS_INTERVAL: 0s` (see [config option documentation](https://www.elastic.co/guide/en/apm/agent/java/current/config-reporter.html#config-metrics-interval)), metrics collection will be disabled.  
In addition, you can add `ELASTIC_APM_LOG_LEVEL: ERROR` to remove agent loggings.

This doesn't mean no agent code will run at all, for that you need to remove the agent altogether. However, it may be enough for your purpose.

I hope this helps.  
Eyal.

---

<div class="post-metadata">

**Author:** ![jaks](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jaks/32/38097_2.png) [@jaks](https://discuss.elastic.co/u/jaks)\
**Post date:** [May 14, 2019, 3:01pm UTC](https://discuss.elastic.co/t/unable-to-disable-apm-via-environment-variable/180558/5 "2019-05-14T15:01:21Z")

</div>

Thanks. I was thinking it will not try to connect. Will enable these flags

---

<div class="post-metadata">

**Author:** ![yycm](https://avatars.discourse-cdn.com/v4/letter/y/839c29/32.png) [@yycm](https://discuss.elastic.co/u/yycm)\
**Post date:** [May 27, 2019, 1:52am UTC](https://discuss.elastic.co/t/unable-to-disable-apm-via-environment-variable/180558/6 "2019-05-27T01:52:54Z")

</div>

2019-05-27 09:27:16.989 [apm-reporter] ERROR co.elastic.apm.agent.report.IntakeV2ReportingEventHandler - Failed to handle event of type METRICS with this error: Connection refused (Connection refused)  
2019-05-27 09:27:16.989 [apm-reporter] INFO co.elastic.apm.agent.report.IntakeV2ReportingEventHandler - Backing off for 36 seconds (+/-10%)  
2019-05-27 09:27:51.275 [apm-reporter] ERROR co.elastic.apm.agent.report.IntakeV2ReportingEventHandler - Failed to handle event of type METRICS with this error: Connection refused (Connection refused)  
2019-05-27 09:27:51.275 [apm-reporter] INFO co.elastic.apm.agent.report.IntakeV2ReportingEventHandler - Backing off for 36 seconds (+/-10%)  
2019-05-27 09:28:29.350 [apm-reporter] ERROR co.elastic.apm.agent.report.IntakeV2ReportingEventHandler - Failed to handle event of type METRICS with this error: Connection refused (Connection refused)  
2019-05-27 09:28:29.350 [apm-reporter] INFO co.elastic.apm.agent.report.IntakeV2ReportingEventHandler - Backing off for 36 seconds (+/-10%)  
2019-05-27 09:29:06.018 [apm-reporter] ERROR co.elastic.apm.agent.report.IntakeV2ReportingEventHandler - Failed to handle event of type METRICS with this error: Connection refused (Connection refused)  
2019-05-27 09:29:06.018 [apm-reporter] INFO co.elastic.apm.agent.report.IntakeV2ReportingEventHandler - Backing off for 36 seconds (+/-10%)  
2019-05-27 09:29:39.416 [apm-reporter] ERROR co.elastic.apm.agent.report.IntakeV2ReportingEventHandler - Failed to handle event of type METRICS with this error: Connection refused (Connection refused)  
2019-05-27 09:29:39.417 [apm-reporter] INFO co.elastic.apm.agent.report.IntakeV2ReportingEventHandler - Backing off for 36 seconds (+/-10%)  
2019-05-27 09:30:15.105 [apm-reporter] ERROR co.elastic.apm.agent.report.IntakeV2ReportingEventHandler - Failed to handle event of type METRICS with this error: Connection refused (Connection refused)  
2019-05-27 09:30:15.105 [apm-reporter] INFO co.elastic.apm.agent.report.IntakeV2ReportingEventHandler - Backing off for 36 seconds (+/-10%)  
2019-05-27 09:30:51.391 [apm-reporter] ERROR co.elastic.apm.agent.report.IntakeV2ReportingEventHandler - Failed to handle event of type METRICS with this error: Connection refused (Connection refused)  
2019-05-27 09:30:51.391 [apm-reporter] INFO co.elastic.apm.agent.report.IntakeV2ReportingEventHandler - Backing off for 36 seconds (+/-10%)  
2019-05-27 09:31:24.047 [apm-reporter] ERROR co.elastic.apm.agent.report.IntakeV2ReportingEventHandler - Failed to handle event of type METRICS with this error: Connection refused (Connection refused)  
2019-05-27 09:31:24.047 [apm-reporter] INFO co.elastic.apm.agent.report.IntakeV2ReportingEventHandler - Backing off for 36 seconds (+/-10%)  
2019-05-27 09:31:58.996 [apm-reporter] ERROR co.elastic.apm.agent.report.IntakeV2ReportingEventHandler - Failed to handle event of type METRICS with this error: Connection refused (Connection refused)  
2019-05-27 09:31:58.996 [apm-reporter] INFO co.elastic.apm.agent.report.IntakeV2ReportingEventHandler - Backing off for 36 seconds (+/-10%)

---

<div class="post-metadata">

**Author:** ![felixbarny](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/felixbarny/32/27341_2.png) [@felixbarny](https://discuss.elastic.co/u/felixbarny)\
**Post date:** [May 27, 2019, 7:45am UTC](https://discuss.elastic.co/t/unable-to-disable-apm-via-environment-variable/180558/7 "2019-05-27T07:45:30Z")

</div>

We have created an issue for this: [https://github.com/elastic/apm-agent-java/issues/639](https://github.com/elastic/apm-agent-java/issues/639)

---

<div class="post-metadata">

**Author:** ![yycm](https://avatars.discourse-cdn.com/v4/letter/y/839c29/32.png) [@yycm](https://discuss.elastic.co/u/yycm)\
**Post date:** [May 28, 2019, 9:38am UTC](https://discuss.elastic.co/t/unable-to-disable-apm-via-environment-variable/180558/8 "2019-05-28T09:38:17Z")

</div>

thanks,felixbarny!!!!

---

<div class="post-metadata">

**Author:** ![jaks](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jaks/32/38097_2.png) [@jaks](https://discuss.elastic.co/u/jaks)\
**Post date:** [June 14, 2019, 9:37am UTC](https://discuss.elastic.co/t/unable-to-disable-apm-via-environment-variable/180558/9 "2019-06-14T09:37:56Z")

</div>

@felixbarny whether this issue is covered as part of agent 1.7.0 release?

---

<div class="post-metadata">

**Author:** ![felixbarny](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/felixbarny/32/27341_2.png) [@felixbarny](https://discuss.elastic.co/u/felixbarny)\
**Post date:** [June 14, 2019, 10:00am UTC](https://discuss.elastic.co/t/unable-to-disable-apm-via-environment-variable/180558/10 "2019-06-14T10:00:31Z")

</div>

Yes, this is fixed in 1.7.0. Let me know how it goes.

---

<div class="post-metadata">

**Author:** ![jaks](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jaks/32/38097_2.png) [@jaks](https://discuss.elastic.co/u/jaks)\
**Post date:** [June 14, 2019, 11:19am UTC](https://discuss.elastic.co/t/unable-to-disable-apm-via-environment-variable/180558/11 "2019-06-14T11:19:31Z")

</div>

Thanks. Verified with 1.7.0 and its working 👍

---

<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 5, 2019, 7:19am UTC](https://discuss.elastic.co/t/unable-to-disable-apm-via-environment-variable/180558/12 "2019-07-05T07:19:41Z")

</div>

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