elastic / elastic/apm-agent-python

Python Agent unable to connect to APM-server

オープン
#1,018 コメント 2 件 リアクション 0 件 担当者 0 名 GitHub で見る
agent-python
主要言語
Python
スター
431
フォーク
239
平均マージ
5日 10時間
マージ済み PR(30日)
7

説明

Errors when trying to send message to APM Server from non framework python test application.

- run the sample.py script from a 3.6.8 virtEnv

Click to expand Trace from script

```
/Users/Shared/Development/pythonEnvs/PyCurion/bin/python /Applications/PyCharm.app/Contents/plugins/python/helpers/pydev/pydevd.py --multiproc --qt-support=auto --client 127.0.0.1 --port 51312 --file /Users/Shared/Development/PyCurion/PyCurion/bin/testAPM.py
pydev debugger: process 78700 is connecting

Connected to pydev debugger (build 202.8194.22)
Failed to submit message: 'Unable to reach APM Server: HTTPSConnectionPool(host=\'elastic-apm.FQDN.biz\', port=8200): Max retries exceeded with url: /intake/v2/events (Caused by SSLError(\'Fingerprints did not match. Expected "13efb39a2f6654e8c67bd04f4c6d4c90cd6cab5091bcedc73787f6b77d3d3fe7", got "b\\\'81799d57e55d334ff35ab66358945ae4639bfd06e571ee9c431457e921e3960e\\\'".\')) (url: https://elastic-apm.FQDN.biz:8200/intake/v2/events)'
Traceback (most recent call last):
File "/usr/local/lib/python3.8/site-packages/urllib3/connectionpool.py", line 670, in urlopen
httplib_response = self._make_request(
File "/usr/local/lib/python3.8/site-packages/urllib3/connectionpool.py", line 381, in _make_request
self._validate_conn(conn)
File "/usr/local/lib/python3.8/site-packages/urllib3/connectionpool.py", line 976, in _validate_conn
conn.connect()
File "/usr/local/lib/python3.8/site-packages/urllib3/connection.py", line 374, in connect
assert_fingerprint(
File "/usr/local/lib/python3.8/site-packages/urllib3/util/ssl_.py", line 177, in assert_fingerprint
raise SSLError(
urllib3.exceptions.SSLError: Fingerprints did not match. Expected "13efb39a2f6654e8c67bd04f4c6d4c90cd6cab5091bcedc73787f6b77d3d3fe7", got "b'81799d57e55d334ff35ab66358945ae4639bfd06e571ee9c431457e921e3960e'".

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "/Users/Shared/Development/pythonEnvs/PyCurion/lib/python3.8/site-packages/elasticapm/transport/http.py", line 82, in send
response = self.http.urlopen(
File "/usr/local/lib/python3.8/site-packages/urllib3/poolmanager.py", line 336, in urlopen
response = conn.urlopen(method, u.request_uri, **kw)
File "/usr/local/lib/python3.8/site-packages/urllib3/connectionpool.py", line 752, in urlopen
return self.urlopen(
File "/usr/local/lib/python3.8/site-packages/urllib3/connectionpool.py", line 752, in urlopen
return self.urlopen(
File "/usr/local/lib/python3.8/site-packages/urllib3/connectionpool.py", line 752, in urlopen
return self.urlopen(
File "/usr/local/lib/python3.8/site-packages/urllib3/connectionpool.py", line 724, in urlopen
retries = retries.increment(
File "/usr/local/lib/python3.8/site-packages/urllib3/util/retry.py", line 439, in increment
raise MaxRetryError(_pool, url, error or ResponseError(cause))
urllib3.exceptions.MaxRetryError: HTTPSConnectionPool(host='elastic-apm.FQDN.biz', port=8200): Max retries exceeded with url: /intake/v2/events (Caused by SSLError('Fingerprints did not match. Expected "13efb39a2f6654e8c67bd04f4c6d4c90cd6cab5091bcedc73787f6b77d3d3fe7", got "b\'81799d57e55d334ff35ab66358945ae4639bfd06e571ee9c431457e921e3960e\'".'))

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "/Users/Shared/Development/pythonEnvs/PyCurion/lib/python3.8/site-packages/elasticapm/transport/base.py", line 228, in _flush
self.send(data)
File "/Users/Shared/Development/pythonEnvs/PyCurion/lib/python3.8/site-packages/elasticapm/transport/http.py", line 96, in send
raise TransportException(message, data, print_trace=print_trace)
elasticapm.transport.exceptions.TransportException: Unable to reach APM Server: HTTPSConnectionPool(host='elastic-apm.FQDN.biz', port=8200): Max retries exceeded with url: /intake/v2/events (Caused by SSLError('Fingerprints did not match. Expected "13efb39a2f6654e8c67bd04f4c6d4c90cd6cab5091bcedc73787f6b77d3d3fe7", got "b\'81799d57e55d334ff35ab66358945ae4639bfd06e571ee9c431457e921e3960e\'".')) (url: https://elastic-apm.FQDN.biz:8200/intake/v2/events)

Process finished with exit code 0

```

- The thing I not about the error is that the return is expecting a "str", but gets a "b'dif_str'"

**Environment (please complete the following information)**
- OS: Testing on MacOS
- Python version: 3.8.6
- Framework and version [e.g. Django 2.1]: None
- APM Server version: 7.10.1
- Agent version: 5.10.1

**Additional context**

Add any other context about the problem here.

- Agent config options

Working Java Config

- The APM & entire Elastic Stack are configured to use an entrusted-chain.crt for ssl
- On the servers where we run the Java app that .crt was added to the java cacerts for the Java cert store(using keytool -import).

```
JAVA_AGENT="-javaagent:/usr/share/java/tomcat/elastic-apm-agent-current.jar \
-Delastic.apm.service_name=Support-test-JAVAapp01 \
-Delastic.apm.server_urls=https://elastic-apm.FQDN.biz:8200 \
-Delastic.apm.application_packages=com.XXX.**"
```


- sample.py:

Click to expand Simple test code

```
from elasticapm import Client

client = Client(service_name="PyCustom-test",
server_url='https://elastic-apm.FQDN.biz:8200',
server_cert='./entrust-chain.crt',
framework_name='PyCustomTest')

if __name__ == "__main__":
client.capture_message('Test Message')
```

コントリビューションガイド

コントリビューションガイドを開く

調査の方向性

まず、報告されている Python、agent、APM Server のバージョンで sample.py を実行し、次に trace にある urllib3 の fingerprint エラーと併せて elasticapm/transport/http.py を調査します。server_cert の接続失敗を再現し、bytes と string の間で fingerprint が不一致になることなく、設定された証明書で正常に接続できることを確認します。

索引モデルが issue の本文から書いたものです。

評価

技術スタック
python
領域
observability-sre
issue の種類
バグ
難易度
3/5
見積もり時間
1〜2日
活発さ
停滞
明瞭さ
おおむね明確
初心者へのやさしさ
35/100

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。