dd-trace-java icon indicating copy to clipboard operation
dd-trace-java copied to clipboard

Allow specifying a readable service name for databases when the JDBC url has IP Address

Open sriraamas opened this issue 6 months ago • 10 comments

In our application, we use IP address in the JDBC url to connect to our database, like:

jdbc://10.4.2.1:3306/test_database

This means that the service name is 10.4.2.1 when I leverage trace.db.client.split-by-host configuration.

However, we would like to specify the service name for this database as a connection parameter to jdbc like:

jdbc://10.4.2.1:3306/test_database?serviceName=user-writer-instance.db.com

Currently, the serverName parameter is lost during runtime because its overridden by the actual host of the jdbc url, which is 10.4.2.1

sriraamas avatar Jan 18 '24 01:01 sriraamas

Hi @sriraamas. I believe you should be able to achieve this by utilizing service mapping (dd.service.mapping) to explicitly set the names for your services. https://docs.datadoghq.com/tracing/trace_collection/library_config/java/#configuration-options

nayeem-kamal avatar Jan 18 '24 14:01 nayeem-kamal

I assume you are recommending using service mapping to map mysql to user-writer-instance.db.com I have looked into this and it doesn't work for us in two situations:

  1. One of our services connects to many database hosts and I would like each database host to appear as a separate service in APM
  2. We have each service using both reader hosts and writer hosts and I would like each host to be a separate service in APM

sriraamas avatar Jan 18 '24 17:01 sriraamas

Hi @sriraamas, could you try using dd.service.mapping to map the IP address in addition to using trace.db.client.split-by-host? The resulting properties would be

-Ddd.trace.db.client.split-by-host=TRUE -Ddd.service.mapping=10.4.2.1:user-writer-instance.db.com

bm1549 avatar Jan 18 '24 20:01 bm1549

fwiw, I verified that this works. The workaround recommended works but it is a lot of additional work.

sriraamas avatar Jan 19 '24 00:01 sriraamas

It is also somewhat problematic because the ip to name mapping must be know at startup time.

The reason we use ip addresses instead of a domain name is so that we can quickly detect if the DNS changed, and properly drain existing connections. But that means we don't necessarily know the mapping initially.

(I work with sriraamas)

tmccombs avatar Jan 19 '24 03:01 tmccombs

@sriraamas @tmccombs another option to try which can vary based on your setup is to use the option dd.trace.db.client.split-by-instance

This will change the service name being used to be the instance, which can vary based on the connection string you're using. You may be able to use that in conjunction with dd.service.mapping to get the desired behavior

bm1549 avatar Jan 19 '24 21:01 bm1549

In our case, by default, db-instance is set to the database being used. so are you saying, if its user database in the user-db host, do service.mapping from user to user.db.com ? The downside there is, we have both reader and writer hosts being used on the same database instance. so, I can't know if its reader/writer.

sriraamas avatar Jan 19 '24 23:01 sriraamas

Thanks for sharing that

Given the information you provided, it indicates that dd.trace.split-by-tags may be beneficial for you. You can use it to identify and rename the service name for reader and writer spans. Can you try that out and let me know if it solves your problem?

bm1549 avatar Jan 22 '24 18:01 bm1549

I am not certain how to set a tag for JDBC Auto instrumentation. I thought that's not possible.

sriraamas avatar Jan 22 '24 19:01 sriraamas

Hi @sriraamas thank you for your patience. I'm reaching out to confirm that, without custom instrumentation, you are correct

In this case, we'll attach this issue to a feature request internally and consider it as part of our long-term roadmap. Please use the options specified above until then

bm1549 avatar Jan 25 '24 16:01 bm1549