Python 疑難排解

Instana 套件是完全自動的,但如果發生錯誤,請 將問題單存檔

下列頁面概述您可以採取的一些步驟,以潛在診斷可能產生的任何問題。

支援的元件

在花太多時間診斷問題之前,請先確定有問題的元件受到支援。 您可以在 Python 支援的元件和版本 頁面中找到所有受支援元件的清單。

記載與環境變數

依預設,套件只會記載指出是否發生任何問題的訊息。 如果您想要更詳細的記載輸出,請設定 INSTANA_DEBUG 環境變數。 它會在 Instana gem 中啟用除錯層次記載。

甚至還有更多方法來控制記載輸出。 如需詳細資料,請參閱 Python 配置 頁面。

監視問題

主機代理程式型 AutoTrace™ 失敗

監視問題類型: python_autotrace_failed

已淘汰 Instana 主機代理程式型自動追蹤已嘗試如 自動安裝 區段中所述,自動檢測 Python 程序,但嘗試失敗。

潛在解決方案

  1. 如果 Python 處理程序在 Kubernetes 或類似 PaaS上執行,請確定您已閱讀並遵循文件 配置受監視應用程式的網路存取權

如果上述無法解決問題,請閱讀疑難排解小節 Python 處理程序未顯示在儀表板中

Python 感應器未安裝

監視問題類型: python_sensor_not_installed

Python 處理程序在我們 支援自動檢測的平台上執行,而且既未使用 在沒有程式碼變更的情況下啟動 ,也未使用 使用程式碼變更來啟動 方法來檢測處理程序。

潛在解決方案

  1. 利用 手動安裝指示 來適當地監視 Python 應用程式。

主機代理程式型 AutoTrace™ 必備項目檢查失敗

監視問題類型: python_autotrace_prerequisites_failed

潛在解決方案

  1. 為了讓 已淘汰 主機代理程式型 AutoTrace™ 功能運作,需要滿足數個必要條件。 您需要驗證下列必要條件已備妥:

    • Instana 主機代理程式可用的系統層次 pippip3
    • 代理程式可以找到並安裝必要的相依關係 (請參閱啟用 DEBUG 層次記載的代理程式日誌檔)

一般問題區域

