This is a method of installing into an existing application using the SDK provided by Opentelemetry.
This guide is for existing JAVA applications that have been build on Cocktail Cloud.
1. Log Appender Setting
Log Appender is an interface provided by a logging framework or library that provides the ability to collect and process log messages. OpenTelemetry interacts with Log Appender through the Log Bridge API to collect log messages and associate them with tracking data from OpenTelemetry. Therefore, log appenders can be used to collect and integrate log data from OpenTelemetry.
We introduce how to collect data using logback and log4j, which are representative loggers.
privatestaticfinalLogger logger =LoggerFactory.getLogger("OTLP");// Logging with a logger called OTLP. This can be changed// If you set it to 'ALL' in the above document, you can log with console and opentelemetry.
2. Image creation via SDK
1) Build/Pipeline - Build details of the Java application for which you want to collect logs from the build.
2) Click “Image Build Task” to edit
3) Setting environment variables and downloading SDK of Opentelemetry-java-instrumentation
...
# Required settings to export log
ENV OTEL_EXPORTER_OTLP_ENDPOINT=$OTEL_EXPORTER_OTLP_ENDPOINT
ENV OTEL_EXPORTER_OTLP_LOGS_ENDPOINT=$OTEL_EXPORTER_OTLP_LOGS_ENDPOINT
ENV OTEL_EXPORTER_OTLP_LOGS_HEADERS=$OTEL_EXPORTER_OTLP_LOGS_HEADERS
ENV OTEL_LOGS_EXPORTER=$OTEL_LOGS_EXPORTER
ENV OTEL_SERVICE_NAME=$OTEL_SERVICE_NAME
# None processing to not collect metrics and traces
ENV OTEL_METRICS_EXPORTER=none
ENV OTEL_TRACES_EXPORTER=none
# Download sdk
RUN wget -q https://github.com/open-telemetry/opentelemetry-java-instrumentation/releases/download/v2.0.0/opentelemetry-javaagent.jar
ENTRYPOINT ["java", "-javaagent:opentelemetry-javaagent.jar", "-jar", "app.jar"]
...
3. Container Setting
1) Logging - Copy the token of the application created in Application Management
2) In Container Details - Settings - Environment Variables tab, set environment variables as follows
apiVersion:apps/v1kind:Deployment...spec:...template:spec:containers: - env:# opentelemetry collector svc address (eg. http://log-agent-cocktail-log-agent.cocktail-addon:4318) - name:OTEL_EXPORTER_OTLP_ENDPOINTvalue: {log-agent Service address}:4318# Log service address of opentelemetry collector (eg. http://log-agent-cocktail-log-agent.cocktail-addon:4318/v1/logs) - name:OTEL_EXPORTER_OTLP_LOGS_ENDPOINTvalue: {log-agent Service address}:4318/v1/logs# Settings using opelemetry protocol - name:OTEL_LOGS_EXPORTERvalue:otlp# Application Name - name:OTEL_SERVICE_NAMEvalue: {Application Name}# Settings for authentication - name:OTEL_EXPORTER_OTLP_LOGS_HEADERSvalue:app_token={Application Token},app_name={Application Name}image: {java-application image}imagePullPolicy:Always...
log-agent Service Address : Infrastructure - Cluster - Add-ons - Click 'log-agent' and check the service name.
( http port = 4318 , grpc port = 4317)
4. Check Application Log Check
1) Logging - Application Log - Search for the application you set in the application list.