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-1836 feat(otel-tracer): conform to otel Tracer, SpanBuilder and Span #1611

Merged
merged 13 commits into from
Jan 5, 2024

Conversation

ganeshnj
Copy link
Contributor

@ganeshnj ganeshnj commented Jan 2, 2024

Things that have fatal error - will be implemented in future PRs

What and why?

Otel tracer implementation.

How?

This PR conforms to Tracer, SpanBuilder and Span protocols from otel.

We are not trying to reinventing the wheel but rather use the existing implementation and make it complaint to otel. During the otel API usage, we keep a internal copy of the span which is a datadog span. When a span is closed, all the otel data is mapped to the datadog span and reported.

Things that are supported

  • Make the public API to get a tracer return both OTTracer and Otel Tracer.
  • start and end span APIs
  • Parent specific APIs - span parent
  • Attribute APIs - akin to tags in datadog
  • name API - akin to operation name in datadog

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

Custom CI job configuration (optional)

  • Run unit tests for Core, RUM, Trace, Logs, CR and WVT
  • Run unit tests for Session Replay
  • Run integration tests
  • Run smoke tests
  • Run tests for tools/

@ganeshnj ganeshnj changed the title RUM-1836 feat(otel-tracer): scaffold conformance to otel Tracer, SpanBuilder and Span RUM-1836 feat(otel-tracer): conform to otel Tracer, SpanBuilder and Span Jan 2, 2024
@ganeshnj ganeshnj force-pushed the ganeshnj/feat/otel-tracer-conform branch from 7baf47a to deb6977 Compare January 2, 2024 13:47
Base automatically changed from ganeshnj/feat/otel-tracer-spm-dep to ganeshnj/feat/otel-tracer January 2, 2024 17:10
@ganeshnj ganeshnj force-pushed the ganeshnj/feat/otel-tracer-conform branch from deb6977 to 6e552e1 Compare January 3, 2024 09:42
@ganeshnj ganeshnj changed the base branch from ganeshnj/feat/otel-tracer to ganeshnj/feat/otel-tracer-project-dependency January 3, 2024 13:34
@ganeshnj ganeshnj force-pushed the ganeshnj/feat/otel-tracer-conform branch from b8700b0 to 95d5382 Compare January 3, 2024 13:40
@datadog-datadog-prod-us1
Copy link

datadog-datadog-prod-us1 bot commented Jan 3, 2024

Datadog Report

Branch report: ganeshnj/feat/otel-tracer-conform
Commit report: 2eab9ac
Test service: dd-sdk-ios

✅ 0 Failed, 2727 Passed, 0 Skipped, 12m 27.49s Wall Time
⬇️ Test Sessions change in coverage: 7 decreased, 3 increased, 4 no change

⬇️ Code Coverage Decreases vs Default Branch (7)

This report shows up to 5 code coverage decreases.

  • test DatadogTraceTests iOS (-6.88%) - Details
  • test DatadogTraceTests tvOS (-6.78%) - Details
  • test DatadogCoreTests tvOS (-4.17%) - Details
  • test DatadogCoreTests iOS (-3.32%) - Details
  • test DatadogCrashReportingTests tvOS (-0.02%) - Details
  • test DatadogCrashReportingTests iOS (-0.02%) - Details
  • test DatadogLogsTests iOS (-0.01%) - Details


internal struct DDNoopGlobals {
static let tracer = DDNoopTracer()
static let span = DDNoopSpan()
static let context = DDNoopSpanContext()
}

