<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Set up OpenTelemetry Collector for Application Observability on Grafana Labs</title><link>https://grafana.com/docs/opentelemetry/collector/opentelemetry-collector/</link><description>Recent content in Set up OpenTelemetry Collector for Application Observability on Grafana Labs</description><generator>Hugo -- gohugo.io</generator><language>en</language><atom:link href="/docs/opentelemetry/collector/opentelemetry-collector/index.xml" rel="self" type="application/rss+xml"/><item><title>Capture Kubernetes logs with OpenTelemetry Collector</title><link>https://grafana.com/docs/opentelemetry/collector/opentelemetry-collector/kubernetes-logs/</link><pubDate>Mon, 16 Jun 2025 10:29:52 +0000</pubDate><guid>https://grafana.com/docs/opentelemetry/collector/opentelemetry-collector/kubernetes-logs/</guid><content><![CDATA[&lt;h1 id=&#34;capture-kubernetes-logs-with-opentelemetry-collector&#34;&gt;Capture Kubernetes logs with OpenTelemetry Collector&lt;/h1&gt;
&lt;p&gt;Grafana Labs recommends sending OpenTelemetry logs with the OTLP protocol. However, some use cases require outputting logs to files or stdout:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;The OpenTelemetry SDK for Go, Python, Ruby, JavaScript, and PHP does not provide a &lt;a href=&#34;https://opentelemetry.io/docs/specs/otel/versioning-and-stability/&#34; target=&#34;_blank&#34; rel=&#34;noopener noreferrer&#34;&gt;stable&lt;/a&gt; OTLP implementation for logs.&lt;/li&gt;
&lt;li&gt;Organizational constraints, often related to reliability practices, require using files for logs.&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;You can still collect file-based logs with the OpenTelemetry Collector. This guide shows how to capture logs emitted through Kubernetes stdout, and you can apply the same pattern to logs written to files.&lt;/p&gt;
&lt;h2 id=&#34;architecture&#34;&gt;Architecture&lt;/h2&gt;
&lt;p&gt;To correlate traces and metrics with logs, enrich logs with the same resource attributes and trace and span IDs.&lt;/p&gt;
&lt;p&gt;First, add identifying resource attributes to logs, such as &lt;code&gt;service.name&lt;/code&gt;, &lt;code&gt;service.namespace&lt;/code&gt;, &lt;code&gt;service.instance.id&lt;/code&gt;, and &lt;code&gt;deployment.environment&lt;/code&gt;, along with &lt;code&gt;trace_id&lt;/code&gt; and &lt;code&gt;span_id&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;Then, use the same metadata enrichment pipeline in the OpenTelemetry Collector, such as the &lt;a href=&#34;https://github.com/open-telemetry/opentelemetry-collector-contrib/tree/main/processor/k8sattributesprocessor&#34; target=&#34;_blank&#34; rel=&#34;noopener noreferrer&#34;&gt;Kubernetes Attributes Processor&lt;/a&gt; or the &lt;a href=&#34;https://github.com/open-telemetry/opentelemetry-collector-contrib/tree/main/processor/resourcedetectionprocessor&#34; target=&#34;_blank&#34; rel=&#34;noopener noreferrer&#34;&gt;Resource Detection Processor&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;If you already get this enrichment when exporting logs through OTLP, add these attributes to log lines collected from files or stdout.&lt;/p&gt;
&lt;figure
    class=&#34;figure-wrapper figure-wrapper__lightbox w-100p &#34;
    style=&#34;max-width: 1500px;&#34;
    itemprop=&#34;associatedMedia&#34;
    itemscope=&#34;&#34;
    itemtype=&#34;http://schema.org/ImageObject&#34;
  &gt;&lt;a
        class=&#34;lightbox-link captioned&#34;
        href=&#34;/media/docs/grafana-cloud/application-observability/architecture-diagram-k8s-containerized-app-logs-through-stdout-and-otelcol-2.png&#34;
        itemprop=&#34;contentUrl&#34;
      &gt;&lt;div class=&#34;img-wrapper w-100p h-auto&#34;&gt;&lt;img
          class=&#34;lazyload mb-0&#34;
          data-src=&#34;/media/docs/grafana-cloud/application-observability/architecture-diagram-k8s-containerized-app-logs-through-stdout-and-otelcol-2.png&#34;data-srcset=&#34;/media/docs/grafana-cloud/application-observability/architecture-diagram-k8s-containerized-app-logs-through-stdout-and-otelcol-2.png?w=320 320w, /media/docs/grafana-cloud/application-observability/architecture-diagram-k8s-containerized-app-logs-through-stdout-and-otelcol-2.png?w=550 550w, /media/docs/grafana-cloud/application-observability/architecture-diagram-k8s-containerized-app-logs-through-stdout-and-otelcol-2.png?w=750 750w, /media/docs/grafana-cloud/application-observability/architecture-diagram-k8s-containerized-app-logs-through-stdout-and-otelcol-2.png?w=900 900w, /media/docs/grafana-cloud/application-observability/architecture-diagram-k8s-containerized-app-logs-through-stdout-and-otelcol-2.png?w=1040 1040w, /media/docs/grafana-cloud/application-observability/architecture-diagram-k8s-containerized-app-logs-through-stdout-and-otelcol-2.png?w=1240 1240w, /media/docs/grafana-cloud/application-observability/architecture-diagram-k8s-containerized-app-logs-through-stdout-and-otelcol-2.png?w=1920 1920w&#34;data-sizes=&#34;auto&#34;alt=&#34;Kubernetes architecture with containerized application logs emitted through stdout, collected with the OpenTelemetry Collector, and sent to Grafana Cloud&#34;width=&#34;1500&#34;height=&#34;504&#34;title=&#34;This Kubernetes architecture diagram shows containerized application logs emitted through stdout, collected with the OpenTelemetry Collector, and sent to Grafana Cloud.&#34;/&gt;
        &lt;noscript&gt;
          &lt;img
            src=&#34;/media/docs/grafana-cloud/application-observability/architecture-diagram-k8s-containerized-app-logs-through-stdout-and-otelcol-2.png&#34;
            alt=&#34;Kubernetes architecture with containerized application logs emitted through stdout, collected with the OpenTelemetry Collector, and sent to Grafana Cloud&#34;width=&#34;1500&#34;height=&#34;504&#34;title=&#34;This Kubernetes architecture diagram shows containerized application logs emitted through stdout, collected with the OpenTelemetry Collector, and sent to Grafana Cloud.&#34;/&gt;
        &lt;/noscript&gt;&lt;/div&gt;&lt;figcaption class=&#34;w-100p caption text-gray-13  &#34;&gt;This Kubernetes architecture diagram shows containerized application logs emitted through stdout, collected with the OpenTelemetry Collector, and sent to Grafana Cloud.&lt;/figcaption&gt;&lt;/a&gt;&lt;/figure&gt;
