Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RUM-5716 fix: propagate global Tracer tags to otel span attributes #2000

Merged
merged 3 commits into from
Aug 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# Unreleased

- [FIX] Propagate global Tracer tags to OpenTelemetry span attributes. See [#2000][]
- [IMPROVEMENT] Send retry information with network requests (eg. retry_count, last_failure_status and idempotency key). See [#1991][]

# 2.16.0 / 20-08-2024
Expand Down Expand Up @@ -747,6 +748,7 @@ Release `2.0` introduces breaking changes. Follow the [Migration Guide](MIGRATIO
[#1967]: https://github.com/DataDog/dd-sdk-ios/pull/1967
[#1973]: https://github.com/DataDog/dd-sdk-ios/pull/1973
[#1988]: https://github.com/DataDog/dd-sdk-ios/pull/1988
[#2000]: https://github.com/DataDog/dd-sdk-ios/pull/2000
[#1991]: https://github.com/DataDog/dd-sdk-ios/pull/1991
[@00fa9a]: https://github.com/00FA9A
[@britton-earnin]: https://github.com/Britton-Earnin
Expand Down
1 change: 1 addition & 0 deletions Datadog/Example/ExampleAppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ class ExampleAppDelegate: UIResponder, UIApplicationDelegate {
// Enable Trace
Trace.enable(
with: Trace.Configuration(
tags: ["testing-tag": "my-value"],
networkInfoEnabled: true,
customEndpoint: Environment.readCustomTraceURL()
)
Expand Down
8 changes: 7 additions & 1 deletion DatadogTrace/Sources/OpenTelemetry/OTelSpan.swift
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,13 @@ internal class OTelSpan: OpenTelemetryApi.Span {
isRecording = false
tags = attributes.tags

// There is no need to lock here, because `DDSpan` is thread-safe
// set global tags
for (key, value) in tracer.tags {
ddSpan.setTag(key: key, value: value)
}

// set local tags
// local takes precedence over global
for (key, value) in tags {
ddSpan.setTag(key: key, value: value)
}
Expand Down
36 changes: 36 additions & 0 deletions DatadogTrace/Tests/OpenTelemetry/OTelSpanTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,42 @@ final class OTelSpanTests: XCTestCase {
DDAssertDictionariesEqual(recordedSpan.tags, expectedTags)
}

func testSetGlobalAttribute() throws {
// Given
let tracer: DatadogTracer = .mockWith(
featureScope: featureScope,
tags: [
"global": "keep_me",
"key3": "replace_me"
]
)

let span = tracer.spanBuilder(spanName: "Span").startSpan()

// When
span.setAttribute(key: "key", value: .bool(true))
span.setAttribute(key: "key2", value: .string("value2"))
span.setAttribute(key: "key3", value: .int(3))
span.setAttribute(key: "key4", value: .double(4.0))

span.end()

// Then
let recordedSpans = try featureScope.spanEventsWritten()
XCTAssertEqual(recordedSpans.count, 1)
let recordedSpan = recordedSpans.first!
let expectedTags =
[
"global": "keep_me",
"key": "true",
"key2": "value2",
"key3": "3",
"key4": "4.0",
"span.kind": "internal",
]
DDAssertDictionariesEqual(recordedSpan.tags, expectedTags)
}

func testStatus_whenStatusIsNotSet() throws {
// Given
let tracer: DatadogTracer = .mockWith(featureScope: featureScope)
Expand Down