Skip to content

OpenTracing Bridge: allow more generic carriers#2141

Closed
bboreham wants to merge 6 commits intoopen-telemetry:mainfrom
bboreham:ot-bridge-carrier
Closed

OpenTracing Bridge: allow more generic carriers#2141
bboreham wants to merge 6 commits intoopen-telemetry:mainfrom
bboreham:ot-bridge-carrier

Conversation

@bboreham
Copy link
Copy Markdown
Contributor

@bboreham bboreham commented Jul 29, 2021

Instead of insisting that the carrier is an HTTPHeaders, cast it or adapt it to the interface we need - TextMapCarrier.

It's a bit long-winded to wrap the read and write side separately, but this gives maximum flexibility.

Fixes #2137 - @kvrhdn has used this fork to create a working program.

@codecov
Copy link
Copy Markdown

codecov Bot commented Jul 29, 2021

Codecov Report

Merging #2141 (8c48780) into main (1884de2) will increase coverage by 0.2%.
The diff coverage is 78.7%.

Impacted file tree graph

@@           Coverage Diff           @@
##            main   #2141     +/-   ##
=======================================
+ Coverage   75.7%   75.9%   +0.2%     
=======================================
  Files        178     178             
  Lines      11703   11740     +37     
=======================================
+ Hits        8864    8922     +58     
+ Misses      2614    2584     -30     
- Partials     225     234      +9     
Impacted Files Coverage Δ
bridge/opentracing/bridge.go 53.1% <78.7%> (+9.5%) ⬆️
sdk/trace/batch_span_processor.go 80.2% <0.0%> (-1.0%) ⬇️
exporters/jaeger/jaeger.go 91.1% <0.0%> (+0.8%) ⬆️

@yvrhdn
Copy link
Copy Markdown
Contributor

yvrhdn commented Jul 29, 2021

I can confirm this fixes our issue, propagation context can be injected and extracted without error now 🙂

Comment thread bridge/opentracing/bridge.go
Copy link
Copy Markdown
Contributor

@MrAlias MrAlias left a comment

Choose a reason for hiding this comment

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

Thanks for the contribution, it is definitely welcomed as we ultimately want to support more than just HTTP carriers for the OT bridge.

These changes need to include tests. Primarily the tests need to ensure behavior of the introduced types are preserved.

Comment thread bridge/opentracing/bridge.go
Comment thread bridge/opentracing/bridge.go Outdated
Comment thread bridge/opentracing/bridge.go Outdated
Comment thread bridge/opentracing/bridge.go Outdated
Comment thread bridge/opentracing/bridge.go Outdated
@hickeyma
Copy link
Copy Markdown
Contributor

Ping @bboreham. Rebase needed and some feedback to look at.

@bboreham
Copy link
Copy Markdown
Contributor Author

Ack. It hasn't been high enough up my priority list lately.

Instead of insisting that the carrier is an HTTPHeaders, cast it
or adapt it to the interface we need - TextMapCarrier.

Signed-off-by: Bryan Boreham <bjboreham@gmail.com>
Suggested by Tyler Yahn <MrAlias@users.noreply.github.com>

Signed-off-by: Bryan Boreham <bjboreham@gmail.com>
Signed-off-by: Bryan Boreham <bjboreham@gmail.com>
Values stored in http.Header get title-cased, i.e. `traceparent` will
turn into `Traceparent`. Since HTTPHeadersCarrier.ForeachKey does not
undo this change, special-case that one type with a different wrapper
that will allow the value to be fetched.

Signed-off-by: Bryan Boreham <bjboreham@gmail.com>
This is not currently used in normal functioning of Inject and Extract,
but might get used in future so give it some testing now.

Test adapted from `open-telemetry/opentelemetry-go/propagation/propagation_test.go`

Signed-off-by: Bryan Boreham <bjboreham@gmail.com>
@bboreham bboreham force-pushed the ot-bridge-carrier branch from 205fd52 to 344c66b Compare April 18, 2022 11:02
@bboreham
Copy link
Copy Markdown
Contributor Author

Rebased and added unit tests for the Inject/Extract functionality added in this PR.

Note that ot.HTTPHeadersCarrier needs special treatment - Set() modifies the keys to meet HTTP header expectations - so we can't use the generic wrapper I added in that case.

It appears baggage was never propagated by BridgeTracer, so that is not included in the test.

Signed-off-by: Bryan Boreham <bjboreham@gmail.com>
@Aneurysm9
Copy link
Copy Markdown
Member

Does #2911 meet the needs here, or is there more required?

@bboreham
Copy link
Copy Markdown
Contributor Author

bboreham commented Jul 10, 2022

Does #2911 meet the needs here

Strictly no, however I think #2911 makes it easier to work around the deficiency.

Perhaps you will update the doc says it should work with TextMapWriter?
EDIT that doc is in OpenTracing so I realise OpenTelemetry would not update it.

Do you have any response to #2141 (comment) ?

@zalegrala
Copy link
Copy Markdown

@MrAlias Do you have any further feedback for this PR please?

return ot.ErrUnsupportedFormat
}
hhcarrier, ok := carrier.(ot.HTTPHeadersCarrier)
// If carrier implements the required interface directly, use that
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggested change
// If carrier implements the required interface directly, use that
// If carrier implements the required interface directly, use that.

tmCarrier, ok := carrier.(propagation.TextMapCarrier)
if !ok {
return ot.ErrInvalidCarrier
tmWriter, ok := carrier.(ot.TextMapWriter) // otherwise see if we can wrap it
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggested change
tmWriter, ok := carrier.(ot.TextMapWriter) // otherwise see if we can wrap it
tmWriter, ok := carrier.(ot.TextMapWriter) // Otherwise, see if we can wrap it.

@dmathieu
Copy link
Copy Markdown
Member

Closing this as stale.
This is not to say the proposal cannot be accepted, but the PR had change suggestions that were not applied in 2 years. And getting this ready to ship now would also require fixing several conflicts.

@dmathieu dmathieu closed this Jul 17, 2024
@zhihali
Copy link
Copy Markdown
Contributor

zhihali commented Aug 14, 2024

Hey @bboreham, if you stop working on this, can I take over it?

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.

OpenTracing bridge: BridgeTracer.Inject errors with ErrInvalidCarrier

8 participants