&lt;p&gt;To carry over resource attributes in log lines, use one of the following export patterns.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Export unstructured logs:&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;Export unstructured logs and parse them with regular expressions, for example:&lt;/p&gt;

&lt;div class=&#34;code-snippet code-snippet__mini&#34;&gt;&lt;div class=&#34;lang-toolbar__mini&#34;&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet code-snippet__border&#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-none&#34;&gt;2024-09-17T11:29:54  INFO [nio-8080-exec-1] c.e.OrderController  : Order completed - service.name=order-processor, service.instance.id=i-123456, span_id=1d5f8ca3f9366fac...&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;&lt;strong&gt;Export structured logs:&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;Export structured format logs like JSON logs and parse them with native parsers of the chosen format, for example:&lt;/p&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;JSON&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-json&#34;&gt;{&amp;#34;timestamp&amp;#34;: &amp;#34;2024-09-17T11:29:54&amp;#34;, &amp;#34;level&amp;#34;: &amp;#34;INFO&amp;#34;, &amp;#34;body&amp;#34;:&amp;#34;Order completed&amp;#34;, &amp;#34;logger&amp;#34;: &amp;#34;c.e.OrderController&amp;#34;, &amp;#34;service_name&amp;#34;: &amp;#34;order-processor&amp;#34;, &amp;#34;service_instance_id&amp;#34;: &amp;#34;i-123456&amp;#34;, &amp;#34;span_id&amp;#34;:&amp;#34;1d5f8ca3f9366fac&amp;#34;...}&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;Both export patterns have advantages and disadvantages:&lt;/p&gt;
&lt;section class=&#34;expand-table-wrapper&#34;&gt;&lt;div class=&#34;button-div&#34;&gt;
      &lt;button class=&#34;expand-table-btn&#34;&gt;Expand table&lt;/button&gt;
    &lt;/div&gt;&lt;div class=&#34;responsive-table-wrapper&#34;&gt;
    &lt;table&gt;
      &lt;thead&gt;
          &lt;tr&gt;
              &lt;th&gt;&lt;/th&gt;
              &lt;th&gt;JSON logs&lt;/th&gt;
              &lt;th&gt;Unstructured logs&lt;/th&gt;
          &lt;/tr&gt;
      &lt;/thead&gt;
      &lt;tbody&gt;
          &lt;tr&gt;
              &lt;td&gt;&lt;strong&gt;Correlation&lt;/strong&gt;&lt;/td&gt;
              &lt;td&gt;&#43;&#43;&#43;&lt;/td&gt;
              &lt;td&gt;&#43;&#43;&#43;&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;&lt;strong&gt;Human Readability&lt;/strong&gt;&lt;/td&gt;
              &lt;td&gt;The verbosity of JSON can seriously erode readability&lt;/td&gt;
              &lt;td&gt;Contextualization attributes can be appended at the end of the log line preserving readability&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;&lt;strong&gt;Reliability of the parsing&lt;/strong&gt;&lt;/td&gt;
              &lt;td&gt;It&amp;rsquo;s simple to define robust JSON parsing rules&lt;/td&gt;
              &lt;td&gt;Parsing unstructured text with regular expressions is fragile, particularly due to multi-line log messages like stack traces, to the point where it requires monitoring parsing failures&lt;/td&gt;
          &lt;/tr&gt;
      &lt;/tbody&gt;
    &lt;/table&gt;
  &lt;/div&gt;
