open-telemetry / opentelemetry-java-instrumentation

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

not able to disable HostResourceProvider #9843

Closed krishnaexplore closed 10 months ago

krishnaexplore commented 11 months ago

Describe the bug

when I disabled HostResourceProvider using environment variable below labels still generated by java agent

net_host_name="localhost", net_host_port="8081",

http_server_duration_milliseconds_count{exported_job="cart", http_method="GET", http_route="/cart", http_scheme="http", http_status_code="200", instance="0.0.0.0:8889", job="otel_collector", net_host_name="localhost", net_host_port="8081", net_protocol_name="http", net_protocol_version="1.1"}

export OTEL_JAVA_DISABLED_RESOURCE_PROVIDERS=io.opentelemetry.instrumentation.resources.HostResourceProvider

Steps to reproduce

java agent configuration

   export OTEL_SERVICE_NAME=cart
   export OTEL_TRACES_EXPORTER=otlp
   export OTEL_METRICS_EXPORTER=otlp
   export OTEL_LOGS_EXPORTER=otlp
   export OTEL_RESOURCE_ATTRIBUTES=deployment.environment=local,service.version=1.1.0
   export OTEL_JAVA_DISABLED_RESOURCE_PROVIDERS=io.opentelemetry.instrumentation.resources.HostResourceProvider

running app like java -javaagent:opentelemetry-javaagent.jar -jar build/libs/cart-0.0.1-SNAPSHOT.jar

console output

     [otel.javaagent 2023-11-11 09:42:39:411 +0530] [main] INFO io.opentelemetry.javaagent.tooling.VersionLogger - opentelemetry-javaagent - version: 1.31.0

  .   ____          _            __ _ _
 /\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
 \\/  ___)| |_)| | | | | || (_| |  ) ) ) )
  '  |____| .__|_| |_|_| |_\__, | / / / /
 =========|_|==============|___/=/_/_/_/
 :: Spring Boot ::                (v2.7.5)

2023-11-11 09:42:41.985     INFO 5041 --- [           main] com.shopping.cart.CartApplication        : Starting CartApplication using Java 11.0.17 on Krishnas-MacBook-Pro.local with PID 5041 (/Users/krishnagangaraju/Documents/GitHub/observ-demos/cart/build/libs/cart-0.0.1-SNAPSHOT.jar started by krishnagangaraju in /Users/krishnagangaraju/Documents/GitHub/observ-demos/cart)
2023-11-11 09:42:41.987     INFO 5041 --- [           main] com.shopping.cart.CartApplication        : No active profile set, falling back to 1 default profile: "default"
2023-11-11 09:42:42.537     INFO 5041 --- [           main] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat initialized with port(s): 8081 (http)
2023-11-11 09:42:42.550     INFO 5041 --- [           main] o.apache.catalina.core.StandardService   : Starting service [Tomcat]
2023-11-11 09:42:42.551     INFO 5041 --- [           main] org.apache.catalina.core.StandardEngine  : Starting Servlet engine: [Apache Tomcat/9.0.68]
2023-11-11 09:42:42.583     INFO 5041 --- [           main] o.a.c.c.C.[Tomcat].[localhost].[/]       : Initializing Spring embedded WebApplicationContext
2023-11-11 09:42:42.583     INFO 5041 --- [           main] w.s.c.ServletWebServerApplicationContext : Root WebApplicationContext: initialization completed in 572 ms
2023-11-11 09:42:42.779     INFO 5041 --- [           main] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat started on port(s): 8081 (http) with context path ''
2023-11-11 09:42:42.786     INFO 5041 --- [           main] com.shopping.cart.CartApplication        : Started CartApplication in 1.245 seconds (JVM running for 3.513)
2023-11-11 09:42:48.498 c236eb302e6da381cd544ea543d62140 99a8fc9ae59a40d1 01  INFO 5041 --- [nio-8081-exec-1] o.a.c.c.C.[Tomcat].[localhost].[/]       : Initializing Spring DispatcherServlet 'dispatcherServlet'
2023-11-11 09:42:48.499 c236eb302e6da381cd544ea543d62140 99a8fc9ae59a40d1 01  INFO 5041 --- [nio-8081-exec-1] o.s.web.servlet.DispatcherServlet        : Initializing Servlet 'dispatcherServlet'
2023-11-11 09:42:48.500 c236eb302e6da381cd544ea543d62140 99a8fc9ae59a40d1 01  INFO 5041 --- [nio-8081-exec-1] o.s.web.servlet.DispatcherServlet        : Completed initialization in 1 ms
2023-11-11 09:42:48.535 c236eb302e6da381cd544ea543d62140 f4155d480019f263 01  INFO 5041 --- [nio-8081-exec-1] com.shopping.cart.CartController         : providing cart
2023-11-11 09:42:49.476 15ba101ed42e272f2f55deb004e604d9 c51adce4ad042365 01  INFO 5041 --- [nio-8081-exec-3] com.shopping.cart.CartController         : providing cart
2023-11-11 09:42:50.127 30bf40445b8739e8a61a35b58f7ddb23 df4c8b8214fe5ca2 01  INFO 5041 --- [nio-8081-exec-4] com.shopping.cart.CartController         : providing cart
2023-11-11 09:42:50.936 3eceb58b3f1f5cf6c5302864954c5cc1 1f7a3011b1da1bd0 01  INFO 5041 --- [nio-8081-exec-5] com.shopping.cart.CartController         : providing cart
2023-11-11 09:42:52.217 7d300998db0658334fceb640e69b0bba 72f46a37204df44b 01  INFO 5041 --- [nio-8081-exec-6] com.shopping.cart.CartController         : providing cart

metrics in prometheus

     http_server_duration_milliseconds_count{exported_job="cart", http_method="GET", http_route="/**", http_scheme="http", http_status_code="404", instance="0.0.0.0:8889", job="otel_collector", net_host_name="localhost", net_host_port="8081", net_protocol_name="http", net_protocol_version="1.1"} 1
http_server_duration_milliseconds_count{exported_job="cart", http_method="GET", http_route="/cart", http_scheme="http", http_status_code="200", instance="0.0.0.0:8889", job="otel_collector", net_host_name="localhost", net_host_port="8081", net_protocol_name="http", net_protocol_version="1.1"} 5

Expected behavior

should not be generated below labels for metric : http_server_duration_milliseconds_count net_host_name="localhost", net_host_port="8081"

Actual behavior

labels generated for metrics : http_server_duration_milliseconds_count net_host_name="localhost", net_host_port="8081"

Javaagent or library instrumentation version

v1.31.0

Environment

JDK: amazoncorretto:11 OS: MacOs

Additional context

No response

laurit commented 11 months ago

These attributes are not added by the HostResourceProvider hence disabling it will have no effect. To get rid of them try setting OTEL_SEMCONV_STABILITY_OPT_IN=http or alternatively you can drop them by configuring a metrics view https://github.com/open-telemetry/opentelemetry-java/tree/main/sdk-extensions/incubator

krishnaexplore commented 11 months ago

@laurit which resource provider adding these labels (net_host_name, net_host_port)? and what is the functionality of views ?

laurit commented 11 months ago

@krishnaexplore they are not added by a resource provider. Description of views can be found in https://opentelemetry.io/docs/concepts/signals/metrics/#views

github-actions[bot] commented 10 months ago

This has been automatically marked as stale because it has been marked as needing author feedback and has not had any activity for 7 days. It will be closed automatically if there is no response from the author within 7 additional days from this comment.