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

apply configured service name mapping to DBM-injected `dddbs`

Open vandonr opened this issue 1 year ago • 2 comments

What Does This Do

The injected dddbs tag should respect service mapping.

For single statements, we create the span and inject the comment in the same instrumentation, so everything is well (code) However, for prepared statements, it's more complicated, because it happens in 2 steps:

  • step 1: the call to prepare is instrumented, this is where we inject the comment, it's done in DBMCompatibleConnectionInstrumentation
  • step 2: the call to execute is instrumented, this is when the command is actually run, so this is where we create the span (this is done in AbstractPreparedStatementInstrumentation) Thus, we don't have the span yet when we do the injection for prepared statements.

Service mapping logic was only applied when a service name is set in a span: https://github.com/DataDog/dd-trace-java/blob/ad66ae831ff35f39b40065180db609c003dda470/dd-trace-core/src/main/java/datadog/trace/core/DDSpanContext.java#L398-L401 so if we get a service name not from a span, the mapping wouldn't be applied to it.

To fix this, I'm repeating the logic that is found here: https://github.com/DataDog/dd-trace-java/blob/0779b79b4acb05a10acf47b1ac1570a27f2c1df7/dd-trace-core/src/main/java/datadog/trace/core/PendingTrace.java#L173

@mcculls helped with the code to retrieve the current trace's config snapshot.

Jira ticket: APMS-12191

vandonr avatar May 22 '24 14:05 vandonr

Would it be possible to add tests?

amarziali avatar May 23 '24 09:05 amarziali

Would it be possible to add tests?

yes I'll look into it. For now, it seems there might be some tests failing, that I cannot reproduce locally :( I was hoping to draw inspiration from there.

vandonr avatar May 23 '24 09:05 vandonr