&lt;/section&gt;]]></content><description>&lt;h1 id="capture-kubernetes-logs-with-opentelemetry-collector">Capture Kubernetes logs with OpenTelemetry Collector&lt;/h1>
&lt;p>Grafana Labs recommends sending OpenTelemetry logs with the OTLP protocol. However, some use cases require outputting logs to files or stdout:&lt;/p></description></item><item><title>Emit contextualized JSON logs with Java</title><link>https://grafana.com/docs/opentelemetry/collector/opentelemetry-collector/java-json-logs/</link><pubDate>Mon, 16 Jun 2025 10:29:52 +0000</pubDate><guid>https://grafana.com/docs/opentelemetry/collector/opentelemetry-collector/java-json-logs/</guid><content><![CDATA[&lt;h1 id=&#34;emit-contextualized-json-logs-with-java&#34;&gt;Emit contextualized JSON logs with Java&lt;/h1&gt;
&lt;p&gt;Most popular logging frameworks, such as &lt;a href=&#34;https://logging.apache.org/log4j/2.x/index.html&#34; target=&#34;_blank&#34; rel=&#34;noopener noreferrer&#34;&gt;Log4j&lt;/a&gt; or &lt;a href=&#34;https://logback.qos.ch/&#34; target=&#34;_blank&#34; rel=&#34;noopener noreferrer&#34;&gt;SLF4J/Logback&lt;/a&gt; in Java, support emitting JSON formatted logs.&lt;/p&gt;
&lt;p&gt;To integrate OpenTelemetry with logging libraries, specify the resource attributes you want available in the log line.&lt;/p&gt;
&lt;p&gt;To keep your architecture simple, add only the attributes you need to filter and correlate logs, such as &lt;code&gt;service.name&lt;/code&gt;, &lt;code&gt;service.namespace&lt;/code&gt;, &lt;code&gt;deployment.environment&lt;/code&gt;, and &lt;code&gt;service.instance.id&lt;/code&gt;.&lt;/p&gt;
&lt;h2 id=&#34;example-application&#34;&gt;Example application&lt;/h2&gt;
&lt;p&gt;The following example uses &lt;a href=&#34;https://spring.io/projects/spring-boot&#34; target=&#34;_blank&#34; rel=&#34;noopener noreferrer&#34;&gt;Spring Boot&lt;/a&gt; to enrich logs with OpenTelemetry attributes and emit them formatted in JSON through stdout.&lt;/p&gt;


&lt;div class=&#34;admonition admonition-note&#34;&gt;&lt;blockquote&gt;&lt;p class=&#34;title text-uppercase&#34;&gt;Note&lt;/p&gt;&lt;p&gt;You can find the full code of the example in the
&lt;a href=&#34;https://github.com/grafana/docker-otel-lgtm/tree/main/examples/java/json-logging-logback&#34; target=&#34;_blank&#34; rel=&#34;noopener noreferrer&#34;&gt;Docker LGTM repository&lt;/a&gt;.&lt;/p&gt;&lt;/blockquote&gt;&lt;/div&gt;

