From 07c6c185fcae1b45bb9d1acc7c3cf420a150b2cc Mon Sep 17 00:00:00 2001 From: Gregor Zeitlinger Date: Thu, 7 Nov 2024 08:57:40 +0100 Subject: [PATCH 1/3] stdout logs example --- README.md | 4 +- examples/java/json-logging-ecs/oats.yaml | 39 -------- examples/java/json-logging-logback/oats.yaml | 44 --------- examples/java/json-logging-otlp/Dockerfile | 22 +++++ examples/java/json-logging-otlp/README.md | 10 ++ examples/java/json-logging-otlp/build.sh | 5 + examples/java/json-logging-otlp/k3d.sh | 15 +++ .../k8s/collector-configmap.yaml | 72 +++++++++++++++ examples/java/json-logging-otlp/k8s/dice.yaml | 48 ++++++++++ examples/java/json-logging-otlp/k8s/lgtm.yaml | 86 +++++++++++++++++ .../java/json-logging-otlp/logback-spring.xml | 5 + examples/java/json-logging-otlp/oats.yaml | 92 +++++++++++++++++++ examples/java/run.sh | 7 +- 13 files changed, 361 insertions(+), 88 deletions(-) delete mode 100644 examples/java/json-logging-ecs/oats.yaml delete mode 100644 examples/java/json-logging-logback/oats.yaml create mode 100644 examples/java/json-logging-otlp/Dockerfile create mode 100644 examples/java/json-logging-otlp/README.md create mode 100755 examples/java/json-logging-otlp/build.sh create mode 100755 examples/java/json-logging-otlp/k3d.sh create mode 100644 examples/java/json-logging-otlp/k8s/collector-configmap.yaml create mode 100644 examples/java/json-logging-otlp/k8s/dice.yaml create mode 100644 examples/java/json-logging-otlp/k8s/lgtm.yaml create mode 100644 examples/java/json-logging-otlp/logback-spring.xml create mode 100644 examples/java/json-logging-otlp/oats.yaml diff --git a/README.md b/README.md index 5e9c349..4bcee32 100644 --- a/README.md +++ b/README.md @@ -57,8 +57,8 @@ There's no need to configure anything: The Docker image works with OpenTelemetry ```sh # Not needed as these are the defaults in OpenTelemetry: -export OTEL_EXPORTER_OTLP_PROTOCOL=grpc -export OTEL_EXPORTER_OTLP_ENDPOINT=http://localhost:4317 +export OTEL_EXPORTER_OTLP_PROTOCOL=http/protobuf +export OTEL_EXPORTER_OTLP_ENDPOINT=http://localhost:4318 ``` ## View Grafana diff --git a/examples/java/json-logging-ecs/oats.yaml b/examples/java/json-logging-ecs/oats.yaml deleted file mode 100644 index 9beeab6..0000000 --- a/examples/java/json-logging-ecs/oats.yaml +++ /dev/null @@ -1,39 +0,0 @@ -# OATS is an acceptance testing framework for OpenTelemetry - https://github.com/grafana/oats/tree/main/yaml -kubernetes: - dir: k8s - app-service: dice - app-docker-file: Dockerfile - app-docker-context: .. - app-docker-tag: dice:1.1-SNAPSHOT - app-docker-port: 8080 - import-images: - - grafana/otel-lgtm:latest -input: - - path: /rolldice -expected: - logs: - - logql: '{service_name="dice"} |~ `.*simulating an error.*`' - equals: 'Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed: java.lang.RuntimeException: simulating an error] with root cause' - attributes: - deployment_environment: staging - exception_message: "simulating an error" - exception_type: "java.lang.RuntimeException" - scope_name: "org.apache.catalina.core.ContainerBase.[Tomcat].[localhost].[/].[dispatcherServlet]" - service_name: dice - service_namespace: shop - severity_number: 17 - severity_text: ERROR - k8s_container_name: dice - k8s_namespace_name: default - attribute-regexp: - detected_level: ".*" # from loki - observed_timestamp: ".*" # from loki - thread_name: ".*" - span_id: ".*" - trace_id: ".*" - k8s_pod_name: dice-.*-.* - k8s_pod_uid: ".*" - k8s_container_restart_count: ".*" - service_instance_id: ".*" - exception_stacktrace: ".*" - no-extra-attributes: true diff --git a/examples/java/json-logging-logback/oats.yaml b/examples/java/json-logging-logback/oats.yaml deleted file mode 100644 index 7983b32..0000000 --- a/examples/java/json-logging-logback/oats.yaml +++ /dev/null @@ -1,44 +0,0 @@ -# OATS is an acceptance testing framework for OpenTelemetry - https://github.com/grafana/oats/tree/main/yaml -kubernetes: - dir: k8s - app-service: dice - app-docker-file: Dockerfile - app-docker-context: .. - app-docker-tag: dice:1.1-SNAPSHOT - app-docker-port: 8080 - import-images: - - grafana/otel-lgtm:latest -input: - - path: /rolldice -expected: - logs: - - logql: '{service_name="dice"} |~ `.*Anonymous player is rolling the dice:.*`' - regexp: 'Anonymous player is rolling the dice: \d+' # uses formatted message - - logql: '{service_name="dice"} |~ `.*simulating an error.*`' - equals: 'Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed: java.lang.RuntimeException: simulating an error] with root cause' - attributes: - deployment_environment: staging - exception_message: "simulating an error" - exception_type: "java.lang.RuntimeException" - scope_name: "org.apache.catalina.core.ContainerBase.[Tomcat].[localhost].[/].[dispatcherServlet]" - service_name: dice - service_namespace: shop - service_version: 1.1 - severity_number: 17 - severity_text: ERROR - k8s_container_name: dice - k8s_namespace_name: default - attribute-regexp: - flags: ".*" # from loki - detected_level: ".*" # from loki - observed_timestamp: ".*" # from loki - thread_name: ".*" - span_id: ".*" - trace_id: ".*" - k8s_pod_name: dice-.*-.* - k8s_pod_uid: ".*" - k8s_container_restart_count: ".*" - service_instance_id: ".*" - exception_stacktrace: ".*" # TODO: transform to sanitized stacktrace - no-extra-attributes: true - diff --git a/examples/java/json-logging-otlp/Dockerfile b/examples/java/json-logging-otlp/Dockerfile new file mode 100644 index 0000000..b0f900b --- /dev/null +++ b/examples/java/json-logging-otlp/Dockerfile @@ -0,0 +1,22 @@ +FROM eclipse-temurin:21-jdk AS builder + +WORKDIR /usr/src/app/ + +COPY ./mvnw pom.xml ./ +COPY ./.mvn ./.mvn +COPY ./src ./src +# uncomment the following line when 2.10.0 is released +# COPY json-logging-otlp/logback-spring.xml ./src/main/resources/logback-spring.xml +RUN --mount=type=cache,target=/root/.m2 ./mvnw install -DskipTests + +FROM eclipse-temurin:21-jre + +WORKDIR /usr/src/app/ + +COPY --from=builder /usr/src/app/target/rolldice.jar ./app.jar +# we ignore the version (which is from upstream) and use the latest version of the grafana distribution +ADD --chmod=644 https://github.com/grafana/grafana-opentelemetry-java/releases/latest/download/grafana-opentelemetry-java.jar /usr/src/app/opentelemetry-javaagent.jar +ENV JAVA_TOOL_OPTIONS=-javaagent:/usr/src/app/opentelemetry-javaagent.jar + +EXPOSE 8080 +ENTRYPOINT [ "java", "-jar", "./app.jar" ] diff --git a/examples/java/json-logging-otlp/README.md b/examples/java/json-logging-otlp/README.md new file mode 100644 index 0000000..eb0b279 --- /dev/null +++ b/examples/java/json-logging-otlp/README.md @@ -0,0 +1,10 @@ +# Exporting Application logs using JSON logging in Kubernetes + +## Running the example + +1. Build the Docker image using using `build.sh` +2. Deploy the manifest using `kubectl apply -f k8s/` (e.g. using [k3d.sh](k3d.sh)) +3. Generate traffic using [generate-traffic.sh](../../../generate-traffic.sh) +4. Log in to [http://localhost:3000](http://localhost:3000) with user _admin_ and password _admin_. +5. Go to "Explore" +6. Select "Loki" as data source diff --git a/examples/java/json-logging-otlp/build.sh b/examples/java/json-logging-otlp/build.sh new file mode 100755 index 0000000..7cbdda6 --- /dev/null +++ b/examples/java/json-logging-otlp/build.sh @@ -0,0 +1,5 @@ +#!/bin/bash + +set -euo pipefail + +docker build -f Dockerfile -t "dice:1.1-SNAPSHOT" .. diff --git a/examples/java/json-logging-otlp/k3d.sh b/examples/java/json-logging-otlp/k3d.sh new file mode 100755 index 0000000..36e446a --- /dev/null +++ b/examples/java/json-logging-otlp/k3d.sh @@ -0,0 +1,15 @@ +#!/bin/bash + +set -euo pipefail + +./build.sh +k3d cluster create jsonlogging || k3d cluster start jsonlogging +k3d image import -c jsonlogging dice:1.1-SNAPSHOT + +kubectl apply -f k8s/ + +kubectl wait --for=condition=ready pod -l app=dice +kubectl wait --for=condition=ready --timeout=5m pod -l app=lgtm + +kubectl port-forward service/dice 8080:8080 & +kubectl port-forward service/lgtm 3000:3000 & diff --git a/examples/java/json-logging-otlp/k8s/collector-configmap.yaml b/examples/java/json-logging-otlp/k8s/collector-configmap.yaml new file mode 100644 index 0000000..7c6e09d --- /dev/null +++ b/examples/java/json-logging-otlp/k8s/collector-configmap.yaml @@ -0,0 +1,72 @@ +apiVersion: v1 +kind: ConfigMap +metadata: + name: otel-collector-config +data: + otel-collector-config.yaml: |- + receivers: + otlp: + protocols: + grpc: + endpoint: 0.0.0.0:4317 + http: + endpoint: 0.0.0.0:4318 + prometheus/collector: # needed if you use the docker-lgtm image + config: + scrape_configs: + - job_name: 'opentelemetry-collector' + static_configs: + - targets: [ 'localhost:8888' ] + filelog/otlp-json-logs: + include: + - /var/log/pods/*/*/*.log + include_file_path: true + operators: + - id: container-parser + type: container + + processors: + batch: + resourcedetection: + detectors: [ "env", "system" ] + override: false + + connectors: + otlpjson: + + exporters: + otlphttp/metrics: + endpoint: http://localhost:9090/api/v1/otlp + otlphttp/traces: + endpoint: http://localhost:4418 + otlphttp/logs: + endpoint: http://localhost:3100/otlp + debug/metrics: + verbosity: detailed + debug/traces: + verbosity: detailed + debug/logs: + verbosity: detailed + nop: + + service: + pipelines: + traces: + receivers: [ otlp ] + processors: [ batch ] + exporters: [ otlphttp/traces ] + metrics: + receivers: [ otlp, prometheus/collector ] + processors: [ batch ] + exporters: [ otlphttp/metrics ] + logs/raw_otlpjson: + receivers: [ filelog/otlp-json-logs ] + # (i) no need for processors before the otlpjson connector + # Declare processors in the shared "logs" pipeline below + processors: [ ] + exporters: [ otlpjson ] + logs/otlp: + receivers: [ otlp, otlpjson ] + processors: [ resourcedetection, batch ] + exporters: [ otlphttp/logs ] + # exporters: [ otlphttp/logs, debug/logs ] # Uncomment this line to enable debug logging diff --git a/examples/java/json-logging-otlp/k8s/dice.yaml b/examples/java/json-logging-otlp/k8s/dice.yaml new file mode 100644 index 0000000..97abb76 --- /dev/null +++ b/examples/java/json-logging-otlp/k8s/dice.yaml @@ -0,0 +1,48 @@ +apiVersion: v1 +kind: Service +metadata: + name: dice +spec: + selector: + app: dice + ports: + - protocol: TCP + port: 8080 + targetPort: 8080 +--- +apiVersion: apps/v1 +kind: Deployment +metadata: + name: dice +spec: + replicas: 1 + selector: + matchLabels: + app: dice + template: + metadata: + labels: + app: dice + spec: + containers: + - name: dice + image: dice:1.1-SNAPSHOT + imagePullPolicy: Never + ports: + - containerPort: 8080 + env: + - name: OTEL_EXPORTER_OTLP_ENDPOINT + value: "http://lgtm:4318" + - name: OTEL_LOGS_EXPORTER + value: "experimental-otlp/stdout" + - name: OTEL_RESOURCE_ATTRIBUTES + value: service.name=dice,service.namespace=shop,service.version=1.1,deployment.environment=staging + - name: OTEL_INSTRUMENTATION_LOGBACK_APPENDER_EXPERIMENTAL_LOG_ATTRIBUTES + value: "true" + - name: OTEL_INSTRUMENTATION_LOGBACK_APPENDER_EXPERIMENTAL_CAPTURE_KEY_VALUE_PAIR_ATTRIBUTES + value: "true" + - name: OTEL_INSTRUMENTATION_LOGBACK_APPENDER_EXPERIMENTAL_CAPTURE_MDC_ATTRIBUTES + value: "true" + - name: SERVICE_NAME + value: dice + diff --git a/examples/java/json-logging-otlp/k8s/lgtm.yaml b/examples/java/json-logging-otlp/k8s/lgtm.yaml new file mode 100644 index 0000000..7d8f6cc --- /dev/null +++ b/examples/java/json-logging-otlp/k8s/lgtm.yaml @@ -0,0 +1,86 @@ +apiVersion: v1 +kind: Service +metadata: + name: lgtm +spec: + selector: + app: lgtm + ports: + - name: grafana + protocol: TCP + port: 3000 + targetPort: 3000 + - name: otel-grpc + protocol: TCP + port: 4317 + targetPort: 4317 + - name: otel-http + protocol: TCP + port: 4318 + targetPort: 4318 + - name: prometheus # needed for automated tests + protocol: TCP + port: 9090 + targetPort: 9090 + - name: loki # needed for automated tests + protocol: TCP + port: 3100 + targetPort: 3100 + - name: tempo # needed for automated tests + protocol: TCP + port: 3200 + targetPort: 3200 +--- +apiVersion: apps/v1 +kind: Deployment +metadata: + name: lgtm +spec: + replicas: 1 + selector: + matchLabels: + app: lgtm + template: + metadata: + labels: + app: lgtm + spec: + containers: + - name: lgtm + image: grafana/otel-lgtm:latest + ports: + - containerPort: 3000 + - containerPort: 4317 + - containerPort: 4318 + - containerPort: 9090 # needed for automated tests + - containerPort: 3100 # needed for automated tests + - containerPort: 3200 # needed for automated tests + readinessProbe: + exec: + command: + - cat + - /tmp/ready + volumeMounts: + - mountPath: /otel-lgtm/otelcol-config.yaml + name: otel-collector-config + subPath: otel-collector-config.yaml + readOnly: true + - mountPath: /var/log + name: varlog + readOnly: true + - mountPath: /var/lib/docker/containers + name: varlibdockercontainers + readOnly: true + env: + - name: ENABLE_LOGS_OTELCOL + value: "true" + volumes: + - name: otel-collector-config + configMap: + name: otel-collector-config + - name: varlog + hostPath: + path: /var/log + - name: varlibdockercontainers + hostPath: + path: /var/lib/docker/containers diff --git a/examples/java/json-logging-otlp/logback-spring.xml b/examples/java/json-logging-otlp/logback-spring.xml new file mode 100644 index 0000000..da72c91 --- /dev/null +++ b/examples/java/json-logging-otlp/logback-spring.xml @@ -0,0 +1,5 @@ + + + + + diff --git a/examples/java/json-logging-otlp/oats.yaml b/examples/java/json-logging-otlp/oats.yaml new file mode 100644 index 0000000..7fd867d --- /dev/null +++ b/examples/java/json-logging-otlp/oats.yaml @@ -0,0 +1,92 @@ +# OATS is an acceptance testing framework for OpenTelemetry - https://github.com/grafana/oats/tree/main/yaml +kubernetes: + dir: k8s + app-service: dice + app-docker-file: Dockerfile + app-docker-context: .. + app-docker-tag: dice:1.1-SNAPSHOT + app-docker-port: 8080 + import-images: + - grafana/otel-lgtm:latest +input: + - path: /rolldice +expected: + logs: + - logql: '{service_name="dice"} |~ `.*Anonymous player is rolling the dice:.*`' + regexp: 'Anonymous player is rolling the dice: \d+' # uses formatted message + - logql: '{service_name="dice"} |~ `.*simulating an error.*`' + equals: 'Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed: java.lang.RuntimeException: simulating an error] with root cause' + attributes: + deployment_environment: staging + exception_message: "simulating an error" + exception_type: "java.lang.RuntimeException" + scope_name: "org.apache.catalina.core.ContainerBase.[Tomcat].[localhost].[/].[dispatcherServlet]" + service_name: dice + service_namespace: shop + service_version: 1.1 + severity_number: 17 + severity_text: SEVERE + exception_stacktrace: "java.lang.RuntimeException: simulating an error + \n\tat com.grafana.example.RollController.index(RollController.java:21)\ + \n\tat java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(Unknown Source)\ + \n\tat java.base/java.lang.reflect.Method.invoke(Unknown Source)\ + \n\tat org.springframework.web.method.support.InvocableHandlerMethod.doInvoke(InvocableHandlerMethod.java:255)\ + \n\tat org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:188)\ + \n\tat org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:118)\ + \n\tat org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:926)\ + \n\tat org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:831)\ + \n\tat org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:87)\ + \n\tat org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:1089)\ + \n\tat org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:979)\ + \n\tat org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:1014)\ + \n\tat org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:903)\ + \n\tat jakarta.servlet.http.HttpServlet.service(HttpServlet.java:564)\ + \n\tat org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:885)\ + \n\tat jakarta.servlet.http.HttpServlet.service(HttpServlet.java:658)\ + \n\tat org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:195)\ + \n\tat org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:140)\ + \n\tat org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:51)\ + \n\tat org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:164)\ + \n\tat org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:140) + \n\tat org.springframework.web.filter.RequestContextFilter.doFilterInternal(RequestContextFilter.java:100) + \n\tat org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:116) + \n\tat org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:164) + \n\tat org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:140) + \n\tat org.springframework.web.filter.FormContentFilter.doFilterInternal(FormContentFilter.java:93) + \n\tat org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:116) + \n\tat org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:164) + \n\tat org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:140) + \n\tat org.springframework.web.servlet.v6_0.OpenTelemetryHandlerMappingFilter.doFilter(OpenTelemetryHandlerMappingFilter.java:78) + \n\tat org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:164) + \n\tat org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:140) + \n\tat org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:201) + \n\tat org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:116) + \n\tat org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:164) + \n\tat org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:140) + \n\tat org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:167) + \n\tat org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:90) + \n\tat org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:483) + \n\tat org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:115) + \n\tat org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:93) + \n\tat org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:74) + \n\tat org.apache.catalina.valves.RemoteIpValve.invoke(RemoteIpValve.java:731) + \n\tat org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:344) + \n\tat org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:384) + \n\tat org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:63) + \n\tat org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:905) + \n\tat org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1741) + \n\tat org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:52) + \n\tat org.apache.tomcat.util.threads.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1190) + \n\tat org.apache.tomcat.util.threads.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:659) + \n\tat org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:63) + \n\tat java.base/java.lang.Thread.run(Unknown Source)" + attribute-regexp: + flags: ".*" # from loki + detected_level: ".*" # from loki + observed_timestamp: ".*" # from loki + thread_name: ".*" + span_id: ".*" + trace_id: ".*" + service_instance_id: ".*" + no-extra-attributes: true + diff --git a/examples/java/run.sh b/examples/java/run.sh index a3d5f33..213f0ab 100755 --- a/examples/java/run.sh +++ b/examples/java/run.sh @@ -1,14 +1,15 @@ #!/bin/bash -set -euo pipefail +set -euox pipefail if [[ ! -f ./target/rolldice.jar ]] ; then ./mvnw clean package fi -version=v2.6.0 +#version=2.10.0-SNAPSHOT +version=2.9.0 jar=opentelemetry-javaagent-${version}.jar if [[ ! -f ./${jar} ]] ; then - curl -sL https://github.com/open-telemetry/opentelemetry-java-instrumentation/releases/download/${version}/opentelemetry-javaagent.jar -o ${jar} + curl -sL http://us-docker.pkg.dev/grafanalabs-global/docker-grafana-opentelemetry-java-prod/grafana-opentelemetry-java:${version}/grafana-javaagent.jar -o ${jar} fi export OTEL_RESOURCE_ATTRIBUTES="service.name=rolldice,service.instance.id=localhost:8080" # uncomment the next line to switch to Prometheus native histograms. From bf7ed2d5f5e86cf5cf764bc357f96b12fe629f55 Mon Sep 17 00:00:00 2001 From: Gregor Zeitlinger Date: Thu, 7 Nov 2024 09:46:52 +0100 Subject: [PATCH 2/3] stdout logs example --- examples/java/json-logging-otlp/oats.yaml | 68 +++++++++++------------ 1 file changed, 34 insertions(+), 34 deletions(-) diff --git a/examples/java/json-logging-otlp/oats.yaml b/examples/java/json-logging-otlp/oats.yaml index 7fd867d..fbd7d75 100644 --- a/examples/java/json-logging-otlp/oats.yaml +++ b/examples/java/json-logging-otlp/oats.yaml @@ -26,7 +26,7 @@ expected: service_version: 1.1 severity_number: 17 severity_text: SEVERE - exception_stacktrace: "java.lang.RuntimeException: simulating an error + exception_stacktrace: "java.lang.RuntimeException: simulating an error\ \n\tat com.grafana.example.RollController.index(RollController.java:21)\ \n\tat java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(Unknown Source)\ \n\tat java.base/java.lang.reflect.Method.invoke(Unknown Source)\ @@ -47,39 +47,39 @@ expected: \n\tat org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:140)\ \n\tat org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:51)\ \n\tat org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:164)\ - \n\tat org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:140) - \n\tat org.springframework.web.filter.RequestContextFilter.doFilterInternal(RequestContextFilter.java:100) - \n\tat org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:116) - \n\tat org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:164) - \n\tat org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:140) - \n\tat org.springframework.web.filter.FormContentFilter.doFilterInternal(FormContentFilter.java:93) - \n\tat org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:116) - \n\tat org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:164) - \n\tat org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:140) - \n\tat org.springframework.web.servlet.v6_0.OpenTelemetryHandlerMappingFilter.doFilter(OpenTelemetryHandlerMappingFilter.java:78) - \n\tat org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:164) - \n\tat org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:140) - \n\tat org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:201) - \n\tat org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:116) - \n\tat org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:164) - \n\tat org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:140) - \n\tat org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:167) - \n\tat org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:90) - \n\tat org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:483) - \n\tat org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:115) - \n\tat org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:93) - \n\tat org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:74) - \n\tat org.apache.catalina.valves.RemoteIpValve.invoke(RemoteIpValve.java:731) - \n\tat org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:344) - \n\tat org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:384) - \n\tat org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:63) - \n\tat org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:905) - \n\tat org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1741) - \n\tat org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:52) - \n\tat org.apache.tomcat.util.threads.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1190) - \n\tat org.apache.tomcat.util.threads.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:659) - \n\tat org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:63) - \n\tat java.base/java.lang.Thread.run(Unknown Source)" + \n\tat org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:140)\ + \n\tat org.springframework.web.filter.RequestContextFilter.doFilterInternal(RequestContextFilter.java:100)\ + \n\tat org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:116)\ + \n\tat org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:164)\ + \n\tat org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:140)\ + \n\tat org.springframework.web.filter.FormContentFilter.doFilterInternal(FormContentFilter.java:93)\ + \n\tat org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:116)\ + \n\tat org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:164)\ + \n\tat org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:140)\ + \n\tat org.springframework.web.servlet.v6_0.OpenTelemetryHandlerMappingFilter.doFilter(OpenTelemetryHandlerMappingFilter.java:78)\ + \n\tat org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:164)\ + \n\tat org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:140)\ + \n\tat org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:201)\ + \n\tat org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:116)\ + \n\tat org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:164)\ + \n\tat org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:140)\ + \n\tat org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:167)\ + \n\tat org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:90)\ + \n\tat org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:483)\ + \n\tat org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:115)\ + \n\tat org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:93)\ + \n\tat org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:74)\ + \n\tat org.apache.catalina.valves.RemoteIpValve.invoke(RemoteIpValve.java:731)\ + \n\tat org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:344)\ + \n\tat org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:384)\ + \n\tat org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:63)\ + \n\tat org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:905)\ + \n\tat org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1741)\ + \n\tat org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:52)\ + \n\tat org.apache.tomcat.util.threads.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1190)\ + \n\tat org.apache.tomcat.util.threads.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:659)\ + \n\tat org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:63)\ + \n\tat java.base/java.lang.Thread.run(Unknown Source)\n" attribute-regexp: flags: ".*" # from loki detected_level: ".*" # from loki From 91d5c9b6238b5d48edb695faa18b773d7957adb4 Mon Sep 17 00:00:00 2001 From: Gregor Zeitlinger Date: Thu, 14 Nov 2024 13:38:14 +0100 Subject: [PATCH 3/3] stdout logs example --- examples/java/json-logging-ecs/Dockerfile | 2 +- examples/java/json-logging-logback/Dockerfile | 2 +- examples/java/json-logging-otlp/Dockerfile | 2 +- examples/java/json-logging-otlp/oats.yaml | 19 ++++++++++++++++++- examples/java/run.sh | 5 ++--- 5 files changed, 23 insertions(+), 7 deletions(-) diff --git a/examples/java/json-logging-ecs/Dockerfile b/examples/java/json-logging-ecs/Dockerfile index 9a7923e..7098697 100644 --- a/examples/java/json-logging-ecs/Dockerfile +++ b/examples/java/json-logging-ecs/Dockerfile @@ -15,7 +15,7 @@ WORKDIR /usr/src/app/ COPY --from=builder /usr/src/app/target/rolldice.jar ./app.jar # we ignore the version (which is from upstream) and use the latest version of the grafana distribution -ADD --chmod=644 https://github.com/grafana/grafana-opentelemetry-java/releases/latest/download/grafana-opentelemetry-java.jar /usr/src/app/opentelemetry-javaagent.jar +ADD --chmod=644 https://github.com/open-telemetry/opentelemetry-java-instrumentation/releases/latest/download/opentelemetry-javaagent.jar /usr/src/app/opentelemetry-javaagent.jar ENV JAVA_TOOL_OPTIONS=-javaagent:/usr/src/app/opentelemetry-javaagent.jar EXPOSE 8080 diff --git a/examples/java/json-logging-logback/Dockerfile b/examples/java/json-logging-logback/Dockerfile index 6b158df..85a3d94 100644 --- a/examples/java/json-logging-logback/Dockerfile +++ b/examples/java/json-logging-logback/Dockerfile @@ -14,7 +14,7 @@ WORKDIR /usr/src/app/ COPY --from=builder /usr/src/app/target/rolldice.jar ./app.jar # we ignore the version (which is from upstream) and use the latest version of the grafana distribution -ADD --chmod=644 https://github.com/grafana/grafana-opentelemetry-java/releases/latest/download/grafana-opentelemetry-java.jar /usr/src/app/opentelemetry-javaagent.jar +ADD --chmod=644 https://github.com/open-telemetry/opentelemetry-java-instrumentation/releases/latest/download/opentelemetry-javaagent.jar /usr/src/app/opentelemetry-javaagent.jar ENV JAVA_TOOL_OPTIONS=-javaagent:/usr/src/app/opentelemetry-javaagent.jar EXPOSE 8080 diff --git a/examples/java/json-logging-otlp/Dockerfile b/examples/java/json-logging-otlp/Dockerfile index b0f900b..caf3407 100644 --- a/examples/java/json-logging-otlp/Dockerfile +++ b/examples/java/json-logging-otlp/Dockerfile @@ -15,7 +15,7 @@ WORKDIR /usr/src/app/ COPY --from=builder /usr/src/app/target/rolldice.jar ./app.jar # we ignore the version (which is from upstream) and use the latest version of the grafana distribution -ADD --chmod=644 https://github.com/grafana/grafana-opentelemetry-java/releases/latest/download/grafana-opentelemetry-java.jar /usr/src/app/opentelemetry-javaagent.jar +ADD --chmod=644 https://github.com/open-telemetry/opentelemetry-java-instrumentation/releases/latest/download/opentelemetry-javaagent.jar /usr/src/app/opentelemetry-javaagent.jar ENV JAVA_TOOL_OPTIONS=-javaagent:/usr/src/app/opentelemetry-javaagent.jar EXPOSE 8080 diff --git a/examples/java/json-logging-otlp/oats.yaml b/examples/java/json-logging-otlp/oats.yaml index fbd7d75..2b3359e 100644 --- a/examples/java/json-logging-otlp/oats.yaml +++ b/examples/java/json-logging-otlp/oats.yaml @@ -84,9 +84,26 @@ expected: flags: ".*" # from loki detected_level: ".*" # from loki observed_timestamp: ".*" # from loki - thread_name: ".*" + # thread_name: ".*" # thread name is missing when there is an exception - has nothing to do with stdout logging span_id: ".*" trace_id: ".*" + container_id: ".*" + host_arch: ".*" + host_name: ".*" + os_description: ".*" + os_type: ".*" + process_command_args: ".*" + process_executable_path: ".*" + process_pid: ".*" + process_runtime_description: ".*" + process_runtime_name: ".*" + process_runtime_version: ".*" service_instance_id: ".*" + telemetry_distro_name: ".*" + telemetry_distro_version: ".*" + telemetry_sdk_language: ".*" + telemetry_sdk_name: ".*" + telemetry_sdk_version: ".*" + no-extra-attributes: true diff --git a/examples/java/run.sh b/examples/java/run.sh index 213f0ab..32a3372 100755 --- a/examples/java/run.sh +++ b/examples/java/run.sh @@ -5,11 +5,10 @@ set -euox pipefail if [[ ! -f ./target/rolldice.jar ]] ; then ./mvnw clean package fi -#version=2.10.0-SNAPSHOT -version=2.9.0 +version=2.10.0 jar=opentelemetry-javaagent-${version}.jar if [[ ! -f ./${jar} ]] ; then - curl -sL http://us-docker.pkg.dev/grafanalabs-global/docker-grafana-opentelemetry-java-prod/grafana-opentelemetry-java:${version}/grafana-javaagent.jar -o ${jar} + curl -vL https://github.com/open-telemetry/opentelemetry-java-instrumentation/releases/download/v${version}/opentelemetry-javaagent.jar -o ${jar} fi export OTEL_RESOURCE_ATTRIBUTES="service.name=rolldice,service.instance.id=localhost:8080" # uncomment the next line to switch to Prometheus native histograms.