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

RUMM-3374 fix: Manual trace injection APIs are not available in DatadogTrace #1415

Merged

Conversation

ncreated
Copy link
Member

@ncreated ncreated commented Aug 16, 2023

What and why?

🐞 This PR fixes the problem of *HTTPHeaderWriter APIs being not available after importing DatadogTrace in 2.0.0.

It was a miss during 1.x2.x APIs migration. As a workaround, users had to import DatadogInternal directly into their code. These APIs should be available with only import DatadogTrace.

How?

The actual fix are following exports in DatadogTrace module:

@_exported import class DatadogInternal.HTTPHeadersWriter
@_exported import class DatadogInternal.B3HTTPHeadersWriter
@_exported import class DatadogInternal.W3CHTTPHeadersWriter

Extra work done:

Screenshot 2023-08-16 at 13 36 19

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
  • Run integration tests
  • Run smoke tests

@ncreated ncreated self-assigned this Aug 16, 2023
@ncreated ncreated changed the title RUMM-3374 fix: Manual trace injection APIs are not exposed in DatadogTrace RUMM-3374 fix: Manual trace injection APIs are not available in DatadogTrace Aug 16, 2023
@ncreated ncreated force-pushed the ncreated/RUMM-3374/fix-manual-trace-injection-impossible branch from 9cd8347 to 3afe2ea Compare August 16, 2023 14:34
@ncreated ncreated marked this pull request as ready for review August 16, 2023 14:45
@ncreated ncreated requested a review from a team as a code owner August 16, 2023 14:45
Comment on lines 9 to 26
/// The `OTelHTTPHeadersWriter` should be used to inject trace propagation headers to
/// the network requests send to the backend instrumented with Open Telemetry.
/// The injected headers conform to [Open Telemetry](https://github.com/openzipkin/b3-propagation) standard.
/// The `OTelHTTPHeadersWriter` class facilitates the injection of trace propagation headers into network requests
/// targeted at a backend expecting [B3 propagation format](https://github.com/openzipkin/b3-propagation).
///
/// Usage:
///
/// var request = URLRequest(...)
///
/// let writer = OTelHTTPHeadersWriter(injectEncoding: .single)
/// let span = DatadogTracer.shared().startSpan("network request")
/// writer.inject(spanContext: span.context)
/// let span = Tracer.shared().startRootSpan(operationName: "network request")
/// Tracer.shared().inject(spanContext: span.context, writer: writer)
///
/// writer.traceHeaderFields.forEach { (field, value) in
/// request.setValue(value, forHTTPHeaderField: field)
/// }
///
/// // call span.finish() when the request completes
///
///
public class OTelHTTPHeadersWriter: TracePropagationHeadersWriter {
Copy link
Member Author

Choose a reason for hiding this comment

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

💡 Even with these changes, I'm concerned about the OTelHTTPHeadersWriter name. OTel doesn't dictate this or that headers format and using "OTel" definitely does not imply B3-* headers. It should be B3HTTPHeadersWriter IMO (consistent with W3CHTTPHeadersWriter and bare HTTPHeadersWriter which uses x-datadog-* headers).

I'd be up for deprecating this symbol and renaming it accordingly. WDYT @ganeshnj @maciejburda @maxep ?

Copy link
Member

Choose a reason for hiding this comment

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

Yeah, I likeB3HTTPHeadersWriter.

Copy link
Member

Choose a reason for hiding this comment

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

Agreed :) B3* is technically more correct 👍

Copy link
Member Author

Choose a reason for hiding this comment

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

Renamed OTelHTTPHeaders* to B3HTTPHeaders* with deprecating the prior. See: 4a3819c

@datadog-datadog-prod-us1
Copy link

datadog-datadog-prod-us1 bot commented Aug 16, 2023

Datadog Report

Branch report: ncreated/RUMM-3374/fix-manual-trace-injection-impossible
Commit report: 99dbb48

dd-sdk-ios: 0 Failed, 0 New Flaky, 118 Passed, 0 Skipped, 2m 57.85s Wall Time

maciejburda
maciejburda previously approved these changes Aug 16, 2023
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.

Great stuff! I like renaming proposal

Comment on lines 9 to 26
/// The `OTelHTTPHeadersWriter` should be used to inject trace propagation headers to
/// the network requests send to the backend instrumented with Open Telemetry.
/// The injected headers conform to [Open Telemetry](https://github.com/openzipkin/b3-propagation) standard.
/// The `OTelHTTPHeadersWriter` class facilitates the injection of trace propagation headers into network requests
/// targeted at a backend expecting [B3 propagation format](https://github.com/openzipkin/b3-propagation).
///
/// Usage:
///
/// var request = URLRequest(...)
///
/// let writer = OTelHTTPHeadersWriter(injectEncoding: .single)
/// let span = DatadogTracer.shared().startSpan("network request")
/// writer.inject(spanContext: span.context)
/// let span = Tracer.shared().startRootSpan(operationName: "network request")
/// Tracer.shared().inject(spanContext: span.context, writer: writer)
///
/// writer.traceHeaderFields.forEach { (field, value) in
/// request.setValue(value, forHTTPHeaderField: field)
/// }
///
/// // call span.finish() when the request completes
///
///
public class OTelHTTPHeadersWriter: TracePropagationHeadersWriter {
Copy link
Member

Choose a reason for hiding this comment

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

Yeah, I likeB3HTTPHeadersWriter.

maxep
maxep previously approved these changes Aug 17, 2023
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.

Nice! Just for clarification: why only in DatadogTrace and not in DatadogRUM?

@ncreated
Copy link
Member Author

Nice! Just for clarification: why only in DatadogTrace and not in DatadogRUM?

It's because the current use of HeaderWriters requires a span and Tracer:

Tracer.shared().inject(spanContext: span.context)

so it won't make sense for RUM. Also, even if trace context is injected manually into request, there is currently no way to pass it to manually created RUM Resource for RUM <> APM correlation.

@ncreated ncreated dismissed stale reviews from maxep and maciejburda via 4a3819c August 18, 2023 07:00
@ncreated ncreated requested review from maxep and maciejburda August 18, 2023 07:11
…tion-impossible

* develop:
  REPLAY-1936 fix access levels
  Update CHANGELOG.md
  REPLAY-1936 add objective-c interface
maxep
maxep previously approved these changes Aug 18, 2023
@ncreated ncreated merged commit 12a92d3 into develop Aug 18, 2023
@ncreated ncreated deleted the ncreated/RUMM-3374/fix-manual-trace-injection-impossible branch August 18, 2023 13:01
@ncreated ncreated mentioned this pull request Aug 18, 2023
6 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