Web サイトの自動インスツルメンテーション

Instana のウェブサイトは、ウェブサイトの監視を可能にするため、自動的に JavaScript エージェントをウェブサイトに組み込みます。 この自動計測機能は、設定手順が最小限で済み、Webサイトのコードを変更する必要もありません。

詳細については、 「 JavaScript エージェント」 を参照してください。

サポート情報

Webサイトの自動計測機能は、以下のWebサーバーでのみサポートされています:
  • HTTPd サーバー : HTTPd センサー( 1.2.12 以降)が必要です。 この autoPageDetection オプションは、 HTTPd センサー( 1.2.19 )およびEUMセンサー( 1.0.5 )で利用可能です。
  • Tomcat サーバー(Jakarta ベース):デフォルトのコンテンツタイプと、キーが である url/path セレクタ matchExpressions のみが、自動インスツルメンテーションの対象となります。 さらに、固定のサイズを指定しているHTMLレスポンスについては、 Content-LengthEUMスクリプトの自動挿入がスキップされます。これは、レスポンス本文を変更すると、宣言されたコンテンツサイズが無効になるためです。 この機能は、 Java Tracer( 2.0.9 )からご利用いただけます。
注: エンドユーザー監視(EUM)と HTTPd トレースは、監視対象の技術において同じインプロセスバイナリを共有している場合でも、個別に有効化および無効化することができます。 ただし、EUMが有効になっている場合、トレース機能も有効になり、エンドツーエンドの監視が可能になります。

Webサイトの自動計測を有効にする

Web サイトの自動インスツルメンテーションを有効にするには、以下の手順を実行します。

ステップ1:ウェブサイトを作成する

モニターする Web サイトを作成するには、以下の手順を実行します。

  1. Instana のUIで、 「Webサイトとモバイルアプリ」 に移動し、 「Webサイトを追加」 をクリックします。

  2. ウェブサイト名を入力し、 「ウェブサイトを追加」 をクリックしてください。

    図 1. Instana ウェブサイトを作成する
    Instana ウェブサイトを作成する
  3. すべての準備ができています。 reportingUrlkey、および jsAgentUrlの値を書き留めます。 ステップ2で、 Instana*instanaAgentDir*/etc/instana/configuration.yaml エージェントの設定ファイルにこれらの値を指定する必要があります。

    図 2. Instana ウェブサイト作成の準備完了
    Instana ウェブサイト作成の準備完了

ステップ 2: エージェントの設定ファイルを変更する

Instana*instanaAgentDir*/etc/instana/configuration.yaml エージェントのファイルのうち、 Apache HTTP Server が含まれている箇所を修正してください。 Instanaconfiguration.yaml エージェントのファイルには、Webサイトの自動計測に関する以下の設定項目が用意されています:

#EUM
#com.instana.plugin.eum:
#  instrumentation:
#    #contentTypes:                       # List of the 'Content-Type' values for matching requests that need to be instrumented,
#                                         #  default values in the list are 'text/html' and 'application/xhtml+xml'.
#    #  - 'text/html'
#    #  - 'application/xhtml+xml'
#    #aggressive: false                   # Indicates whether to instrument with the EUM JavaScript agent if Instana cannot determine
#                                         # the 'Content-Type' of the request, default is false.
#    #######################################################################################################
#    # Following parameters are used as common EUM monitoring configuration.
#    # They can be overwritten by specifying them in the website configuration.
#    #######################################################################################################
#    jsAgentUrl: 'https://eum.instana.io/1.7.2/eum.min.js' # EUM JavaScript agent download URL.
#    reportingUrl: <reportingUrl>                    # The URL to which to send website monitoring data to.
#    trackSessions: true                             # Indicates whether to enable session tracking, default is true.
#    autoPageDetection: true                         # Indicates whether to enable automatic page detection for single-page-application, default is true.
#    #######################################################################################################
#    # AutoPageDetection can be further customised to use url RegEx mapping rule or document title as page name.
#    # If the following parameters are enabled the priority of autoPageDetection will be:
#    # RegEx mapping rule > auto detect page title > regular automatic page detection
#    #autoPageDetectionRegex:                        # Indicates whether to match an array of RegExp objects to the URL of page change and replace them with the string provided.
#     #- ['/.*MappingRule.*/i', 'PageTitle String']
#     #- ['/.*aboutPage.*-([A-Za-z].*)/', 'About Page id: $1']
#    #autoPageDetectionPageTitle: false              # Indicates whether to enable document title as page name. Default value is false.
#    #######################################################################################################
#    integrityId: 'sha384-cgeSlevgebehPauohUhsnAeBrpjXzaj94mSv3L2EXjCQH0RRb9xSQ2ErGOWkthIJ' # The SHA value corresponding to the jsAgentUrl version for SRI enablement.
#    #######################################################################################################
#    # Following parameters are used to configure each monitored website.
#    # Optional parameters are commented out by default. Remove the hashtag (#) when needed.
#    #######################################################################################################
#    websites:
#      - name: <WEBSITE_NAME>             # Name of the website for the website configuration in Instana.
#        key: <WEBSITE_KEY>               # Monitoring key for the website configuration in Instana.
#        #enabled: true                   # Indicates whether to enable website monitoring on this website, default is true.
#        #reportingUrl: <reportingUrl>    # The URL to which to send website monitoring data to. Overwrites upper-level setting.
#        #jsAgentUrl: 'https://eum.instana.io/1.7.2/eum.min.js' # JavaScript agent download URL. Overwrites upper-level setting.
#        #trackSessions: true             # Indicates whether to enable session tracking, default is true. Overwrites upper-level setting.
#        #autoPageDetection: true         # Indicates whether to enable automatic page detection for single-page-application, default is true. Overwrites upper-level setting.
#        ##autoPageDetectionRegex:         # Indicates whether to set page title based on a specific RegEx mapping rule in automatic page detection. Overwrites upper-level setting.
#        ## - ['/.*MappingRule.*/i', 'PageTitle']
#        ## - ['/.*aboutPage.*-([A-Za-z].*)/', 'About Page id: $1']
#        ##autoPageDetectionPageTitle: false  # Indicates whether to enable document title as page name. Default value is false. Overwrites upper-level setting.
#        #integrityId: 'sha384-cgeSlevgebehPauohUhsnAeBrpjXzaj94mSv3L2EXjCQH0RRb9xSQ2ErGOWkthIJ' # The SHA value corresponding to the jsAgentUrl version for SRI enablement. Overwrites upper-level setting.
#        #mode: 'regular'                 # Mode for monitoring data transmission, default is 'regular'.
#                                         # Available mode is 'regular'.
#        selector:                        # List of match expressions to filter requests.
#          matchExpressions:              # When all match expressions are evaluated to true, the request is monitored.
#                                         # At least one match expression with the key of the 'url' catalog must be defined.
#            - key: 'url/path'            # Key specified in the <catalog>/<resource> format.
#                                         # Available catalogs in the key include 'url' for request filtering plus
#                                         #  'container' and 'k8s' for Web Server infrastructure filtering.
#                                         # Available keys:
#                                         #  'url/hostname', 'url/path', and 'url/filename'
#                                         #  'container/name' and 'container/imagename'
#                                         #  'k8s/namespace', 'k8s/podname', and 'k8s/containername'
#              operator: 'StartWith'      # Match expression operators: 'Contains', 'ContainsIgnoreCase', 'Equals',
#                                         #  'EqualsIgnoreCase', 'StartWith', and 'StartWithIgnoreCase'.
#              values:                    # List of match expression values.
#                - '/'
 

各行のコメントに従って、EUM Web サイトの自動インスツルメンテーションを構成します。 以下の例を参照してください。

com.instana.plugin.eum:
  instrumentation:
    jsAgentUrl: 'https://eum.instana.io/1.7.2/eum.min.js'
    reportingUrl: 'https://eum.example.com'
    trackSessions: true
    integrityId: 'integrityId for version 1.7.2'
    websites:
      - name: demo
        key: YOURWEBSITEKEYHERE
        selector:
          matchExpressions:
            - key: 'url/hostname'
              operator: 'Equals'
              values:
                - 'example.com'
 

この例では、ホスト名 へのすべての HTTPexample.com リクエストに対して、Webサイトの監視が有効になっています。 生成されたビーコンは、レポート用 YOURWEBSITEKEYHERE キーを添付して、 URL 宛て demo に送信 https://eum.example.comされます。

変更した configuration.yaml ファイルを保存すると、 HTTPd のEUMモジュールが自動的にダウンロードされ、インストールされます。 HTTPdinstana_tracing.conf の設定ディレクトリにあるファイルを確認することで、モジュールを検証できます。

手順 3: Web サーバーを再起動する

HTTPd のトレース設定で true が に設定されている autoRestart 場合、 Apache HTTP Server を手動で再起動する必要はありません。

com.instana.plugin.httpd:
  tracing:
    autoRestart: true
 

それ以外の場合は、 Apache HTTP Server を正常に再起動して、EUMモジュールを読み込んでください。

ステップ4:ウェブサイトのダッシュボードで確認する

