宣言的設定

宣言的設定は、application.yaml 内で OpenTelemetry の宣言的設定スキーマを使用します。

このアプローチは以下のような場合に便利です。

  • 設定するオプションが多い場合
  • application.propertiesapplication.yaml では利用できない設定オプションを使いたい場合
  • Java エージェントと同じ設定形式を使いたい場合

サポートされるバージョン

宣言的設定は OpenTelemetry Spring Boot スターターのバージョン 2.26.0 以降でサポートされています。

依存関係の管理

はじめにのページに記載されているように、dependencyManagementopentelemetry-instrumentation-bom をインポートしてください。

はじめに

application.yamlotel.file_format: "1.0"(または現在の、もしくは希望するバージョン)を追加して、宣言的設定を有効にします。

otel:
  file_format: '1.0'

  resource:
    detection/development:
      detectors:
        - service:
    attributes:
      - name: service.name
        value: my-spring-app

  propagator:
    composite:
      - tracecontext:
      - baggage:

  tracer_provider:
    processors:
      - batch:
          exporter:
            otlp_http:
              endpoint: ${OTEL_EXPORTER_OTLP_TRACES_ENDPOINT:http://localhost:4318/v1/traces}

  meter_provider:
    readers:
      - periodic:
          exporter:
            otlp_http:
              endpoint: ${OTEL_EXPORTER_OTLP_METRICS_ENDPOINT:http://localhost:4318/v1/metrics}

  logger_provider:
    processors:
      - batch:
          exporter:
            otlp_http:
              endpoint: ${OTEL_EXPORTER_OTLP_LOGS_ENDPOINT:http://localhost:4318/v1/logs}

${VAR:default} はコロン1つ(Spring の構文)を使用しており、エージェントのスタンドアロン YAML ファイルで使用される ${VAR:-default} 構文とは異なることに注意してください。

既存の設定を変換する

Paste your existing configuration below to generate the equivalent declarative configuration YAML. You can fill in any combination of inputs.

設定オプションのマッピング

以下のルールは、application.properties / application.yaml の設定オプションが宣言的設定の対応する形式にどのようにマッピングされるかを説明します。

計装の有効化/無効化

宣言的設定では、計装の有効化/無効化は個別のプロパティのかわりに集中管理されたリストを使用します。 計装名には -(kebab-case)ではなく _(snake_case)を使用します。

プロパティ宣言的設定
otel.instrumentation.jdbc.enabled=trueotel.distribution.spring_starter.instrumentation.enabled: [jdbc]
otel.instrumentation.logback-appender.enabled=falseotel.distribution.spring_starter.instrumentation.disabled: [logback_appender]
otel.instrumentation.common.default-enabled=falseotel.distribution.spring_starter.instrumentation.default_enabled: false

例:

otel:
  distribution:
    spring_starter:
      instrumentation:
        default_enabled: false
        enabled:
          - jdbc
          - spring_web
        disabled:
          - logback_appender

計装の設定

otel.instrumentation.* 配下の設定オプション(有効化/無効化以外)は、otel.instrumentation/development.java.* にマッピングされます。

  1. otel.instrumentation. 接頭辞を取り除く
  2. 各セグメントで -_ に置き換える
  3. otel.instrumentation/development.java. 配下に配置する
  4. キーの /development 接尾辞は実験的な機能を示す(逆マッピングについては ConfigPropertiesBackedDeclarativeConfigPropertiestranslateName メソッドを参照)

例:

プロパティ宣言的設定
otel.instrumentation.logback-appender.experimental-log-attributesotel.instrumentation/development.java.logback_appender.experimental_log_attributes/development

デフォルトのアルゴリズムに従わない特別なマッピングを持つオプションもあります。

プロパティ宣言的設定
otel.instrumentation.common.db.query-sanitization.enabledotel.instrumentation/development.java.common.db.query_sanitization.enabled
otel.instrumentation.common.db-statement-sanitizer.enabled (deprecated)otel.instrumentation/development.java.common.db_statement_sanitizer.enabled
otel.instrumentation.common.db.experimental.sqlcommenter.enabledotel.instrumentation/development.java.common.db.sqlcommenter/development.enabled
otel.instrumentation.http.client.capture-request-headersotel.instrumentation/development.general.http.client.request_captured_headers
otel.instrumentation.http.client.capture-response-headersotel.instrumentation/development.general.http.client.response_captured_headers
otel.instrumentation.http.server.capture-request-headersotel.instrumentation/development.general.http.server.request_captured_headers
otel.instrumentation.http.server.capture-response-headersotel.instrumentation/development.general.http.server.response_captured_headers
otel.instrumentation.http.client.emit-experimental-telemetryotel.instrumentation/development.java.common.http.client.emit_experimental_telemetry/development
otel.instrumentation.http.server.emit-experimental-telemetryotel.instrumentation/development.java.common.http.server.emit_experimental_telemetry/development
otel.instrumentation.http.known-methodsotel.instrumentation/development.java.common.http.known_methods
otel.instrumentation.messaging.experimental.receive-telemetry.enabledotel.instrumentation/development.java.common.messaging.receive_telemetry/development.enabled
otel.instrumentation.messaging.experimental.capture-headersotel.instrumentation/development.java.common.messaging.capture_headers/development
otel.instrumentation.genai.capture-message-contentotel.instrumentation/development.java.common.gen_ai.capture_message_content
otel.instrumentation.sanitization.url.experimental.sensitive-query-parametersotel.instrumentation/development.general.sanitization.url.sensitive_query_parameters/development
otel.semconv-stability.opt-inotel.instrumentation/development.general.semconv_stability.opt_in
otel.semconv.exception.signal.previewotel.instrumentation/development.general.semconv_exception.signal.preview
otel.instrumentation.experimental.span-suppression-strategyotel.instrumentation/development.java.common.span_suppression_strategy/development
otel.instrumentation.opentelemetry-annotations.exclude-methodsotel.instrumentation/development.java.opentelemetry_extension_annotations.exclude_methods
otel.experimental.javascript-snippetotel.instrumentation/development.java.servlet.javascript_snippet/development
otel.jmx.enabledotel.instrumentation/development.java.jmx.enabled
otel.jmx.configotel.instrumentation/development.java.jmx.config
otel.jmx.discovery.delayotel.instrumentation/development.java.jmx.discovery.delay
otel.jmx.target.systemotel.instrumentation/development.java.jmx.target.system

instrumentation/development セクションには2つのトップレベルグループがあります。

  • general.* — 言語横断的な設定(HTTP ヘッダー、セマンティック規約の安定性)
  • java.* — Java 固有の計装設定

SDK の無効化

プロパティ宣言的設定
otel.sdk.disabled=trueotel.disabled: true

SDK の設定

SDK レベルの設定(エクスポーター、プロパゲーター、リソース)は、はじめにの例で示したように、標準の宣言的設定スキーマに従って otel: 直下に配置します。

エージェントの宣言的設定との違い

項目エージェントSpring Boot スターター
設定の場所別ファイル(-Dotel.config.file=...application.yaml
変数の構文${VAR:-default}(コロン2つ)${VAR:default}(コロン1つ、Spring)
プロファイル非対応Spring プロファイルが通常通り動作
有効化/無効化distribution.javaagent.instrumentation.*distribution.spring_starter.instrumentation.*
デフォルト有効distribution.javaagent.instrumentation.default_enableddistribution.spring_starter.instrumentation.default_enabled

環境変数によるオーバーライド

Spring の緩和バインディングにより、宣言的設定の YAML の任意の部分を環境変数でオーバーライドできます。

# instrumentation/development 配下のスカラー値をオーバーライド
OTEL_INSTRUMENTATION/DEVELOPMENT_JAVA_FOO_STRING_KEY=new_value

# インデックス付きリスト要素のオーバーライド(例: エクスポーターのエンドポイント)
OTEL_TRACER_PROVIDER_PROCESSORS_0_BATCH_EXPORTER_OTLP_HTTP_ENDPOINT=http://custom:4318/v1/traces

ルール: 大文字にし、._ に置き換え、/ はそのまま(例: INSTRUMENTATION/DEVELOPMENT)にし、リストのインデックスには _0__1_ を使用します。

これは標準的な Spring の機能であり、application.yaml 内のすべてのキーで動作します。

期間のフォーマット

宣言的設定はミリ秒単位の期間のみをサポートします(例: 5秒の場合は 5000)。 5s のような期間文字列を使用するとエラーになります。

プログラムによる設定

宣言的設定では、AutoConfigurationCustomizerProviderプログラムによる設定を参照)は DeclarativeConfigurationCustomizerProvider に置き換えられます。 スパンエクスポーターなどのコンポーネントは ComponentProvider API を使用します。 詳細と例については、エージェントの Extension API セクションを参照してください。同じ API が Spring Boot スターターにも適用されます。