4
5

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

New Relic APMでリクエストのクエリパラメータを取得してみよう

Last updated at Posted at 2025-01-31

New Relic APMの簡単な設定でリクエストに付与されているクエリパラメータを取得することで、ログから確認するよりも簡単にリクエストについたパラメータを確認できるようになりますよ!設定方法についてご紹介です!

設定方法

Java APMエージェントを例にクエリパラメータの取得方法についてご紹介です。APMエージェントはデフォルトの設定ではセンシティブな情報が含まれている可能性があるため、リクエストに紐づくクエリパラメータを取得しませんが、APMエージェントの設定ファイルの変更で取得できるようになります。

幾つか取得方法の設定を見ていきます。

全てのクエリパラメータを取得する

リクエストに紐づく全てのパラメータを取得する場合は、attirubtes.includerequest.parameters.*と定義します。

newrelic.yml
  attributes:

    # When true, attributes will be sent to New Relic. The default is true.
    enabled: true

    #A comma separated list of attribute keys whose values should
    # be sent to New Relic.
    include: request.parameters.*

    # A comma separated list of attribute keys whose values should
    # not be sent to New Relic.
    #exclude:

アプリケーションを再起動することで設定が反映されます。

取得したパラメータはTransactionの属性(Attribute)として付与されるため、Transactionに紐づくパラメータをすぐに確認することができるようになります。
リクエスト例: http://www.example.com/?example1=1&example2=2&example3=3

image.png

取得するパラメータを明示的に指定する

取得するパラメータを明示的に指定することも可能です。

newrelic.yml
  attributes:

    # When true, attributes will be sent to New Relic. The default is true.
    enabled: true

    #A comma separated list of attribute keys whose values should
    # be sent to New Relic.
    include: request.parameters.example1,request.parameters.example2

    # A comma separated list of attribute keys whose values should
    # not be sent to New Relic.
    #exclude:

この場合、attirubtes.includeで明示的に指定したパラメータのみ属性として取得されます。
リクエスト例: http://www.example.com/?example1=1&example2=2
image.png

一部のパラメータの取得を除外する

attirubtes.includeでワイルドカードで指定しますが、一部のパラメータだけattirubtes.excludeで定義することで取得を除外することも可能です。

newrelic.yml
  attributes:

    # When true, attributes will be sent to New Relic. The default is true.
    enabled: true

    #A comma separated list of attribute keys whose values should
    # be sent to New Relic.
    include: request.parameters.*

    # A comma separated list of attribute keys whose values should
    # not be sent to New Relic.
    exclude: request.parameters.example1,request.parameters.example3

attirubtes.excludeで定義したパラメータは取得されてないことが確認できます。
リクエスト例: http://www.example.com/?example1=1&example2=2&exapmle3=3
image.png

クエリパラメータの分析例

特定のクエリパラメータが付与されているTransactionの件数をrequest.uri毎に算出する例です。

SELECT
    count(*)
FROM
    Transaction
WHERE
    appName = '****'
and request.parameters.example1 is not null
FACET request.uri,request.parameters.example1

image.png
WHERE句でパラメーターに含まれる値を絞り込んで、request.uri毎のTransactionの件数の推移を確認する例です。

SELECT
    count(*)
FROM
    Transaction
WHERE
    appName = '****'
and request.parameters.example2 = '2'
FACET request.uri TIMESERIES

image.png

まとめ

本記事では、New Relic APMでリクエストのクエリパラメータを取得する設定例と、クエリパラメータを使った分析の例をご紹介しました。ログから確認するよりも簡単にパラメータを使ったアプリケーションの分析が出来るようになります。

言語毎の設定方法は公式ドキュメントをご確認ください。

JavaのAPMエージェントのインストール方法を確認されたい方は、以下の記事が参考になります。

その他

New Relicでは、新しい機能やその活用方法について、QiitaやXで発信しています!
無料でアカウント作成も可能なのでぜひお試しください!

New Relic株式会社のX(旧Twitter)Qiita OrganizationOrganizationでは、
新機能を含む活用方法を公開していますので、ぜひフォローをお願いします。

無料のアカウントで試してみよう!
New Relic フリープランで始めるオブザーバビリティ!

4
5
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
4
5

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?