If you're already using the OpenTelemetry™  Java Agent to instrument a Java application, you can configure the agent's log exporter to harvest logs from the path you specify. This option is best for Java applications that are already using an OpenTelemetry SDK and generating logs in log4j, logback, or JUL/SLF4J format. This option does not work for Python or Node.js applications because they can't use the OpenTelemetry Java Agent's auto-instrumentation and export; they require their logs to be written to a physical file, from which a Filelog Receiver in an OpenTelemetry collector can harvest and export them.

  1. Configure your Java Agent's log appender.
  2. Configure your Java Agent's log exporter to harvest logs from the path you specify.
  3. Configure your Java Agent's log exporter to export logs to an OpenTelemetry Collector (either Cisco AppDynamics Distribution of OpenTelemetry Collector or an open-source distribution) in native OTLP format by settings its OTEL_LOGS_EXPORTER environment variable to otlp.
  4. In your OpenTelemetry collector's configuration file, in the processor, receivers, and pipelines sections, add mandatory resource attributes to the log packets. Without this step Cisco Cloud Observability will drop the log packets during ingestion:

    1. In the resource processor, add service.namespace, service.name, and service.instance.id. To use different values for each service, create different resource/<service-name> sections. For example:

      resource/service-1:
        attributes:
          - key: service.namespace
            action: upsert
            value: my-app
          - key: service.name
            action: upsert
            value: service-1
          - key: service.instance.id
            action: upsert
            value: xxxx
      
      resource/service-2:
        attributes:
          - key: service.namespace
            action: upsert
            value: my-app
          - key: service.name
            action: upsert
            value: service-2
          - key: service.instance.id
            action: upsert
            value: xxxx
      YML
    2. In receivers, specify an endpoint for each of the resource/<service-name> sections you created in resource. For example:

      receivers:
        otlp/service-1:
          protocols:
            grpc:
              endpoint: 0.0.0.0:8639
        otlp/service-2:
          protocols:
            grpc:
              endpoint: 0.0.0.0:8640
      YML
    3. In pipelines, create as many logs/<service-name> sections as you have resource/<service-name> sections. In each logs/<service-name> section, point to the receivers and processors section that corresponds to that <service-name>. For example: 

      service:
        pipelines:
          logs/service-1:
            receivers: [ otlp/service-1 ]
            processors: [ memory_limiter, resource/service-1 ]
            exporters: [ otlphttp ]
          logs/service-2:
            receivers: [ otlp/service-2 ]
            processors: [ memory_limiter, resource/service-2 ]
            exporters: [ otlphttp ] 
      YML

Learn More

OpenTelemetry™ is a trademark of The Linux Foundation®.