Python 處理程序未顯示在儀表板中

  1. 檢查 Instana 主機代理程式日誌,以查看是否有任何與此 Python 程序相關的訊息。

    許多 Python 處理程序將自動從遠端檢測。 如果無法這樣做,「主機代理程式」可能會記載一則指出問題的訊息。

  2. 驗證您的環境是否受支援,以及您是否正在執行受支援的 Python 版本

    在花太多時間診斷問題之前,請先確定有問題的元件和環境受到支援。 您可以在 Python 支援的元件和版本 頁面中找到所有受支援元件的清單。

  3. 驗證安裝步驟

    此處理程序是否透過 AutoTrace 或手動進行檢測?

    如果透過 AutoTrace,請確定 配置的白名單 符合您要檢測的候選程序。

    如果是手動,請驗證已適當遵循 手動安裝步驟

  4. 驗證 Instana Python 套件已安裝且可供應用程式使用

    可以透過在 Python 應用程式 requirements.txt 檔案中查看 instana 來驗證此功能。

    或者, 從 Python 應用程式環境,您可以執行 pip list。 這將列出 Python 應用程式可用的所有 Python 套件。 驗證 Instana Python 套件是否在該清單中。

  5. 請確定 Instana 套件是最新版本。

    最新版本可在 Pipi上找到。

    requirements.txt中,您應該會看到 Instana Python 套件的最新版本與名稱一起註明,例如 instana==x.x.xpip list 也會在產生的清單中輸出版本號碼。

  6. 驗證應用程式日誌輸出中是否提及 Instana。

    應用程式及/或容器日誌應該一律具有類似於 Stan is on the scene. Starting Instana instrumentation version x.x.x 的開機訊息

    如果沒有這樣做,則很可能未安裝套件,或未適當遵循手動安裝步驟。

  7. 請啟用除錯輸出,並重新檢查應用程式或儲存器日誌。

    為 Python 處理程序設定環境變數 INSTANA_DEBUG=true ,並重新驗證應用程式或容器日誌 (與 #6相同)。

    請特別注意,查看是否有任何 Instana 相關錯誤訊息。

  8. 嘗試從主控台以詳細模式啟動 Python 應用程式

    如何執行此動作的範例主要取決於有問題的 Python 應用程式。 例如,如果 Python 應用程式包含在 app.py 中,您可以執行下列指令:

    export INSTANA_DEBUG=true
    python app.py
    

    請特別注意,以查看 Python 應用程式輸出中是否有任何 Instana 相關錯誤訊息。

  9. 如果使用已淘汰的「主機代理程式」型 AutoTracing ,請確保未設定 TERM 環境變數,且處理程序未呈現在已排除處理程序的清單中

    已淘汰的主機代理程式型 AutoTracing 將跳過嘗試追蹤任何已設定 TERM 環境變數或在代理程式配置的 excludes 區段中配置的處理程序。

    通常,只有在從連接至作用中使用者階段作業的終端機執行 Python 處理程序時,才會設定此值。 若要檢查是否已設定 TERM ,請執行 cat /proc/<pid>/environ ,其中 <pid> 是有問題 Python 程序的程序 ID。

    如果需要設定 TERM ,且需要檢測程序,請考量替代檢測方法,例如 Instana AutoTrace WebHook在沒有程式碼變更的情況下啟動

  10. 存檔支援問題單。

如果您已驗證每一個步驟,且 Python 程序仍未顯示在 Instana 儀表板中,請 將問題單存檔

支援問題單應該包括:

  1. 環境詳細資料; 平台、 Python 版本、使用中的架構
  2. 上述所有驗證的摘要。

來自 Python 應用程式的遺漏追蹤資料

  1. 請參閱 支援的版本 頁面,確定支援使用中的架構和程式庫。

  2. 請確定應用程式程序顯示在有問題主機下的 Instana 儀表板中。

    如果您的應用程式未顯示在 Instana 儀表板中,請參閱前一節。

  3. 設定 Python 應用程式程序的 INSTANA_DEBUG=true 環境,然後重新啟動程序。

    設定此環境變數之後,您應該會看到來自 Python 應用程式程序的日誌輸出,如下所示:

    DEBUG instana: initializing agent
    INFO instana: Stan is on the scene.  Starting Instana instrumentation version: 1.22.1
    DEBUG instana: initializing fsm
    DEBUG instana: Instrumenting asyncio
    DEBUG instana: Instrumenting aiohttp client
    DEBUG instana: Instrumenting aiohttp server
    DEBUG instana: Instrumenting asynqp
    DEBUG instana: Instrumenting cassandra
    DEBUG instana: Instrumenting couchbase
    DEBUG instana: Instrumenting flask (without blinker support)
    DEBUG instana: Instrumenting gevent: gevent not detected or loaded.  Nothing done.
    DEBUG instana: Instrumenting grpcio
    DEBUG instana: Instrumenting tornado client
    DEBUG instana: Instrumenting tornado server
    DEBUG instana: Instrumenting logging
    DEBUG instana: Instrumenting pymysql
    DEBUG instana: Instrumenting psycopg2
    DEBUG instana: Instrumenting redis
    DEBUG instana: Instrumenting sqlalchemy
    DEBUG instana: Instrumenting suds-jurko
    DEBUG instana: Instrumenting urllib3
    DEBUG instana: Instrumenting django
    DEBUG instana: Instana host agent found on localhost:42699
    DEBUG instana: Attempting to make an announcement to the agent on localhost:42699
    DEBUG instana: Spawning metric & span reporting threads
    DEBUG instana:  -> Metric reporting thread is now alive
    DEBUG instana:  -> Span reporting thread is now alive
    DEBUG instana: Announced pid: 34287 (true pid: 34287).  Waiting for Agent Ready...
    DEBUG instana: Instrumenting pymongo
    DEBUG instana: uwsgi hooks: decorators not available: likely not running under uWSGI
    INFO instana: Instana host agent available. We're in business. Announced pid: 34287 (true pid: 34287)
    DEBUG instana: Sending process snapshot data
    

    請確定預期元件在此清單中,以取得正確的可見性。

  4. 檢查回應標頭中的要求環境定義標頭

    使用 curlwget 對應用程式提出要求,以檢查從應用程式傳回的回應標頭。

    例如,針對 curl 使用 -i 選項將輸出回應標頭:

    curl -i http://127.0.0.1:8000/
    
    HTTP/1.1 200 OK
    Date: Wed, 10 Jun 2020 08:55:25 GMT
    Server: WSGIServer/0.2 CPython/3.6.9
    Content-Type: text/html; charset=utf-8
    X-Instana-T: 495b8301e86286c4
    X-Instana-S: 495b8301e86286c4
    X-Instana-L: 1
    Server-Timing: intid;desc=495b8301e86286c4
    Connection: close
    

    在輸出中,您應該會看到 X-Instana-TX-Instana-SX-Instana-L 標頭。

    如果您在輸出中看到這些標頭,則可以在「查詢分析」中使用過濾器 trace.id equals 495b8301e86286c4 來搜尋此特定追蹤,並假設使用中的時間範圍涵蓋提出此要求的期間。

  5. 存檔支援問題單

如果您正在執行其中一個受支援的架構或元件,且看不到前一個步驟中的 X-Instana-TX-Instana-SX-Instana-L 回應標頭,請 將支援問題單存檔。` ` `

將下列項目附加至支援問題單:

  1. 應用程式 requirements.txt 或使用中的 Python 套件清單 (來自 pip list的輸出)
  2. 從步驟 #2 到應用程式實體的儀表板鏈結
  3. 步驟 #3 的輸出
  4. 步驟 #4 的輸出

追蹤 Python 處理程序損毀,無法啟動新的執行緒訊息

如果 Python 應用程式因追蹤而損毀,且 RuntimeError: can't start new thread 訊息出現在應用程式日誌中,則最可能的原因是需要授與應用程式許可權。 如需追蹤和執行緒啟動許可權的相關資訊,請參閱 追蹤附註和限制

AutoTrace 正在損毀 Python 程序

  1. 存檔支援問題單

如果 AutoTrace 會使 Python 處理程序當機,請 將通行證存檔

  1. 更新 Instana 代理程式主機 configuration.yaml ,以修改 AutoTrace 行為

    文件頁面 說明如何配置 Python AutoTrace。 使用此選項,您可以排除損毀處理程序,或完全停用 AutoTrace 。 這可以作為暫時暫行解決方法,直到識別並修正損毀的主要原因為止。

  2. 使用手動安裝方法

    在過渡期間,您也可以使用 Python 可見性的 手動安裝方法

AUTOWRAPT_BOOTSTRAP, gevent & RecursionError

gevent 猴子會修補 Python 中的許多標準程式庫,其中一項 gevent需求是在開機處理程序中 盡早 完成。

如果您使用安裝的 啟動而不變更程式碼 方法 (使用 AUTOWRAPT_BOOTSTRAP 環境變數) 及 gevent 套件,則可能會發生錯誤,例如:

RecursionError: maximum recursion depth exceeded while calling a Python object
[Previous line repeated 212 more times]
super(SSLContext, SSLContext).options.__set__(self, value)

這是因為 autowrapt 會在任何其他套件之前載入 instana Python 套件 (甚至是 gevent)。

在此情況下,建議 移轉至 Python AutoTrace 或切換至 手動安裝方法 (透過將 import instana 新增至程式碼)。

"無法將 Instana Python 套件安裝至 /tmp/.instana/python"

由於各種原因,已淘汰的「主機代理程式」型 AutoTracing 可能會發生這種情況。 若要診斷,請執行下列動作:

  1. 啟用 DEBUG 層次 代理程式記載 ,以取得失敗的相關細節。
  2. 如果代理程式直接在主機上執行 (不是在儲存器中) ,請確定已使用 pip install -U pip更新系統 pip 指令。 已知某些早期版本的 pip 會在特定情況下造成問題。

移轉至 Instana AutoTrace WebHook

Instana AutoTrace WebHook 現在是 Instana 所監視 Python 應用程式的受支援自動檢測方法。

若要完全移轉至 AutoTrace WebHook,您必須從應用程式中移除下列項目:

  1. Instana Python 套件

    Instana AutoTrace WebHook 將獨立管理您應用程式的 Instana Python 套件。 您或您的組織不需要手動安裝它。

    請確保從 requirements.txtPipfilevirtualenv中移除 instana Python 套件。

    附註: 如果您正在進行 OpenTracing API 呼叫,則應該改為明確匯入 opentracing ,並確保對該套件進行呼叫 (例如 opentracing.tracer.start_active_span)。 Instana 仍會接收產生的追蹤資料。

  2. 移除 AUTOWRAPT_BOOTSTRAP 環境變數

    此環境變數用來載入 Instana Python 套件,而不需要進行任何程式碼變更。 使用 Instana AutoTrace WebHook,不再需要此動作。

  3. 移除任何 import instana 呼叫

    Python AutoTrace 會自動將 Instana Python 套件套用至 Python 應用程式。 可以移除 Instana Python 套件的手動匯入。

另請參閱