elastic / elastic/apm-agent-python

Error when testing apm connection from the agent

Open
#1,319 1 comment 0 reactions 0 assignees View on GitHub
agent-python
Dominant language
Python
Stars
431
Forks
239
Avg merge
5d 10h
Merged PRs (30d)
7

Description

**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
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",
(...)
]
(...)
```
2. 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.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.