open-telemetry / opentelemetry-java-instrumentation

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

service.name auto-discover #10068

Open MatheusGelinskiPires opened 8 months ago

MatheusGelinskiPires commented 8 months ago

Is your feature request related to a problem? Please describe.

Hello folks,

While instrumenting the OTLP Java APM Agent on a Oracle WebLogic Server (or another Application Server) it is not feasible to set the service.name attribute because it could be consolidating traces/metrics/logs under the same service.name and these application server could have more than just one application deployed.

Describe the solution you'd like

I am requesting a possible new feature where the OTLP Java APM Agent could be auto-discovering the service.name attribute based in some steps before assume the default value "unknown_service" for it.

Example based on Elastic APM Java Agent: link

Describe alternatives you've considered

No response

Additional context

No response

laurit commented 8 months ago

While instrumenting the OTLP Java APM Agent on a Oracle WebLogic Server (or another Application Server) it is not feasible to set the service.name attribute because it could be consolidating traces/metrics/logs under the same service.name and these application server could have more than just one application deployed.

Otel service.name is set per java process, currently it is not possible to set a separate service name for each deployed application.

I am requesting a possible new feature where the OTLP Java APM Agent could be auto-discovering the service.name attribute based in some steps before assume the default value "unknown_service" for it.

We already have something similar in https://github.com/open-telemetry/opentelemetry-java-contrib/tree/main/resource-providers

MatheusGelinskiPires commented 8 months ago

We already have something similar in https://github.com/open-telemetry/opentelemetry-java-contrib/tree/main/resource-providers

Is there any possibility to make this resource a common library for Otel Java based agents?

laurit commented 8 months ago

I believe you can use it as an agent extension, just use the resource-providers jar as described in https://github.com/open-telemetry/opentelemetry-java-instrumentation/tree/main/examples/extension

MatheusGelinskiPires commented 8 months ago

Hello @laurit , I will test it and return here as soon as I can.

MatheusGelinskiPires commented 8 months ago

So, just to summarize my lab:

Oracle WebLogic Server version: 14.1.1.0.0 JDK version: java version "1.8.0_391" / Java(TM) SE Runtime Environment (build 1.8.0_391-b13) / Java HotSpot(TM) 64-Bit Server VM (build 25.391-b13, mixed mode)

OpenTelemetry APM Agent version: 1.32.0 Resource Provider version: 1.33.0-alpha-SNAPSHOT

JVM arguments in use:

-Xms1024m -Xmx2048m -Djava.security.egd=file:/dev/urandom -javaagent:/opt/otlp/opentelemetry-apm-agent.jar -Dotel.exporter.otlp.endpoint=http://elk-apm.gelinski.local:8200 -Dotel.javaagent.extensions=/opt/otlp/opentelemetry-java-instrumentation-extension-all.jar

As the result I got the following message:

[otel.javaagent 2023-12-28 10:58:51:623 -0300] [main] WARN io.opentelemetry.contrib.resourceproviders.AppServerServiceNameProvider - Service name could not be detected using common application server strategies.

screenshot

image

laurit commented 8 months ago

Not really surprising as https://github.com/open-telemetry/opentelemetry-java-contrib/tree/main/resource-providers does not support weblogic.

MatheusGelinskiPires commented 8 months ago

Yeah. Should I open a 'feature request' in there since we are sure this is not an otlp java apm agent issue? Thx

MatheusGelinskiPires commented 8 months ago

Actually,

I was reviewing that resource-providers code and understood that just one service.name will be set which is the first to be dynamically found.

https://github.com/open-telemetry/opentelemetry-java-contrib/blob/main/resource-providers/src/main/java/io/opentelemetry/contrib/resourceproviders/AppServerServiceNameDetector.java#L58

So all the data continues to be sent under the same service.name.

And by doing that it stills not being a good solution for application servers in general I guess.