&lt;p&gt;Create a Spring Boot application 3.3.0&#43; using the default logging instrumentation with the Logback library and the stdout output.&lt;/p&gt;
&lt;h3 id=&#34;instrument-the-application&#34;&gt;Instrument the application&lt;/h3&gt;
&lt;p&gt;Instrument the Spring Boot application with the OpenTelemetry Java Agent by following the setup flow defined by the Grafana Cloud integration for Java:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Open the Grafana Cloud home page in a web browser.&lt;/li&gt;
&lt;li&gt;Navigate to &lt;strong&gt;Connections &amp;gt; Add new Connection&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;Select &lt;strong&gt;Java OpenTelemetry&lt;/strong&gt; and follow the setup instructions.&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;Enrich Logback logs with OpenTelemetry resource attributes and log attributes using:&lt;/p&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;shell&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-shell&#34;&gt;export OTEL_INSTRUMENTATION_COMMON_MDC_RESOURCE_ATTRIBUTES=service.namespace,service.name,service.instance.id,service.version,deployment.environment&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;Change the Logback SpringBoot configuration to emit JSON logs with OpenTelemetry contextualization and add the following &lt;code&gt;logback-spring.xml&lt;/code&gt; under &lt;code&gt;src/main/resources&lt;/code&gt;:&lt;/p&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;xml&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-xml&#34;&gt;&amp;lt;!-- tested with Logback 1.5.0 and Spring Boot 3.3.0 --&amp;gt;
&amp;lt;configuration&amp;gt;
    &amp;lt;include resource=&amp;#34;org/springframework/boot/logging/logback/defaults.xml&amp;#34;/&amp;gt;
    &amp;lt;include resource=&amp;#34;org/springframework/boot/logging/logback/console-appender.xml&amp;#34;/&amp;gt;

    &amp;lt;root level=&amp;#34;INFO&amp;#34;&amp;gt;
        &amp;lt;appender-ref ref=&amp;#34;CONSOLE_JSON&amp;#34;/&amp;gt;
    &amp;lt;/root&amp;gt;

    &amp;lt;appender name=&amp;#34;CONSOLE_JSON&amp;#34; class=&amp;#34;ch.qos.logback.core.ConsoleAppender&amp;#34;&amp;gt;
        &amp;lt;encoder class=&amp;#34;ch.qos.logback.classic.encoder.JsonEncoder&amp;#34;&amp;gt;
            &amp;lt;withFormattedMessage&amp;gt;true&amp;lt;/withFormattedMessage&amp;gt;
            &amp;lt;withMessage&amp;gt;false&amp;lt;/withMessage&amp;gt;
            &amp;lt;withArguments&amp;gt;false&amp;lt;/withArguments&amp;gt;
            &amp;lt;withSequenceNumber&amp;gt;false&amp;lt;/withSequenceNumber&amp;gt;
            &amp;lt;withNanoseconds&amp;gt;false&amp;lt;/withNanoseconds&amp;gt;
        &amp;lt;/encoder&amp;gt;
    &amp;lt;/appender&amp;gt;
