Class OpenTelemetryAppender

java.lang.Object
ch.qos.logback.core.spi.ContextAwareBase
ch.qos.logback.core.UnsynchronizedAppenderBase<ch.qos.logback.classic.spi.ILoggingEvent>
io.opentelemetry.instrumentation.logback.appender.v1_0.OpenTelemetryAppender
All Implemented Interfaces:
ch.qos.logback.core.Appender<ch.qos.logback.classic.spi.ILoggingEvent>, ch.qos.logback.core.spi.ContextAware, ch.qos.logback.core.spi.FilterAttachable<ch.qos.logback.classic.spi.ILoggingEvent>, ch.qos.logback.core.spi.LifeCycle

public class OpenTelemetryAppender extends ch.qos.logback.core.UnsynchronizedAppenderBase<ch.qos.logback.classic.spi.ILoggingEvent>
  • Constructor Details

    • OpenTelemetryAppender

      public OpenTelemetryAppender()
  • Method Details

    • install

      public static void install(io.opentelemetry.api.OpenTelemetry openTelemetry)
      Installs the openTelemetry instance on any OpenTelemetryAppenders identified in the LoggerContext.
    • start

      public void start()
      Specified by:
      start in interface ch.qos.logback.core.spi.LifeCycle
      Overrides:
      start in class ch.qos.logback.core.UnsynchronizedAppenderBase<ch.qos.logback.classic.spi.ILoggingEvent>
    • append

      protected void append(ch.qos.logback.classic.spi.ILoggingEvent event)
      Specified by:
      append in class ch.qos.logback.core.UnsynchronizedAppenderBase<ch.qos.logback.classic.spi.ILoggingEvent>
    • setCaptureExperimentalAttributes

      public void setCaptureExperimentalAttributes(boolean captureExperimentalAttributes)
      Sets whether experimental attributes should be set to logs. These attributes may be changed or removed in the future, so only enable this if you know you do not require attributes filled by this instrumentation to be stable across versions.
    • setCaptureCodeAttributes

      public void setCaptureCodeAttributes(boolean captureCodeAttributes)
      Sets whether the code attributes (file name, class name, method name and line number) should be set to logs. Enabling these attributes can potentially impact performance (see https://logback.qos.ch/manual/layouts.html).
      Parameters:
      captureCodeAttributes - To enable or disable the code attributes (file name, class name, method name and line number)
    • setCaptureMarkerAttribute

      public void setCaptureMarkerAttribute(boolean captureMarkerAttribute)
      Sets whether the marker attribute should be set to logs.
      Parameters:
      captureMarkerAttribute - To enable or disable capturing the marker attribute
    • setCaptureKeyValuePairAttributes

      @Deprecated public void setCaptureKeyValuePairAttributes(boolean captureKeyValuePairAttributes)
      Deprecated.
      Use setKeyValuePairAttributesIncluded(String) and setKeyValuePairAttributesExcluded(String), or setKeyValuePairAttributes(IncludeExclude), which select key value pair keys by glob pattern. May be removed in the next minor release.
      Sets whether the key value pair attributes should be set to logs.

      This setter backs the captureKeyValuePairAttributes element in logback.xml.

      Parameters:
      captureKeyValuePairAttributes - To enable or disable capturing key value pairs
    • setKeyValuePairAttributes

      public void setKeyValuePairAttributes(@Nullable io.opentelemetry.instrumentation.api.config.IncludeExclude keyValuePairAttributes)
      Configures the key value pair attributes that will be copied to logs.

      Key value pair keys and selector patterns are matched case-sensitively. ? matches any single character and * matches any number of characters, including none, so * captures all key value pair attributes. Excluded patterns take precedence over included patterns, so a selector with only excluded patterns captures every key value pair attribute that it does not exclude.

      A null or empty selector leaves this appender without a programmatic selector, in which case the key value pair attributes are selected by setKeyValuePairAttributesIncluded(String) and setKeyValuePairAttributesExcluded(String). When these are also absent or empty, the deprecated setCaptureKeyValuePairAttributes(boolean) setting controls whether all key value pair attributes are captured. Only a non-empty selector configured with this method takes precedence over the other settings.

      Captured key value pair attributes may contain sensitive information. Configure included and excluded patterns to limit the data exported as log attributes.

    • setKeyValuePairAttributesIncluded

      public void setKeyValuePairAttributesIncluded(@Nullable String keyValuePairAttributesIncluded)
      Configures the comma-separated key value pair key patterns that will be copied to logs.

      This setter backs the keyValuePairAttributesIncluded element in logback.xml. It is ignored when a non-empty selector is configured with setKeyValuePairAttributes(IncludeExclude), and it takes precedence over the deprecated setCaptureKeyValuePairAttributes(boolean).

      Key value pair keys and patterns are matched case-sensitively. ? matches any single character and * matches any number of characters, including none, so * captures all key value pair attributes. Excluded patterns take precedence over included patterns.

    • setKeyValuePairAttributesExcluded

      public void setKeyValuePairAttributesExcluded(@Nullable String keyValuePairAttributesExcluded)
      Configures the comma-separated key value pair key patterns that will not be copied to logs.

      This setter backs the keyValuePairAttributesExcluded element in logback.xml. It is ignored when a non-empty selector is configured with setKeyValuePairAttributes(IncludeExclude), and it takes precedence over the deprecated setCaptureKeyValuePairAttributes(boolean).

      Key value pair keys and patterns are matched case-sensitively. ? matches any single character and * matches any number of characters, including none. Excluded patterns take precedence over included patterns, so configuring only excluded patterns captures every key value pair attribute that they do not exclude.

    • setCaptureLoggerContext

      @Deprecated public void setCaptureLoggerContext(boolean captureLoggerContext)
      Deprecated.
      Use setLoggerContextAttributesIncluded(String) and setLoggerContextAttributesExcluded(String), or setLoggerContextAttributes(IncludeExclude), which select logger context property keys by glob pattern. May be removed in the next minor release.
      Sets whether the logger context properties should be set to logs.
      Parameters:
      captureLoggerContext - To enable or disable capturing logger context properties
    • setLoggerContextAttributes

      public void setLoggerContextAttributes(@Nullable io.opentelemetry.instrumentation.api.config.IncludeExclude loggerContextAttributes)
      Configures the logger context properties that will be copied to logs.

      Logger context property keys and selector patterns are matched case-sensitively. ? matches any single character and * matches any number of characters, including none, so * captures all logger context properties. Excluded patterns take precedence over included patterns, so a selector with only excluded patterns captures every logger context property that it does not exclude.

      A null or empty selector leaves this appender without a programmatic selector, in which case the logger context properties are selected by setLoggerContextAttributesIncluded(String) and setLoggerContextAttributesExcluded(String), and then by the deprecated setCaptureLoggerContext(boolean). No logger context properties are captured when all of these are absent or empty.

      Captured logger context properties may contain sensitive information. Configure included and excluded patterns to limit the data exported as log attributes.

    • setLoggerContextAttributesIncluded

      public void setLoggerContextAttributesIncluded(@Nullable String loggerContextAttributesIncluded)
      Configures the comma-separated logger context property key patterns that will be copied to logs.

      This setter backs the loggerContextAttributesIncluded element in logback.xml. It is ignored when a non-empty selector is configured with setLoggerContextAttributes(IncludeExclude), and it takes precedence over the deprecated setCaptureLoggerContext(boolean).

      Logger context property keys and patterns are matched case-sensitively. ? matches any single character and * matches any number of characters, including none, so * captures all logger context properties. Excluded patterns take precedence over included patterns.

    • setLoggerContextAttributesExcluded

      public void setLoggerContextAttributesExcluded(@Nullable String loggerContextAttributesExcluded)
      Configures the comma-separated logger context property key patterns that will not be copied to logs.

      This setter backs the loggerContextAttributesExcluded element in logback.xml. It is ignored when a non-empty selector is configured with setLoggerContextAttributes(IncludeExclude), and it takes precedence over the deprecated setCaptureLoggerContext(boolean).

      Logger context property keys and patterns are matched case-sensitively. ? matches any single character and * matches any number of characters, including none. Excluded patterns take precedence over included patterns, so configuring only excluded patterns captures every logger context property that they do not exclude.

    • setCaptureTemplate

      public void setCaptureTemplate(boolean captureTemplate)
      Sets whether the message template should be captured in logs if arguments are provided.
      Parameters:
      captureTemplate - whether the message template should be captured in logs if arguments are provided
    • setCaptureArguments

      public void setCaptureArguments(boolean captureArguments)
      Sets whether the arguments should be set to logs.
      Parameters:
      captureArguments - To enable or disable capturing logger arguments
    • setCaptureLogstashMarkerAttributes

      @Deprecated public void setCaptureLogstashMarkerAttributes(boolean captureLogstashMarkerAttributes)
      Deprecated.
      Use setLogstashMarkerAttributesIncluded(String) and setLogstashMarkerAttributesExcluded(String), or setLogstashMarkerAttributes(IncludeExclude), which select Logstash marker keys by glob pattern. May be removed in the next minor release.
      Sets whether the Logstash marker attributes should be captured.
      Parameters:
      captureLogstashMarkerAttributes - To enable or disable capturing Logstash marker attributes
    • setLogstashMarkerAttributes

      public void setLogstashMarkerAttributes(@Nullable io.opentelemetry.instrumentation.api.config.IncludeExclude logstashMarkerAttributes)
      Configures the Logstash marker attributes that will be copied to logs.

      Logstash marker keys and selector patterns are matched case-sensitively. ? matches any single character and * matches any number of characters, including none, so * captures all Logstash marker attributes. Excluded patterns take precedence over included patterns, so a selector with only excluded patterns captures every Logstash marker attribute that it does not exclude.

      A null or empty selector leaves this appender without a programmatic selector, in which case the Logstash marker attributes are selected by setLogstashMarkerAttributesIncluded(String) and setLogstashMarkerAttributesExcluded(String), and then by the deprecated setCaptureLogstashMarkerAttributes(boolean). No Logstash marker attributes are captured when all of these are absent or empty.

      Captured Logstash marker attributes may contain sensitive information. Configure included and excluded patterns to limit the data exported as log attributes.

    • setLogstashMarkerAttributesIncluded

      public void setLogstashMarkerAttributesIncluded(@Nullable String logstashMarkerAttributesIncluded)
      Configures the comma-separated Logstash marker key patterns that will be copied to logs.

      This setter backs the logstashMarkerAttributesIncluded element in logback.xml. It is ignored when a non-empty selector is configured with setLogstashMarkerAttributes(IncludeExclude), and it takes precedence over the deprecated setCaptureLogstashMarkerAttributes(boolean).

      Logstash marker keys and patterns are matched case-sensitively. ? matches any single character and * matches any number of characters, including none, so * captures all Logstash marker attributes. Excluded patterns take precedence over included patterns.

    • setLogstashMarkerAttributesExcluded

      public void setLogstashMarkerAttributesExcluded(@Nullable String logstashMarkerAttributesExcluded)
      Configures the comma-separated Logstash marker key patterns that will not be copied to logs.

      This setter backs the logstashMarkerAttributesExcluded element in logback.xml. It is ignored when a non-empty selector is configured with setLogstashMarkerAttributes(IncludeExclude), and it takes precedence over the deprecated setCaptureLogstashMarkerAttributes(boolean).

      Logstash marker keys and patterns are matched case-sensitively. ? matches any single character and * matches any number of characters, including none. Excluded patterns take precedence over included patterns, so configuring only excluded patterns captures every Logstash marker attribute that they do not exclude.

    • setCaptureLogstashStructuredArguments

      @Deprecated public void setCaptureLogstashStructuredArguments(boolean captureLogstashStructuredArguments)
      Deprecated.
      Use setLogstashStructuredArgumentAttributesIncluded(String) and setLogstashStructuredArgumentAttributesExcluded(String), or setLogstashStructuredArgumentAttributes(IncludeExclude), which select Logstash structured argument keys by glob pattern. May be removed in the next minor release.
      Sets whether the Logstash StructuredArguments should be captured.
    • setLogstashStructuredArgumentAttributes

      public void setLogstashStructuredArgumentAttributes(@Nullable io.opentelemetry.instrumentation.api.config.IncludeExclude logstashStructuredArgumentAttributes)
      Configures the Logstash structured argument attributes that will be copied to logs.

      Logstash structured argument keys and selector patterns are matched case-sensitively. ? matches any single character and * matches any number of characters, including none, so * captures all Logstash structured argument attributes. Excluded patterns take precedence over included patterns, so a selector with only excluded patterns captures every Logstash structured argument attribute that it does not exclude.

      A null or empty selector leaves this appender without a programmatic selector, in which case the Logstash structured argument attributes are selected by setLogstashStructuredArgumentAttributesIncluded(String) and setLogstashStructuredArgumentAttributesExcluded(String), and then by the deprecated setCaptureLogstashStructuredArguments(boolean). No Logstash structured argument attributes are captured when all of these are absent or empty.

      Captured Logstash structured argument attributes may contain sensitive information. Configure included and excluded patterns to limit the data exported as log attributes.

    • setLogstashStructuredArgumentAttributesIncluded

      public void setLogstashStructuredArgumentAttributesIncluded(@Nullable String logstashStructuredArgumentAttributesIncluded)
      Configures the comma-separated Logstash structured argument key patterns that will be copied to logs.

      This setter backs the logstashStructuredArgumentAttributesIncluded element in logback.xml. It is ignored when a non-empty selector is configured with setLogstashStructuredArgumentAttributes(IncludeExclude), and it takes precedence over the deprecated setCaptureLogstashStructuredArguments(boolean).

      Logstash structured argument keys and patterns are matched case-sensitively. ? matches any single character and * matches any number of characters, including none, so * captures all Logstash structured argument attributes. Excluded patterns take precedence over included patterns.

    • setLogstashStructuredArgumentAttributesExcluded

      public void setLogstashStructuredArgumentAttributesExcluded(@Nullable String logstashStructuredArgumentAttributesExcluded)
      Configures the comma-separated Logstash structured argument key patterns that will not be copied to logs.

      This setter backs the logstashStructuredArgumentAttributesExcluded element in logback.xml. It is ignored when a non-empty selector is configured with setLogstashStructuredArgumentAttributes(IncludeExclude), and it takes precedence over the deprecated setCaptureLogstashStructuredArguments(boolean).

      Logstash structured argument keys and patterns are matched case-sensitively. ? matches any single character and * matches any number of characters, including none. Excluded patterns take precedence over included patterns, so configuring only excluded patterns captures every Logstash structured argument attribute that they do not exclude.

    • setMdcAttributes

      public void setMdcAttributes(@Nullable io.opentelemetry.instrumentation.api.config.IncludeExclude mdcAttributes)
      Configures the MDC attributes that will be copied to logs.

      MDC keys and selector patterns are matched case-sensitively. ? matches any single character and * matches any number of characters, including none, so * captures all MDC attributes. Excluded patterns take precedence over included patterns, so a selector with only excluded patterns captures every MDC attribute that it does not exclude.

      A null or empty selector leaves this appender without a programmatic selector, in which case the MDC attributes are selected by setMdcAttributesIncluded(String) and setMdcAttributesExcluded(String), or, when those are absent or empty too, by the deprecated setCaptureMdcAttributes(String). No MDC attributes are captured when all of these are absent or empty. Only a non-empty selector configured with this method takes precedence over the other settings.

      Captured MDC attributes may contain sensitive information. Configure included and excluded patterns to limit the data exported as log attributes.

    • setMdcAttributesIncluded

      public void setMdcAttributesIncluded(@Nullable String mdcAttributesIncluded)
      Configures the comma-separated MDC key patterns that will be copied to logs.

      This setter backs the mdcAttributesIncluded element in logback.xml. It is ignored when a non-empty selector is configured with setMdcAttributes(IncludeExclude), and it takes precedence over the deprecated setCaptureMdcAttributes(String).

      MDC keys and patterns are matched case-sensitively. ? matches any single character and * matches any number of characters, including none, so * captures all MDC attributes. Excluded patterns take precedence over included patterns.

    • setMdcAttributesExcluded

      public void setMdcAttributesExcluded(@Nullable String mdcAttributesExcluded)
      Configures the comma-separated MDC key patterns that will not be copied to logs.

      This setter backs the mdcAttributesExcluded element in logback.xml. It is ignored when a non-empty selector is configured with setMdcAttributes(IncludeExclude), and it takes precedence over the deprecated setCaptureMdcAttributes(String).

      MDC keys and patterns are matched case-sensitively. ? matches any single character and * matches any number of characters, including none. Excluded patterns take precedence over included patterns, so configuring only excluded patterns captures every MDC attribute that they do not exclude.

    • setCaptureMdcAttributes

      @Deprecated public void setCaptureMdcAttributes(@Nullable String captureMdcAttributes)
      Deprecated.
      Use setMdcAttributesIncluded(String) and setMdcAttributesExcluded(String), or setMdcAttributes(IncludeExclude), which select MDC keys by glob pattern. May be removed in the next minor release.
      Configures the comma-separated MDC keys that will be copied to logs.

      Keys are matched by exact, case-sensitive equality, except that the single value * captures all MDC attributes. This setting is ignored when a non-empty selector is configured with setMdcAttributes(IncludeExclude), setMdcAttributesIncluded(String) or setMdcAttributesExcluded(String).

    • setNumLogsCapturedBeforeOtelInstall

      public void setNumLogsCapturedBeforeOtelInstall(int size)
      Log telemetry is emitted after the initialization of the OpenTelemetry Logback appender with an OpenTelemetry object. This setting allows you to modify the size of the cache used to replay the first logs.
    • setOpenTelemetry

      public void setOpenTelemetry(io.opentelemetry.api.OpenTelemetry openTelemetry)
      Configures the OpenTelemetry used to append logs. This MUST be called for the appender to function. See install(OpenTelemetry) for simple installation option.