apm-agent-python icon indicating copy to clipboard operation
apm-agent-python copied to clipboard

Error when testing apm connection from the agent

Open manuelsaks opened this issue 4 years ago • 1 comments

Describe the bug: ... The command ./manage.py elasticapm test gives me an error:

Click to expand the error
[2021-09-07 10:59:24,554 public urllib3.poolmanager] INFO: Redirecting http://192.168.100.100:8200// ->         
http://192.168.100.100:8200/
[2021-09-07 10:59:24,556 public elasticapm.transport.http] INFO: Fetched APM Server version 7.14.0
[2021-09-07 10:59:26,134 public elasticapm] WARNING: Client object is being set more than once
Stack (most recent call last):
  File "/test/./manage.py", line 37, in <module>
    execute_from_command_line(sys.argv)
  File "/usr/local/lib/python3.9/site-packages/django/core/management/__init__.py", line 419, in 
execute_from_command_line
utility.execute()
  File "/usr/local/lib/python3.9/site-packages/django/core/management/__init__.py", line 413, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/usr/local/lib/python3.9/site-packages/django/core/management/base.py", line 354, in run_from_argv
    self.execute(*args, **cmd_options)
  File "/usr/local/lib/python3.9/site-packages/django/core/management/base.py", line 398, in execute
    output = self.handle(*args, **options)
  File "/usr/local/lib/python3.9/site-packages/elasticapm/contrib/django/management/commands/elasticapm.py", line 131, in handle
    self.dispatch.get(subcommand, self.handle_command_not_found)(self, subcommand, **options)
  File "/usr/local/lib/python3.9/site-packages/elasticapm/contrib/django/management/commands/elasticapm.py", line 153, 
in handle_test
    client = DjangoClient(**config)
  File "/usr/local/lib/python3.9/site-packages/elasticapm/contrib/django/client.py", line 89, in __init__
    super(DjangoClient, self).__init__(config, **inline)
  File "/usr/local/lib/python3.9/site-packages/elasticapm/base.py", line 215, in __init__
    set_client(self)
  File "/usr/local/lib/python3.9/site-packages/elasticapm/base.py", line 636, in set_client
    logger.warning("Client object is being set more than once", stack_info=True)
Trying to send a test error to APM Server using these settings:

SERVICE_NAME:   app
SECRET_TOKEN:   secret
SERVER:         http://192.168.100.100:8200

[2021-09-07 10:59:26,136 public urllib3.poolmanager] INFO: Redirecting http://192.168.100.100:8200// -> 
http://192.168.100.100:8200/
[2021-09-07 10:59:26,137 public elasticapm.transport.http] INFO: Fetched APM Server version 7.14.0
Oops. That didn't work. The following error occured: 

Fetched APM Server version 7.14.0

To Reproduce

  1. Install elasticapm with the command pip install elastic-apm in Dockerfile.
  2. Add it to base.py:
(...)
import elasticapm

ELASTIC_APM = {
    "SERVICE_NAME": "app",
    "SECRET_TOKEN": "secret",
    "SERVER_URL": "http://192.168.100.100:8200",
    "ENVIRONMENT": "test",
}

(...)
MIDDLEWARE = [
    "elasticapm.contrib.django.middleware.TracingMiddleware",
    "elasticapm.contrib.django.middleware.Catch404Middleware",
    (...)
]
INSTALLED_APPS = [
    "elasticapm.contrib.django",
    (...)
]
(...)
  1. After building image and running the app, run inside the container command ./manage.py elasticapm test

Environment (please complete the following information)

  • OS: Debian Buster
  • Python version: 3.9.2
  • Framework and version: Django 3.2.6
  • APM Server version: 7.14.1
  • Agent version: 6.4.0

Additional context The agent is sending some data to APM Server and I can see it in Kibana.

curl inside of the container:

$: curl 192.168.100.100:8200 -kv
* Expire in 0 ms for 6 (transfer 0x557c549befb0)
*   Trying 192.168.100.100...
* TCP_NODELAY set
* Expire in 200 ms for 4 (transfer 0x557c549befb0)
* Connected to 192.168.100.100 (192.168.100.100) port 8200 (#0)
> GET / HTTP/1.1
> Host: 192.168.100.100:8200
> User-Agent: curl/7.64.0
> Accept: */*
> 
< HTTP/1.1 200 OK
< X-Content-Type-Options: nosniff
< Date: Tue, 07 Sep 2021 11:10:35 GMT
< Content-Length: 0
< 
* Connection #0 to host 192.168.100.100 left intact

I tried by removing middlewares and by deleting import elasticapm from base.py, but it didn't help.

manuelsaks avatar Sep 07 '21 11:09 manuelsaks

I think you can safely ignore this error. It comes from some work we've been doing to make the Client object globally available (and enforce it as a singleton).

We still want to fix this, but it shouldn't affect the actual agent's functionality.

basepi avatar Sep 13 '21 16:09 basepi