ワークロードがウェブサイトに存在することを確認してください。 Go Instana のUIにあるWebサイトのダッシュボードにアクセスし、監視データが正常に受信されていることを確認してください。

Webサイトの自動計測機能を無効にする

Web サイトの自動インスツルメンテーションを無効にするには、 configuration.yaml ファイル内の com.instana.plugin.eum のすべての行をコメント化または削除します。

正規表現の例

複数の仮想ホストでのリクエストフィルタリングの例

以下の例は、 Apache HTTPd の設定に複数の VirtualHost が存在する場合に、Webサイトが自動的に計測対象となるよう、マッチ式を定義する方法を示しています。

例えば、以下の VirtualHost 定義を参照してください。

Listen 80
<VirtualHost *:80>
    DocumentRoot "/www/example1"
    ServerName www.example.com

    # Other directives here
</VirtualHost>

<VirtualHost *:80>
    DocumentRoot "/www/example2"
    ServerName www.example.org

    # Other directives here
</VirtualHost>
 

例 1: URL/パスをキーとして使用する

以下の構成に示すように、 url/path キーを使用して、モニターする要求をフィルターに掛けることができます。

com.instana.plugin.eum:
  instrumentation:
    jsAgentUrl: 'https://eum.instana.io/eum.min.js'
    reportingUrl: 'https://eum.example.com'
    trackSessions: true
    websites:
      - name: 'website1'
        key: 'WEBSITEKEY1'
        selector:
          matchExpressions:
            - key: 'url/path'
              operator: 'StartWith'
              values:
                - '/products'
                - '/carts'
      - name: 'website2'
        key: 'WEBSITEKEY2'
        selector:
          matchExpressions:
            - key: 'url/path'
              operator: 'StartWith'
              values:
                - '/offers'
                - '/employees'

 

この設定では、 URL のパスが または /products で始まるクライアントリクエストの /carts EUMデータが、 website1のダッシュボードに表示されます。 URL のパスが または /offers で始まるクライアントリクエストの /employees EUMデータは、のダッシュボードに website2表示されます。

例 2: URL やファイル名をキーとして使用する

以下の構成に示すように、 url/filename キーを使用して DocumentRoot を突き合わせることもできます。

com.instana.plugin.eum:
  instrumentation:
    jsAgentUrl: 'https://eum.instana.io/eum.min.js'
    reportingUrl: 'https://eum.example.com'
    trackSessions: true
    websites:
      - name: 'website1'
        key: 'WEBSITEKEY1'
        selector:
          matchExpressions:
            - key: 'url/filename'
              operator: 'StartWith'
              values:
                - '/www/example1'
      - name: 'website2'
        key: 'WEBSITEKEY2'
        selector:
          matchExpressions:
            - key: 'url/filename'
              operator: 'StartWith'
              values:
                - '/www/example2'
 

この構成では、 /www/example1 内の文書に対するクライアント要求の EUM データが website1のダッシュボードに表示され、 /www/example2 内の文書に対するクライアント要求の EUM データが website2のダッシュボードに表示されます。

例 3: URL/ホスト名をキーとして使用する

ServerNameに一致させるために、以下の構成に示すように url/hostname キーを使用できます。

com.instana.plugin.eum:
  instrumentation:
    jsAgentUrl: 'https://eum.instana.io/eum.min.js'
    reportingUrl: 'https://eum.example.com'
    trackSessions: true
    websites:
      - name: 'website1'
        key: 'WEBSITEKEY1'
        selector:
          matchExpressions:
            - key: 'url/hostname'
              operator: 'Equals'
              values:
                - 'www.example.com'
      - name: 'website2'
        key: 'WEBSITEKEY2'
        selector:
          matchExpressions:
            - key: 'url/hostname'
              operator: 'Equals'
              values:
                - 'www.example.org'
 

この構成では、サーバー www.example.com のクライアント要求の EUM データが website1のダッシュボードに表示され、サーバー www.example.org のクライアント要求の EUM データが website2のダッシュボードに表示されます。

注: この設定における url/hostname は、 HTTPd サーバーが実行されているホストのホスト名ではなく、 HTTPd 設定ファイル内の VirtualHost 定義における ServerName を指します。

例 4:複数のキーを使用する

モニターする要求をフィルタリングするには、以下の構成に示すように、 url/pathキー、 url/filenameキー、および url/hostname キーの組み合わせを使用できます。

