Skip to content

OTEL reserved attributes are not applied if using setAttribute(AttributeKey<T> key...) #2935

Description

@paolorotolo

Describe the bug

When using OpenTelemetry implementation, reserved custom attributes (like "operation.name") are not applied when passing an AttributeKey instead of a String key.

For example, the following code works:

spanBuilder.setAttribute("operation.name", "op_name")

The following code instead doesn't:

spanBuilder.setAttribute(stringKey("operation.name"), "op_name")

As a result of this, it's impossible to use spanBuilder.setAllAttributes(...) since internally it iterates over a list of AttributeKey<T>, ignoring any reserved key passed in the Map.

Reproduction steps

val spanBuilder: SpanBuilder = otelTracer.spanBuilder("name")
// This handles correctly the reserved attribute "operation.name". On Datadog the operation name will be "op_name"
spanBuilder.setAttribute("operation.name", "op_name")

// This ignores the reserved attributes. On Datadog the operation name with be the default "internal"
spanBuilder.setAttribute(stringKey("operation.name"), "op_name")

// This also ignores the reserved attributes.
val attributes = Attributes.builder().put("operation.name", "op_name").build()
spanBuilder.setAllAttributes(attributes)

Logcat logs

No response

Expected behavior

Reserved attributes should be handled in all cases.

Affected SDK versions

3.1.0

Latest working SDK version

none

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions