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

Getting `MalformedURLException: no protocol` for a valid HTTP URL #9137

Closed Spitfire1900 closed 1 year ago

Spitfire1900 commented 1 year ago

Describe the bug When instrumenting a Java 17 Spring Boot workload, the agent is reporting the configured URL set by the -Dotel.exporter.otlp.traces.endpoint cmdline flag is reported as malformed when tests with curl using the same URL work.

Steps to reproduce With a Spring Boot project run the following java -javaagent:/opt/otel_agent/opentelemetry-javaagent-1.28.0.jar -Dotel.traces.exporter=otlp -Dotel.exporter.otlp.traces.endpoint="http://otel-collector.dev.svc.cluster.local:4317" -jar my_springboot_app.jar

What did you expect to see? I expected to see the javaagent successfully connect to an on premises OTEL Collector

What did you see instead? I got the following error message:

OpenTelemetry Javaagent failed to start
io.opentelemetry.sdk.autoconfigure.spi.ConfigurationException: OTLP endpoint must be a valid URL: "http://otel-collector.dev.svc.cluster.local:4317"
at io.opentelemetry.exporter.otlp.internal.OtlpConfigUtil.validateEndpoint(OtlpConfigUtil.java:214)
at io.opentelemetry.exporter.otlp.internal.OtlpConfigUtil.configureOtlpExporterBuilder(OtlpConfigUtil.java:67)
at io.opentelemetry.exporter.otlp.internal.OtlpSpanExporterProvider.createExporter(OtlpSpanExporterProvider.java:50)
at io.opentelemetry.sdk.autoconfigure.SpiUtil.lambda$loadConfigurable$0(SpiUtil.java:48)
at io.opentelemetry.sdk.autoconfigure.NamedSpiManager.tryLoadImplementationForName(NamedSpiManager.java:46)
at java.base/java.util.concurrent.ConcurrentHashMap.computeIfAbsent(ConcurrentHashMap.java:1708)
at io.opentelemetry.sdk.autoconfigure.NamedSpiManager.getByName(NamedSpiManager.java:36)
at io.opentelemetry.sdk.autoconfigure.SpanExporterConfiguration.configureExporter(SpanExporterConfiguration.java:91)
at io.opentelemetry.sdk.autoconfigure.SpanExporterConfiguration.configureSpanExporters(SpanExporterConfiguration.java:66)
at io.opentelemetry.sdk.autoconfigure.TracerProviderConfiguration.configureTracerProvider(TracerProviderConfiguration.java:51)
at io.opentelemetry.sdk.autoconfigure.AutoConfiguredOpenTelemetrySdkBuilder.build(AutoConfiguredOpenTelemetrySdkBuilder.java:356)
at io.opentelemetry.javaagent.tooling.OpenTelemetryInstaller.installOpenTelemetrySdk(OpenTelemetryInstaller.java:34)
at io.opentelemetry.javaagent.tooling.AgentInstaller.installBytebuddyAgent(AgentInstaller.java:121)
at io.opentelemetry.javaagent.tooling.AgentInstaller.installBytebuddyAgent(AgentInstaller.java:101)
at io.opentelemetry.javaagent.tooling.AgentStarterImpl.start(AgentStarterImpl.java:98)
at io.opentelemetry.javaagent.bootstrap.AgentInitializer$1.run(AgentInitializer.java:53)
at io.opentelemetry.javaagent.bootstrap.AgentInitializer$1.run(AgentInitializer.java:47)
at io.opentelemetry.javaagent.bootstrap.AgentInitializer.execute(AgentInitializer.java:64)
at io.opentelemetry.javaagent.bootstrap.AgentInitializer.initialize(AgentInitializer.java:46)
at io.opentelemetry.javaagent.OpenTelemetryAgent.startAgent(OpenTelemetryAgent.java:57)
at io.opentelemetry.javaagent.OpenTelemetryAgent.premain(OpenTelemetryAgent.java:45)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:568)
at java.instrument/sun.instrument.InstrumentationImpl.loadClassAndStartAgent(InstrumentationImpl.java:491)
at java.instrument/sun.instrument.InstrumentationImpl.loadClassAndCallPremain(InstrumentationImpl.java:503)
Caused by: java.net.MalformedURLException: no protocol: "http://otel-collector.dev.svc.cluster.local:4317"
at java.base/java.net.URL.<init>(URL.java:674)
at java.base/java.net.URL.<init>(URL.java:569)
at java.base/java.net.URL.<init>(URL.java:516)
at io.opentelemetry.exporter.otlp.internal.OtlpConfigUtil.validateEndpoint(OtlpConfigUtil.java:212)
... 26 more

What version are you using? v1.28.0

Environment I've using the shipped version of the javaagent from maven central. Compiler: Java 11 OS: Windows 2016 Runtime (if different from JDK above): Red Hat 17.0.8+7-LTS OS (if different from OS compiled on): Red Hat UBI 8

Additional context Add any other context about the problem here.

mateuszrzeszutek commented 1 year ago

Looks like your shell probably is not stripping the "" chars around the URL. Can you try -Dotel.exporter.otlp.traces.endpoint=http://otel-collector.dev.svc.cluster.local:4317 instead?

Spitfire1900 commented 1 year ago

This looks to have fixed issues, thank you @mateuszrzeszutek .

I'd like to leave to keep this issue open and or open a new one on handling double-quoted values in the -Dotel.exporter.otlp.traces.endpoint cmdline argument. Is that appropriate and is it a better fit to rename and modify the description of this issue or create a new one?

mateuszrzeszutek commented 1 year ago

I'd like to leave to keep this issue open and or open a new one on handling double-quoted values in the -Dotel.exporter.otlp.traces.endpoint cmdline argument.

I don't think that this is a responsibility of the OpenTelemetry SDK to be honest. The spec says that The endpoint MUST be a valid URL ..., and valid URLs do not include the quotes. (@jack-berg you might want to chime in here)

Spitfire1900 commented 1 year ago

Fair enough, if double quotes are required wrap it around the entire -Dkey=value pair instead, e.g. "-Dkey=val" instead of -Dkey="val".

jack-berg commented 1 year ago

I agree with @mateuszrzeszutek - the code receiving endpoint shouldn't be responsible for stripping double quotes.