open-telemetry / opentelemetry-java-instrumentation

OpenTelemetry auto-instrumentation and instrumentation libraries for Java
https://opentelemetry.io
Apache License 2.0
1.96k stars 860 forks source link

metricReaders is not auto configured by java agent while passing property otel.metrics.exporter through configuration file #12735

Closed vijaybtech13 closed 43 minutes ago

vijaybtech13 commented 4 hours ago

Describe the bug

metricReaders object was not auto configured when passing otel.metrics.exporter property through configuration file(otel.properties). Since metricReaders was not configured metrics generation and export did not happen.

However, while passing as environment variable (OTEL_METRICS_EXPORTER=otlp) solved this issue. Why was the config file approach not worked?

java-agent-auto-configuration-log.txt

Steps to reproduce

  1. Have otel java agent properties in configuration file. (otel.properties)
  2. Pass the configuration file to spring boot application using env variable OTEL_JAVAAGENT_CONFIGURATION_FILE through docker compose file.
  3. Bring up the spring boot application.
**otel.properties**
otel.service.name=test-service
otel.exporter.otlp.protocol=grpc
otel.exporter.otlp.endpoint=http://collector:4317
otel.traces.exporter=otlp
otel.metrics.exporter=otlp
otel.logs.exporter=none
**Docker-compose file: [ only environment section ]**
 "environment": {
"OTEL_JAVAAGENT_CONFIGURATION_FILE": "otel.properties-file-path",
"OTEL_JAVAAGENT_ENABLED": "true"
}

Expected behavior

metricReaders should be auto configured. Metrics should be generated and exported to configured collector.

Auto configured metricReaders [ expected ] metricReaders=[PeriodicMetricReader{exporter=OtlpGrpcMetricExporter{exporterName=otlp, type=metric, endpoint=https://collector:4317, endpointPath=/opentelemetry.proto.collector.metrics.v1.MetricsService/Export, timeoutNanos=10000000000, connectTimeoutNanos=10000000000, compressorEncoding=null, headers=Headers{User-Agent=OBFUSCATED}

Actual behavior

metricReaders was not auto configured by java-agent. Metrics were not generated and exported to configured collector.

Auto configured metricReaders [ actual ] metricReaders=[]

Javaagent or library instrumentation version

opentelemetry-java-instrumentation/releases/tag/v2.9.0

Environment

JDK: process.runtime.description="BellSoft OpenJDK 64-Bit Server VM 17.0.13+12-LTS", process.runtime.name="OpenJDK Runtime Environment", process.runtime.version="17.0.13+12-LTS",

OS: os.description="Linux 5.15.0-1066-aws", os.type="linux",

Spring boot: 3.3.2

Additional context

  1. Javaagent was added into application image using Paketo Buildpack for OpenTelemetry 2.5.0.
  2. Issue was observed only for metrics generation and export. Trace generation and export worked properly with the configured property - otel.metrics.exporter.
  3. Issue had been solved, after setting environment variable OTEL_METRICS_EXPORTER=otlp.

What is expected from this bug?

  1. Why environment variable OTEL_METRICS_EXPORTER is required to configure metricReaders by java agent, when property was passed through configuration file?
laurit commented 4 hours ago

https://github.com/paketo-buildpacks/opentelemetry?tab=readme-ov-file#behavior reads By default, the metrics exporting feature of the agent is configured to be disabled (OTEL_METRICS_EXPORTER=none). Paketo build pack uses environment variable to disable the metrics exporter. Environment variables have a higher precedence than the configuration file.

vijaybtech13 commented 43 minutes ago

@laurit - Thanks for the information. It helps. Now understood, why otel.metrics.exporter was not applied, while passing it through configuration file.