Java

You can leverage Custom Resources to configure the OpenTelemetry auto-instrumentation library and add annotations to your workloads to easily collect logs.

1) CRD installation

You can create one by searching for Infrastructure - Custom Resources - 'instrumentations'.

You can create it by clicking the Create button, selecting the namespace where you want to collect logs, and modifying the form below.

The above CRD is applied on a namespace basis, and automatic container logs can be collected for other languages ​​in the same namespace.

apiVersion: opentelemetry.io/v1alpha1
kind: Instrumentation
metadata:
  name: {Instrumentation name}
spec:
  exporter:
    endpoint: {log-agent Service address}:4318
  java:
    image: ghcr.io/open-telemetry/opentelemetry-operator/autoinstrumentation-java:2.0.0
    env:
      - name: OTEL_LOGS_EXPORTER
        value: otlp
      - name: OTEL_METRICS_EXPORTER
        value: none
      - name: OTEL_TRACES_EXPORTER
        value: none
        
      # Used when you want to collect all Java applications for which the anotation value of the namespace is 'true'..                
      - name: OTEL_EXPORTER_OTLP_LOGS_ENDPOINT
        value: {log-agent Service address}:4318/v1/logs

log-agent Service address : Infrastructure - Cluster - Add-ons - Click 'log-agent' and check the service name.

( http port = 4318 , grpc port = 4317)

By adding an environment variable for each individual application rather than all applications in the namespace through CRD, you can only collect logs for a specific application.

2) Add annotations to the individual applications you want to collect

Add annotations to the workloads in the namespace for which you want to collect logs.

Application - Service Map - Service Map to collect logs - Workload - Select the application to collect logs - Click the "Settings" button.

Change the Yaml view and add the following annotations to the template - metadata - annotations section.

instrumentation.opentelemetry.io/inject-java: 'true'

3) Add service name and token value to environment variables

apiVersion: apps/v1
kind: Deployment
...
spec:
...
  template:
    spec:
      containers:
      - env:

	# Application name
	- name: OTEL_SERVICE_NAME
          value: {Application name}
        
        # Settings for authentication
        - name: OTEL_EXPORTER_OTLP_LOGS_HEADERS
          value: app_token={Application token},app_name={Application name}        
        
        image: {java-application image}
        imagePullPolicy: Always
        ...

4. Check Application log

1) Logging - Application Log - Search for the application you set in the application list.

Last updated

Was this helpful?