internal struct DDNoopTracer: OTTracer {
internal class DDNoopTracer: OTTracer, OpenTelemetryApi.Tracer {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

OpenTelemetryApi.Tracer is class only protocol.

@ganeshnj ganeshnj marked this pull request as ready for review January 3, 2024 16:00
@ganeshnj ganeshnj requested review from a team as code owners January 3, 2024 16:00
Base automatically changed from ganeshnj/feat/otel-tracer-project-dependency to ganeshnj/feat/otel-tracer January 3, 2024 16:29
@ganeshnj ganeshnj force-pushed the ganeshnj/feat/otel-tracer-conform branch from 8f37dd0 to 84a7f78 Compare January 3, 2024 16:30
@ganeshnj ganeshnj marked this pull request as draft January 4, 2024 08:18
@ganeshnj ganeshnj marked this pull request as ready for review January 4, 2024 09:42
Copy link
Member

@maciejburda maciejburda left a comment

Choose a reason for hiding this comment

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

Good stuff and decent coverage! 🙇

Left some minor comments :)

func addEvent(name: String, attributes: [String: OpenTelemetryApi.AttributeValue], timestamp: Date) {}

func end() {
OpenTelemetry.instance.contextProvider.removeContextForSpan(self)
Copy link
Member

Choose a reason for hiding this comment

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

just curious: is there a use case for noop to have this implementation?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

probably never, unless someone adds the span manually to the context.

There is an API for it OpenTelemetry.instance.contextProvider.setActiveSpan(span)

Comment on lines +151 to +153
var description: String {
return "OTelSpan"
}
Copy link
Member

Choose a reason for hiding this comment

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

Maybe we can dump a little bit more data. Will be useful when debugging with print

Copy link
Contributor Author

Choose a reason for hiding this comment

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

that's debugDescription

https://developer.apple.com/documentation/swift/customdebugstringconvertible

I can put a separate PR for a pretty print.

Comment on lines +11 to +14
extension OpenTelemetryApi.SpanId {
/// Converts OpenTelemetry `SpanId` to Datadog `SpanID`.
/// - Returns: Datadog `SpanID`.
func toDatadog() -> SpanID {
Copy link
Member

Choose a reason for hiding this comment

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

Having Id and ID is a little bit awkward :/

Is there any way we could easily normalise class naming to one fashion?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

that's otel (SpanId) vs datadog (SpanID), given these are public types - we don't want to change them.

DatadogTrace/Tests/OpenTelemetry/OTelSpanTests.swift Outdated Show resolved Hide resolved
Copy link
Member

@ncreated ncreated left a comment

Choose a reason for hiding this comment

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

Nice to see that it fits the existing DatadogTracer 👌. I left few questions and pointed to some blockers on thread safety.

DatadogTrace/Sources/DatadogTracer.swift Outdated Show resolved Hide resolved
DatadogTrace/Sources/OpenTelemetry/OTelNoOpSpan.swift Outdated Show resolved Hide resolved
DatadogTrace/Sources/OpenTelemetry/OTelSpan.swift Outdated Show resolved Hide resolved
Comment on lines +11 to +17
var tracer: DatadogTracer
var spanName: String
var spanKind = SpanKind.client
var attributes: [String: OpenTelemetryApi.AttributeValue]
var startTime: Date?
var active: Bool
var parent: Parent
Copy link
Member

Choose a reason for hiding this comment

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

blocking/ It's all a mutable state modified by user and it lacks synchronisation. @ReadWriteLock might do the job.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I would argue that this needs to thread safe given the purpose of the builder. When a customer is building the span using the SpanBuilder it must be all done from the same thread. Once they start the span, it can be move around different threads.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

DatadogTrace/Sources/OpenTelemetry/OTelSpan.swift Outdated Show resolved Hide resolved
func startSpan() -> OpenTelemetryApi.Span {
let parentContext = parent.context()
let traceId: TraceId
let spanId = SpanId.random()
Copy link
Member

Choose a reason for hiding this comment

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

suggestion/ Abstracting trace IDs generation to separate type might be handy in some unit tests.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

this is not required at this point - so going to keep as it is. We can refactor when needed.

DatadogTrace/Tests/OpenTelemetry/OTelSpanTests.swift Outdated Show resolved Hide resolved
DatadogTrace/Tests/OpenTelemetry/OTelSpanTests.swift Outdated Show resolved Hide resolved
DatadogTrace/Sources/OpenTelemetry/OTelSpan.swift Outdated Show resolved Hide resolved
@ganeshnj ganeshnj requested a review from ncreated January 5, 2024 12:26
Copy link
Member

@ncreated ncreated left a comment

Choose a reason for hiding this comment

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

Looks good 👍, I left only one question.

Please be aware of the impact that #1615 may have on this work.

DatadogTrace/Sources/OpenTelemetry/OTelSpan.swift Outdated Show resolved Hide resolved
@ganeshnj
Copy link
Contributor Author

ganeshnj commented Jan 5, 2024

Looks good 👍, I left only one question.

Please be aware of the impact that #1615 may have on this work.

Yes, I'm aware of that. Had a glance on your PR. Thanks for headsup.

@ganeshnj ganeshnj merged commit 43ac91a into ganeshnj/feat/otel-tracer Jan 5, 2024
8 checks passed
@ganeshnj ganeshnj deleted the ganeshnj/feat/otel-tracer-conform branch January 5, 2024 16:50
@ncreated ncreated mentioned this pull request May 31, 2024
8 tasks
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