open-telemetry / open-telemetry/opentelemetry-java-instrumentation
[BUG] StringIndexOutOfBoundsException when parsing MySQL Replication mode URL in JDBC instrumentation
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 2.6k
- Forks
- 1.2k
- Avg merge
- 2d 18h
- Merged PRs (30d)
- 228
Description
Describe the bug
When using the MySQL driver Replication mode, JDBC insert pile trying to parse the internal generated URL **internally_generated** because dbLoc = -1 cause StringIndexOutOfBoundsException anomalies
Steps to reproduce
I've created a complete reproduction case with: https://github.com/wl2027/otel-java-examples/tree/main/mysql-replication-demo
Expected behavior
- fix the exception (at present)
- extract real host info (later)
I think it's necessary to add instrumentation to the MySQL driver to capture the actual url and host information. Only in this way can we construct an accurate service topology diagram.
Actual behavior
- stack trace
[otel.javaagent 2025-06-27 17:50:00:042 +0800] [Druid-ConnectionPool-Create-866045247] DEBUG io.opentelemetry.javaagent.shaded.instrumentation.jdbc.internal.JdbcConnectionUrlParser - Error parsing URL
java.lang.StringIndexOutOfBoundsException: String index out of range: -1
at java.lang.String.substring(String.java:1967)
at io.opentelemetry.javaagent.shaded.instrumentation.jdbc.internal.JdbcConnectionUrlParser$6.doParse(JdbcConnectionUrlParser.java:355)
at io.opentelemetry.javaagent.shaded.instrumentation.jdbc.internal.JdbcConnectionUrlParser$5.doParse(JdbcConnectionUrlParser.java:281)
at io.opentelemetry.javaagent.shaded.instrumentation.jdbc.internal.JdbcConnectionUrlParser.parse(JdbcConnectionUrlParser.java:943)
at io.opentelemetry.javaagent.shaded.instrumentation.jdbc.internal.JdbcUtils.computeDbInfo(JdbcUtils.java:109)
at io.opentelemetry.javaagent.shaded.instrumentation.jdbc.internal.JdbcUtils.extractDbInfo(JdbcUtils.java:87)
at io.opentelemetry.javaagent.shaded.instrumentation.jdbc.internal.DbRequest.create(DbRequest.java:37)
- arthas
[arthas@1]$ watch io.opentelemetry.javaagent.shaded.instrumentation.jdbc.internal.JdbcConnectionUrlParser\$* doParse '{params,returnObj}' -x 3 -n 5
Press Q or Ctrl+C to abort.
Affect(class count: 20 , method count: 20) cost in 471 ms, listenerId: 1
method=io.opentelemetry.javaagent.shaded.instrumentation.jdbc.internal.JdbcConnectionUrlParser$6.doParse location=AtExceptionExit
ts=2025-06-27 22:38:46.523; [cost=0.043679ms] result=@ArrayList[
@Object[][
@String[**internally_generated**17489615264691**],
@Builder[
system=@String[mysql],
subtype=null,
shortUrl=null,
user=null,
name=null,
db=@String[**internally_generated**17489615264619**],
host=@String[localhost],
port=@Integer[3306],
],
],
null,
]
method=io.opentelemetry.javaagent.shaded.instrumentation.jdbc.internal.JdbcConnectionUrlParser$5.doParse location=AtExceptionExit
ts=2025-06-27 22:38:46.524; [cost=0.847149ms] result=@ArrayList[
@Object[][
@String[mysql:loadbalance://**internally_generated**1748961526469**],
@Builder[
system=@String[mysql],
subtype=null,
shortUrl=null,
user=null,
name=null,
db=@String[**internally_generated**1748961526469**],
host=@String[localhost],
port=@Integer[3306],
],
],
null,
]
Javaagent or library instrumentation version
v2.17.0
Environment
JDK: jdk8+
OS: macos
Additional context
recurrence #2741
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with JdbcConnectionUrlParser.java, especially the doParse path shown in the stack trace, and run the mysql-replication-demo reproduction. Trace handling of the internally generated replication URL and confirm the exception is avoided; accurate host extraction is identified as later work in the issue.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java, mysql
- Domain
- backend, databases
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100