DataDog / dd-sdk-android

Datadog SDK for Android (Compatible with Kotlin and Java)
Apache License 2.0
155 stars 60 forks source link

Span resource name set with tag is not used #2374

Open paco-spr opened 22 hours ago

paco-spr commented 22 hours ago

Describe the bug

Using a tag to set the resource name does not work and instead shows up as the operation name in the datadog ui. This comes from a bug in this library and even has a TODO comment to resolve it. In DDSpanContext getResourceName does not read the "resource.name" set in the tags, but it does read it when returning a value for hasResourceName. You can work around this by casting the span to DDSpan and setting the resource name using span.setResourceName() but this seems like a bug in the library.

https://github.com/DataDog/dd-sdk-android/blob/b1d6ebb82d26299faa41195747198850dcef090d/features/dd-sdk-android-trace/src/main/java/com/datadog/trace/core/DDSpanContext.java#L404

Reproduction steps

import io.opentracing.util.GlobalTracer

val spanBuilder = GlobalTracer.get().build("operation_name")
spanBuilder.withTag("resource.name", "custom resource name")
spanBuilder.start().finish()

Logcat logs

No response

Expected behavior

No response

Affected SDK versions

2.14.0

Latest working SDK version

never

Did you confirm if the latest SDK version fixes the bug?

Yes

Kotlin / Java version

No response

Gradle / AGP version

No response

Other dependencies versions

No response

Device Information

No response

Other relevant information

No response

mariusc83 commented 18 hours ago

Hi @paco-spr , thank you for taking the time to repot this. This is indeed a bug in our library and indeed you could use the workaround (span as DDSpan).setResourceName to go around this problem. We are going to open a ticket on our end to fix this in the next SDK versions. On the other hand I am wondering if you've noticed our new release of OpenTelemetry support: https://docs.datadoghq.com/tracing/trace_collection/custom_instrumentation/android/otel/?tab=kotlin. I recommend you on the long term to try to switch to this new API as this will be better maintained in the future and this bug is not there in this newer implementation.

paco-spr commented 12 hours ago

Hi @paco-spr , thank you for taking the time to repot this. This is indeed a bug in our library and indeed you could use the workaround (span as DDSpan).setResourceName to go around this problem. We are going to open a ticket on our end to fix this in the next SDK versions. On the other hand I am wondering if you've noticed our new release of OpenTelemetry support: https://docs.datadoghq.com/tracing/trace_collection/custom_instrumentation/android/otel/?tab=kotlin. I recommend you on the long term to try to switch to this new API as this will be better maintained in the future and this bug is not there in this newer implementation.

I had not seen that. Thanks for confirming the bug and suggesting the new API we will update on our end as well.