question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[🐛 Bug]: Issues when using selenium-remote-driver and opentelemetry sdk

See original GitHub issue

What happened?

Selenium java remote web driver currently initialize OptenTelemetrySdk instance by itself and that makes impossible to use pre configured OpenTelemetry instances (exception thrown).

Also it’s impossible to use opentelementry-agent with selenium.

How can we reproduce the issue?

// configure opentelementry instance and set it as global
OpenTelemetrySdk.builder()
     .setTracerProvider(sdkTracerProvider)                 
     .setPropagators(ContextPropagators.create(W3CTraceContextPropagator.getInstance()))
     .buildAndRegisterGlobal();

// then try use selenium
new RemoteWebDriver(remoteAddress, capabilities)

To reproduce issue with agent add “-javaagent:path/to/opentelemetry-javaagent.jar” to project using selenium remote and JPMS.

Relevant log output

Wrapped by: java.lang.IllegalStateException: GlobalOpenTelemetry.set has already been called. GlobalOpenTelemetry.set must be called only once before any calls to GlobalOpenTelemetry.get. If you are using the OpenTelemetrySdk, use OpenTel
emetrySdkBuilder.buildAndRegisterGlobal instead. Previous invocation set to cause of this exception.
        at io.opentelemetry.api@1.9.0/io.opentelemetry.api.GlobalOpenTelemetry.set(GlobalOpenTelemetry.java:84)
        at io.opentelemetry.sdk.autoconfigure@1.9.0-alpha/io.opentelemetry.sdk.autoconfigure.OpenTelemetrySdkAutoConfiguration.newOpenTelemetrySdk(OpenTelemetrySdkAutoConfiguration.java:113)
        at io.opentelemetry.sdk.autoconfigure@1.9.0-alpha/io.opentelemetry.sdk.autoconfigure.AutoConfiguredOpenTelemetrySdkBuilder.build(AutoConfiguredOpenTelemetrySdkBuilder.java:177)
        at io.opentelemetry.sdk.autoconfigure@1.9.0-alpha/io.opentelemetry.sdk.autoconfigure.AutoConfiguredOpenTelemetrySdk.initialize(AutoConfiguredOpenTelemetrySdk.java:29)
        at io.opentelemetry.sdk.autoconfigure@1.9.0-alpha/io.opentelemetry.sdk.autoconfigure.OpenTelemetrySdkAutoConfiguration.initialize(OpenTelemetrySdkAutoConfiguration.java:47)
        at org.seleniumhq.selenium.remote_driver/org.openqa.selenium.remote.tracing.opentelemetry.OpenTelemetryTracer.createTracer(OpenTelemetryTracer.java:77)
        at org.seleniumhq.selenium.remote_driver/org.openqa.selenium.remote.tracing.opentelemetry.OpenTelemetryTracer.getInstance(OpenTelemetryTracer.java:59)
        at org.seleniumhq.selenium.remote_driver/org.openqa.selenium.remote.RemoteWebDriver.createTracedExecutorWithTracedHttpClient(RemoteWebDriver.java:151)
        at org.seleniumhq.selenium.remote_driver/org.openqa.selenium.remote.RemoteWebDriver.<init>(RemoteWebDriver.java:146)

Trace when using with java agent:

java.lang.reflect.InvocationTargetException
	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 io.opentelemetry.javaagent.bootstrap.AgentInitializer.initialize(AgentInitializer.java:40)
	at io.opentelemetry.javaagent.OpenTelemetryAgent.agentmain(OpenTelemetryAgent.java:51)
	at io.opentelemetry.javaagent.OpenTelemetryAgent.premain(OpenTelemetryAgent.java:44)
	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.lang.NoSuchMethodError: 'io.opentelemetry.sdk.resources.Resource io.opentelemetry.sdk.resources.Resource.create(io.opentelemetry.javaagent.shaded.io.opentelemetry.api.common.Attributes)'
	at io.opentelemetry.javaagent.tooling.AutoVersionResourceProvider.createResource(AutoVersionResourceProvider.java:26)
	at io.opentelemetry.sdk.autoconfigure@1.10.0-alpha/io.opentelemetry.sdk.autoconfigure.ResourceConfiguration.configureResource(ResourceConfiguration.java:42)
	at io.opentelemetry.sdk.autoconfigure@1.10.0-alpha/io.opentelemetry.sdk.autoconfigure.AutoConfiguredOpenTelemetrySdkBuilder.build(AutoConfiguredOpenTelemetrySdkBuilder.java:186)
	at io.opentelemetry.javaagent.tooling.OpenTelemetryInstaller.installAgentTracer(OpenTelemetryInstaller.java:63)
	at io.opentelemetry.javaagent.tooling.OpenTelemetryInstaller.beforeAgent(OpenTelemetryInstaller.java:35)
	at io.opentelemetry.javaagent.tooling.AgentInstaller.runBeforeAgentListeners(AgentInstaller.java:192)
	at io.opentelemetry.javaagent.tooling.AgentInstaller.installBytebuddyAgent(AgentInstaller.java:122)
	at io.opentelemetry.javaagent.tooling.AgentInstaller.installBytebuddyAgent(AgentInstaller.java:100)
	... 13 more

Selenium version

java 4.1.0

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:10 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
ham1commented, Jan 31, 2022

Ok, thanks, I’ll try to get a smaller repro this afternoon and raise tomorrow. I’ll also try to set enableTracing=false when creating the RemoteWebDriver

1reaction
diemolcommented, Jan 31, 2022

that seems to be a different issue, a new bug report would be nice

Read more comments on GitHub >

github_iconTop Results From Across the Web

How we used OpenTelemetry to fix a bug in OpenTelemetry
We recently had an issue that we were able to fix by using one feature of OpenTelemetry to identify the root cause of...
Read more >
Java Selenium Error: Exception in thread "main" java.lang ...
I am just trying to run a basic webdriver program using the IntelliJ IDE but I get all these errors upon running ...
Read more >
An Essential Guide to OpenTelemetry - Logz.io
Start your journey with OpenTelemetry to generate and collect traces, metrics and logs from your system, with this useful tutorial and reference hub....
Read more >
OpenTelemetry integration | APM User Guide [8.5] - Elastic
OpenTelemetry is a set of APIs, SDKs, tooling, and integrations that enable the ... and supports various logging levels: debug , info ,...
Read more >
Adopting Observability with OpenTelemetry - New Relic
The status of signal/telemetry type, such as the API specification. The status of the SDK for the programming languages used by the application....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found