Docs » Splunk Observability Cloud でサポートされているインテグレーション » バックエンドアプリケーションをインストルメンテーションして、スパンを Splunk APM に送信する » Splunk Observability Cloud 用 Java アプリケーションのインストルメンテーション » Splunk Observability Cloud のログと Java トレースデータを接続する

Splunk Observability Cloud のログと Java トレースデータを接続する 🔗

The agent from the Splunk Distribution of OpenTelemetry Java automtically annotates application logs with trace ID, span ID, and flags. The agent then sends the logs to Splunk Observability Cloud through the OpenTelemetry Collector.

If needed, you can configure your Java logging library to produce logs that include additional attributes provided automatically by the Splunk OTel Java agent, like the version of your service or the deployment environment.

注釈

Logs export to Splunk Observability Cloud requires the Splunk Distribution of OpenTelemetry Collector.

互換性と必要条件をチェック 🔗

Splunk OTel Java エージェントは以下のロギングライブラリをサポートしています:

  • Log4j 2 2.7 以上

  • Log4j 1 1.2 以上

  • Logback 1.0 以上

  • JBoss LogManager 1.1.0 and higher

The java.util.logging library is fully supported in all JDK versions that are compatible with the Splunk Distribution of OpenTelemetry Java. See Javaエージェントの互換性と要件.

ログ文のトレースメタデータ 🔗

The Splunk OTel Java agent automatically add the following attributes for logging libraries by default:

  • トレース情報: trace_idspan_id

  • トレースフラグ

The Collector sends the annotated logs through the OTLP exporter.

Deactivate logs export 🔗

To turn off logs export to Splunk Observability Cloud, set the OTEL_LOGS_EXPORTER environment variable or the otel.logs.exporter system property to none.

Inject resource attributes 🔗

While the Java agent automatically generates and sends logs to Splunk through the Collector, you can still produce annotated logs using a compatible log library, so that logs can be collected manually or go through the Universal Forwarder. See Splunk Log Observer Connectの概要.

For example, you can inject resource attributes in your log statements, such as service.name and deployment.environment. This requires defining the attributes you want to inject and configuring your logger manually.

Define the resource attributes 🔗

Before injecting attributes, you must make them available through the Mapped Diagnostic Context (MDC) by setting the mdc.resource-attributes property at runtime. For example:

-Dotel.instrumentation.common.mdc.resource-attributes=service.name,environment

Configure your logging library 🔗

The Splunk Distribution of OpenTelemetry Java exposes resource attributes as context properties, which you can use to configure logger libraries.

The following examples show how to include additional metadata in log statements produced by the logging library:

Log4jのコンフィギュレーションを編集します。例えば、src/main/resources/log4j2.xml 。使用環境によっては、別のファイルを編集するか、別の構成システムを使わなければならない可能性があります。

<?xml version="1.0" encoding="UTF-8"?>
<Configuration status="WARN">
   <Appenders>
      <Console name="STDOUT" target="SYSTEM_OUT">
         <JsonLayout compact="true" eventEol="true">
            <KeyValuePair key="trace_id" value="${ctx:trace_id}"/>
            <KeyValuePair key="span_id" value="${ctx:span_id}"/>
            <KeyValuePair key="service.name" value="${ctx:service.name}"/>
            <KeyValuePair key="environment" value="${ctx:environment}"/>
            <KeyValuePair key="trace_sampled" value="${ctx:trace_flags}"/>
         </JsonLayout>
      </Console>
   </Appenders>
   <!-- More configuration -->
</Configuration>

Spring Bootアプリケーションでは、application.properties ファイルを編集して、以下のロギングパターンを追加することもできます:

logging.pattern.console = %d{yyyy-MM-dd HH:mm:ss} - %logger{36} - %msg trace_id=%X{trace_id} span_id=%X{span_id} service=%X{service.name}, env=%X{environment} trace_flags=%X{trace_flags} %n

If you’re instrumenting a serverless service or application, use environment variables instead. The deployment environment requires that you set an arbitrary environment variable, for example OTEL_ENV_NAME.

<PatternLayout>
   <pattern>
      service.name=${OTEL_SERVICE_NAME}, deployment.environment=${OTEL_ENV_NAME} %m%n
   </pattern>
</PatternLayout>

This page was last updated on 2024年06月25日.