&amp;lt;/configuration&amp;gt;&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;h3 id=&#34;deploy-the-application&#34;&gt;Deploy the application&lt;/h3&gt;
&lt;p&gt;Deploy the Spring Boot application on Kubernetes and verify that the application outputs logs to the container stdout stream with JSON formatting and OpenTelemetry contextualization, for example &lt;code&gt;kubectl logs my_pod_name | jq&lt;/code&gt; outputs:&lt;/p&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;JSON&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-json&#34;&gt;{
  &amp;#34;timestamp&amp;#34;: 1727346005788,
  &amp;#34;level&amp;#34;: &amp;#34;INFO&amp;#34;,
  &amp;#34;threadName&amp;#34;: &amp;#34;http-nio-8080-exec-5&amp;#34;,
  &amp;#34;loggerName&amp;#34;: &amp;#34;com.grafana.example.RollController&amp;#34;,
  &amp;#34;context&amp;#34;: {
    &amp;#34;name&amp;#34;: &amp;#34;default&amp;#34;,
    &amp;#34;birthdate&amp;#34;: 1727345887787,
    &amp;#34;properties&amp;#34;: {
    }
  },
  &amp;#34;mdc&amp;#34;: {
    &amp;#34;trace_id&amp;#34;: &amp;#34;97a39974ba2dfc9275e4d31dc2730ee4&amp;#34;,
    &amp;#34;trace_flags&amp;#34;: &amp;#34;01&amp;#34;,
    &amp;#34;service.name&amp;#34;: &amp;#34;dice&amp;#34;,
    &amp;#34;service.instance.id&amp;#34;: &amp;#34;0fb18318-06c0-4893-9a8b-353c00b45227&amp;#34;,
    &amp;#34;service.version&amp;#34;: &amp;#34;1.1&amp;#34;,
    &amp;#34;span_id&amp;#34;: &amp;#34;08d6d83d645e3ad2&amp;#34;,
    &amp;#34;service.namespace&amp;#34;: &amp;#34;shop&amp;#34;,
    &amp;#34;deployment.environment&amp;#34;: &amp;#34;staging&amp;#34;
  },
  &amp;#34;formattedMessage&amp;#34;: &amp;#34;Anonymous player is rolling the dice: 6&amp;#34;,
  &amp;#34;throwable&amp;#34;: null
}&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;h3 id=&#34;configure-opentelemetry-collector&#34;&gt;Configure OpenTelemetry Collector&lt;/h3&gt;
&lt;p&gt;Configure the OpenTelemetry Collector instance with the file log receiver:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Add a &lt;a href=&#34;https://github.com/open-telemetry/opentelemetry-collector-contrib/tree/main/receiver/filelogreceiver&#34; target=&#34;_blank&#34; rel=&#34;noopener noreferrer&#34;&gt;file log receiver&lt;/a&gt;.&lt;/li&gt;
&lt;li&gt;Add the &lt;a href=&#34;https://github.com/open-telemetry/opentelemetry-collector-contrib/blob/main/pkg/stanza/docs/operators/container.md&#34; target=&#34;_blank&#34; rel=&#34;noopener noreferrer&#34;&gt;container parser&lt;/a&gt; operator.&lt;/li&gt;
&lt;li&gt;Add the &lt;a href=&#34;https://github.com/open-telemetry/opentelemetry-collector-contrib/blob/main/pkg/stanza/docs/operators/json_parser.md&#34; target=&#34;_blank&#34; rel=&#34;noopener noreferrer&#34;&gt;json parser&lt;/a&gt; operator.
&lt;ul&gt;
&lt;li&gt;Map &lt;code&gt;body&lt;/code&gt; to &lt;code&gt;attributes.formattedMessage&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;Map &lt;code&gt;timestamp.parse_from&lt;/code&gt; to &lt;code&gt;attributes.timestamp&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;Map &lt;code&gt;severity.parse_from&lt;/code&gt; to &lt;code&gt;attributes.level&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;Map &lt;code&gt;trace.trace_id.parse_from&lt;/code&gt; to &lt;code&gt;attributes.mdc.trace_id&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;Map &lt;code&gt;trace.span_id.parse_from&lt;/code&gt; to &lt;code&gt;attributes.mdc.span_id&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;Map &lt;code&gt;trace.trace_flags.parse_from&lt;/code&gt; to &lt;code&gt;attributes.mdc.trace_flags&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;Add the &lt;a href=&#34;https://github.com/open-telemetry/opentelemetry-collector-contrib/blob/main/pkg/stanza/docs/operators/move.md&#34; target=&#34;_blank&#34; rel=&#34;noopener noreferrer&#34;&gt;move&lt;/a&gt; operator.
&lt;ul&gt;
&lt;li&gt;Move top level fields, such as &lt;code&gt;threadName&lt;/code&gt;, to their corresponding OTel attributes, such as &lt;a href=&#34;https://opentelemetry.io/docs/specs/semconv/attributes-registry/thread/&#34; target=&#34;_blank&#34; rel=&#34;noopener noreferrer&#34;&gt;&lt;code&gt;thread.name&lt;/code&gt;&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;Move entries from the &lt;code&gt;mdc&lt;/code&gt; field to the resource entry of the log entry&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;Remove all unnecessary fields using the &lt;a href=&#34;https://github.com/open-telemetry/opentelemetry-collector-contrib/blob/main/pkg/stanza/docs/operators/remove.md&#34; target=&#34;_blank&#34; rel=&#34;noopener noreferrer&#34;&gt;attributes&lt;/a&gt; operator.&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;You can find the full configuration in the &lt;a href=&#34;https://github.com/grafana/docker-otel-lgtm/blob/main/examples/java/json-logging-logback/k8s/collector-configmap.yaml&#34; target=&#34;_blank&#34; rel=&#34;noopener noreferrer&#34;&gt;reference OTel collector configuration&lt;/a&gt;.&lt;/p&gt;
]]></content><description>&lt;h1 id="emit-contextualized-json-logs-with-java">Emit contextualized JSON logs with Java&lt;/h1>
&lt;p>Most popular logging frameworks, such as &lt;a href="https://logging.apache.org/log4j/2.x/index.html" target="_blank" rel="noopener noreferrer">Log4j&lt;/a> or &lt;a href="https://logback.qos.ch/" target="_blank" rel="noopener noreferrer">SLF4J/Logback&lt;/a> in Java, support emitting JSON formatted logs.&lt;/p>
&lt;p>To integrate OpenTelemetry with logging libraries, specify the resource attributes you want available in the log line.&lt;/p></description></item></channel></rss>