com.instana.plugin.eum:
  instrumentation:
    jsAgentUrl: 'https://eum.instana.io/eum.min.js'
    reportingUrl: 'https://eum.example.com'
    trackSessions: true
    websites:
      - name: 'website1'
        key: 'WEBSITEKEY1'
        selector:
          matchExpressions:
            - key: 'url/hostname'
              operator: 'Equals'
              values:
                - 'www.example.com'
            - key: 'url/path'
              operator: 'StartWith'
              values:
                - '/products'
                - '/carts'
      - name: 'website3'
        key: 'WEBSITEKEY3'
        selector:
          matchExpressions:
            - key: 'url/hostname'
              operator: 'Equals'
              values:
                - 'www.example.com'
            - key: 'url/path'
              operator: 'StartWith'
              values:
                - '/offers'
                - '/employees'
      - name: 'website2'
        key: 'WEBSITEKEY2'
        selector:
          matchExpressions:
            - key: 'url/filename'
              operator: 'StartWith'
              values:
                - '/www/example2'

 

この設定では、サーバーへのクライアントリクエストに関するEUMデータは、2つのWebサイトに分けられます。 website1 1つは www.example.comURL/carts が または /products で始まるリクエスト用 website3 、もう1つは URL が または /offers で始まる /employeesリクエスト用です。 /www/example2 の文書に対するクライアント要求の EUM データが、 website2のダッシュボードに表示されます。

インフラストラクチャ・フィルタリングの例

以下の例は、特定のインフラストラクチャ展開上のWebサイトが自動的に計測対象となるよう、マッチ式を定義する方法を示しています。

注: リクエストフィルタリングとは異なり、インフラストラクチャフィルタリングは任意です。

例 1:ホストにデプロイされたコンテナ化されたウェブサイト

com.instana.plugin.eum:
  instrumentation:
    jsAgentUrl: 'https://eum.instana.io/eum.min.js'
    reportingUrl: 'https://eum.example.com'
    trackSessions: true
    websites:
      - name: 'containerized website'
        key: 'WEBSITEKEY1'
        selector:
          matchExpressions:
            - key: 'url/hostname'
              operator: 'Equals'
              values:
                - 'www.example.com'
            - key: 'container/name'
              operator: 'Equals'
              values:
                - 'example-app'
 

この構成では、Web サイト・デプロイメント・コンテナー名が example-appと一致すると、サーバー www.example.com のクライアント要求の EUM データが containerized websiteのダッシュボードに表示されます。

例 2: Kubernetes 環境にデプロイされたコンテナ化されたウェブサイト

com.instana.plugin.eum:
  instrumentation:
    jsAgentUrl: 'https://eum.instana.io/eum.min.js'
    reportingUrl: 'https://eum.example.com'
    trackSessions: true
    websites:
      - name: 'k8s website'
        key: 'WEBSITEKEY1'
        selector:
          matchExpressions:
            - key: 'url/hostname'
              operator: 'Equals'
              values:
                - 'www.example.com'
            - key: 'k8s/namespace'
              operator: 'Equals'
              values:
                - 'prod-example'
            - key: 'k8s/podname'
              operator: 'Equals'
              values:
                - 'example-pod'
            - key: 'k8s/containername'
              operator: 'Equals'
              values:
                - 'example-app'
 

この構成では、Web サイトが Kubernetes 環境の prod-example 名前空間のポッド example-pod 上のコンテナー example-app にデプロイされると、 k8s websiteのダッシュボードに、サーバー www.example.com のクライアント要求の EUM データが表示されます。

Apache モジュール「mod_deflate」の使用

Apache HTTPd サーバーで mod_deflate モジュールを使用して gzip 圧縮が有効になっている場合は、ウェブサイトの自動計測機能を使用するように Apache の設定を更新してください。

enabling website automatic instrumentation セクションで説明した最初の3ステップを完了し、次のステップを完了します:

  1. お使いの HTTPd サーバーで、 HTTPd のEUMモジュール(dem_module)が読み込まれているか確認してください:

    httpd -M -f <HTTPd_CONF_FILE>
     
  2. HTTPd の設定ファイルにある AddOutputFilterByType の設定を変更し、フィルター DEFLATE の前に INSTANA_DEM_OUT 配置するようにします:

    <IfModule mod_deflate.c>
      <IfModule mod_filter.c>
        AddOutputFilterByType INFLATE;INSTANA_DEM_OUT;DEFLATE text/html text/plain text/xml text/css text/javascript
        AddOutputFilterByType DEFLATE application/x-javascript application/javascript application/ecmascript
        AddOutputFilterByType DEFLATE application/rss+xml
        AddOutputFilterByType DEFLATE application/wasm
        AddOutputFilterByType DEFLATE application/xml
      </IfModule>
    </IfModule>
     
  3. HTTPd サーバーを正常に再起動してください。