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-8558 Update DatadogTrace to OTel API 1.13.0 #2217

Merged
merged 10 commits into from
Mar 5, 2025

Conversation

ncreated
Copy link
Member

@ncreated ncreated commented Mar 4, 2025

What and why?

📦 This PR updates DatadogTrace to use OpenTelemetryApi 1.13.0.

This addresses #2190.

How?

The new OpenTelemetryApi version was published in opentelemetry-swift-packages#27, and this PR integrates it into dd-sdk-ios.

Platform Versions Alignment

Since 1.6.0 (our previous OpenTelemetryApi dependency version), open-telemetry-swift introduced a breaking change in supported platforms, raising the minimum deployment targets from .iOS(11) and .tvOS(11) to .iOS(13) and .tvOS(13). Because our SDK supports .iOS(12) and .tvOS(12), this required adding a patch in Package.swift to conditionally adjust platforms when the OTEL_SWIFT environment variable is set. I used this as an opportunity to add comments and better document this flag. In our repository, this is leveraged in BenchmarkTests.

New OTelSpanBuilder APIs

This update introduces the following OTelSpanBuilder APIs. Their implementation in this PR follows otel-swift, delegating active span management to OpenTelemetry.instance.contextProvider:

func withActiveSpan<T>(_ operation: (any OpenTelemetryApi.SpanBase) throws -> T) rethrows -> T

func withActiveSpan<T>(_ operation: (any OpenTelemetryApi.SpanBase) async throws -> T) async rethrows -> T

This PR adds test coverage for these new APIs and also re-enables OTelSpanTests/testSetActive_givenParentSpan(), which was disabled in #1881 due to flaky performance. The updated OpenTelemetryApi refines active span management, so performance should now be stable.

New OTelSpan APIs

The update also introduces new OTelSpan APIs:

func recordException(_ exception: any OpenTelemetryApi.SpanException, attributes: [String: OpenTelemetryApi.AttributeValue], timestamp: Date)

func recordException(_ exception: any OpenTelemetryApi.SpanException, attributes: [String: OpenTelemetryApi.AttributeValue])

func recordException(_ exception: any OpenTelemetryApi.SpanException, timestamp: Date)

func recordException(_ exception: any OpenTelemetryApi.SpanException)

These APIs are not implemented in this PR because their proper implementation depends on the addEvent() API, which is not yet supported in our OTel integration.

Deprecated OTel APIs

The latest OpenTelemetryApi deprecates the following attribute array creation methods:

.stringArray(_:)
.boolArray(_:)
.intArray(_:)
.doubleArray(_:)

These have been replaced with a more uniform .array(.init(values: [])) API. This PR updates our test suite to use the new .array() format and removes dependencies on deprecated APIs.

Review checklist

  • Feature or bugfix MUST have appropriate tests (unit, integration)
  • Make sure each commit and the PR mention the Issue number or JIRA reference
  • Add CHANGELOG entry for user facing changes
  • Add Objective-C interface for public APIs (see our guidelines [internal]) and run make api-surface)

@ncreated ncreated self-assigned this Mar 4, 2025
@datadog-datadog-prod-us1
Copy link

Datadog Report

Branch report: ncreated/RUM-8558/update-otel-to-1.13.0
Commit report: ea7ca33
Test service: dd-sdk-ios

✅ 0 Failed, 321 Passed, 3499 Skipped, 53.01s Total duration (1m 42.98s time saved)

@ncreated ncreated marked this pull request as ready for review March 5, 2025 10:33
@ncreated ncreated requested review from a team as code owners March 5, 2025 10:33
Copy link
Contributor

@simaoseica-dd simaoseica-dd left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great work overall in this update to OTel 1.13.0 🎖️

Copy link
Member

@maxep maxep left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👌

Comment on lines +6 to +15
// If the `OTEL_SWIFT` environment variable is set, `dd-sdk-ios` will be compiled against `OpenTelemetryApi`
// from https://github.com/open-telemetry/opentelemetry-swift, which includes the full OpenTelemetry SDK.
// Otherwise, it will use our lightweight mirror from https://github.com/DataDog/opentelemetry-swift-packages.
//
// This split is driven by feedback from https://github.com/DataDog/dd-sdk-ios/issues/1877, where
// users reported that fetching the full OpenTelemetry SDK significantly increased dependency size.
//
// By using this environment variable, `dd-sdk-ios` consumers can choose whether to depend on the entire
// OpenTelemetry SDK or just the API. This remains necessary until OpenTelemetry officially separates
// the API and SDK packages (see https://github.com/open-telemetry/opentelemetry-swift/issues/486).
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice, thanks!

@ncreated ncreated merged commit 03efbbd into develop Mar 5, 2025
15 checks passed
@ncreated ncreated deleted the ncreated/RUM-8558/update-otel-to-1.13.0 branch March 5, 2025 13:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants