Class OpenTelemetryAppender.Builder<B extends OpenTelemetryAppender.Builder<B>>

java.lang.Object
org.apache.logging.log4j.core.filter.AbstractFilterable.Builder<B>
org.apache.logging.log4j.core.appender.AbstractAppender.Builder<B>
io.opentelemetry.instrumentation.log4j.appender.v2_17.OpenTelemetryAppender.Builder<B>
All Implemented Interfaces:
org.apache.logging.log4j.core.util.Builder<OpenTelemetryAppender>
Enclosing class:
OpenTelemetryAppender

public static class OpenTelemetryAppender.Builder<B extends OpenTelemetryAppender.Builder<B>> extends org.apache.logging.log4j.core.appender.AbstractAppender.Builder<B> implements org.apache.logging.log4j.core.util.Builder<OpenTelemetryAppender>
  • Constructor Details

    • Builder

      public Builder()
  • Method Details

    • setCaptureExperimentalAttributes

      @CanIgnoreReturnValue public B 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

      @CanIgnoreReturnValue public B 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://logging.apache.org/log4j/2.x/manual/performance.html#layouts-location).
      Parameters:
      captureCodeAttributes - To enable or disable the code attributes (file name, class name, method name and line number)
    • setMapMessageAttributes

      @CanIgnoreReturnValue public B setMapMessageAttributes(@Nullable io.opentelemetry.instrumentation.api.config.IncludeExclude mapMessageAttributes)
      Configures the log4j MapMessage attributes that will be copied to logs.

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

      Only a non-empty selector set here takes precedence over the mapMessageAttributesIncluded and mapMessageAttributesExcluded settings, which in turn take precedence over the deprecated captureMapMessageAttributes setting. A null or empty selector carries no configuration, so it does not disable capture and the next configured source is used instead. No MapMessage attributes are captured when the selector and the pattern settings are absent or empty and captureMapMessageAttributes is false, which is also its default.

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

    • setMapMessageAttributesIncluded

      @CanIgnoreReturnValue public B setMapMessageAttributesIncluded(String mapMessageAttributesIncluded)
      Configures the comma-separated log4j MapMessage attribute key patterns that will be copied to logs.

      This is the configuration-file form of setMapMessageAttributes(IncludeExclude) and is ignored when a non-empty selector is set with that method. Patterns use the same case-sensitive glob syntax, where ? matches any single character and * matches any number of characters, including none.

    • setMapMessageAttributesExcluded

      @CanIgnoreReturnValue public B setMapMessageAttributesExcluded(String mapMessageAttributesExcluded)
      Configures the comma-separated log4j MapMessage attribute key patterns that will not be copied to logs.

      This is the configuration-file form of setMapMessageAttributes(IncludeExclude) and is ignored when a non-empty selector is set with that method. Patterns use the same case-sensitive glob syntax, where ? matches any single character and * matches any number of characters, including none. Excluded patterns take precedence over included patterns.

    • setCaptureMapMessageAttributes

      @Deprecated @CanIgnoreReturnValue public B setCaptureMapMessageAttributes(boolean captureMapMessageAttributes)
      Deprecated.
      Use setMapMessageAttributes(IncludeExclude) instead. May be removed in the next minor release.
      Sets whether log4j MapMessage attributes should be copied to logs.

      true is equivalent to setting a selector that includes "*" with setMapMessageAttributes(IncludeExclude), and false is equivalent to clearing that selector, so the last of these two methods to be called wins. The captureMapMessageAttributes configuration-file attribute is only used when no selector and no mapMessageAttributesIncluded or mapMessageAttributesExcluded pattern is configured.

    • setCaptureMarkerAttribute

      @CanIgnoreReturnValue public B setCaptureMarkerAttribute(boolean captureMarkerAttribute)
      Sets whether the marker attribute should be set to logs.
      Parameters:
      captureMarkerAttribute - To enable or disable the marker attribute
    • setCaptureTemplate

      @CanIgnoreReturnValue public B 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

      @CanIgnoreReturnValue public B setCaptureArguments(boolean captureArguments)
      Sets whether the arguments should be captured in logs.
      Parameters:
      captureArguments - whether the arguments should be captured in logs
    • setContextDataAttributes

      @CanIgnoreReturnValue public B setContextDataAttributes(@Nullable io.opentelemetry.instrumentation.api.config.IncludeExclude contextDataAttributes)
      Configures the ThreadContext attributes that will be copied to logs.

      Context data keys and selector patterns are matched case-sensitively. ? matches any single character and * matches any number of characters, including none, so included("*") captures every context data attribute. Excluded patterns take precedence over included patterns. A selector with only excluded patterns captures every context data attribute that it does not exclude.

      Only a non-empty selector set here takes precedence over the contextDataAttributesIncluded and contextDataAttributesExcluded settings, which in turn take precedence over the deprecated setCaptureContextDataAttributes(String) setting. A null or empty selector carries no configuration, so it does not disable capture and the next configured source is used instead. No context data attributes are captured only when every one of these sources is absent or empty.

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

    • setContextDataAttributesIncluded

      @CanIgnoreReturnValue public B setContextDataAttributesIncluded(String contextDataAttributesIncluded)
      Configures the comma-separated ThreadContext attribute key patterns that will be copied to logs.

      This is the configuration-file form of setContextDataAttributes(IncludeExclude) and is ignored when a non-empty selector is set with that method. Patterns use the same case-sensitive glob syntax, where ? matches any single character and * matches any number of characters, including none.

    • setContextDataAttributesExcluded

      @CanIgnoreReturnValue public B setContextDataAttributesExcluded(String contextDataAttributesExcluded)
      Configures the comma-separated ThreadContext attribute key patterns that will not be copied to logs.

      This is the configuration-file form of setContextDataAttributes(IncludeExclude) and is ignored when a non-empty selector is set with that method. Patterns use the same case-sensitive glob syntax, where ? matches any single character and * matches any number of characters, including none. Excluded patterns take precedence over included patterns.

    • setCaptureContextDataAttributes

      @Deprecated @CanIgnoreReturnValue public B setCaptureContextDataAttributes(String captureContextDataAttributes)
      Deprecated.
      Use setContextDataAttributes(IncludeExclude) instead. May be removed in the next minor release.
      Configures the ThreadContext attributes that will be copied to logs.

      This setting does not support glob patterns. A comma-separated list containing only * captures every context data attribute; otherwise every entry, including one that contains * or ?, is matched as a literal context data key.

      It is ignored when a non-empty selector is set with setContextDataAttributes(IncludeExclude) or when contextDataAttributesIncluded or contextDataAttributesExcluded is configured.

    • setNumLogsCapturedBeforeOtelInstall

      @CanIgnoreReturnValue public B setNumLogsCapturedBeforeOtelInstall(int numLogsCapturedBeforeOtelInstall)
      Log telemetry is emitted after the initialization of the OpenTelemetry Log4j appender with an OpenTelemetry object. This setting allows you to modify the size of the cache used to replay the logs that were emitted prior to setting the OpenTelemetry instance into the OpenTelemetry Log4j appender.
    • setOpenTelemetry

      @CanIgnoreReturnValue public B setOpenTelemetry(io.opentelemetry.api.OpenTelemetry openTelemetry)
      Configures the OpenTelemetry used to append logs.
    • build

      public OpenTelemetryAppender build()
      Specified by:
      build in interface org.apache.logging.log4j.core.util.Builder<B extends OpenTelemetryAppender.Builder<B>>