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

otelhttp: get tracer from current context if not set in constructor #873

Merged
merged 2 commits into from
Oct 29, 2021

Conversation

tonistiigi
Copy link
Contributor

When otelhttp is used as a Transport the traces should go to the parent span tracer by default. If custom TracerProvider is set then it is still used and if none is set then global one is used like it was before.

@Aneurysm9

Signed-off-by: Tonis Tiigi tonistiigi@gmail.com

Copy link
Member

@pellared pellared left a comment

Choose a reason for hiding this comment

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

I am not sure if there was any issue or discussion before this PR was created, please link it if there is some. I imagine that if we would like to support such behavior then we should probably create some helper in SDK and then use it in all applicable instrumentation packages (you already repeated the functionality in #874). This would deserve an issue at least for tracking purposes.

instrumentation/net/http/otelhttp/handler.go Show resolved Hide resolved
instrumentationName,
trace.WithInstrumentationVersion(contrib.SemVersion()),
)
// Tracer is only initialized if manually specified. Otherwise, can be passed with the tracing context.
Copy link
Member

Choose a reason for hiding this comment

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

a comment in code like this is not enough for documenting the behavior
it should be at least noted in "entry" point functions/types e.g. NewHandler and NewTransport

Moreover the new feature should be noted in CHANGELOG.md

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 documenting behavior but explaining why the .Meter and .Tracer are handled differently to the reader. This switch could be in RoundTrip() as well.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added changelog item to the "Added" section. Could have been in "Fixed" as well as if the global tracer and the parent span tracer would not have matched previously I think it would have lead to some bad behavior. Lmk if you want to change that.

Copy link
Member

@pellared pellared Jul 13, 2021

Choose a reason for hiding this comment

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

particularly while the question of even getting a TracerProvider from a Span is still outstanding in the spec.

For sure it should not be in "Fixed".

If we accept such behavior as acceptable, then, in my opinion, it should be explicitly described in the godoc.

@tonistiigi tonistiigi force-pushed the otelhttp-context branch 2 times, most recently from 3a7013e to e00caaa Compare July 13, 2021 21:06
@codecov
Copy link

codecov bot commented Jul 20, 2021

Codecov Report

Merging #873 (9dac66e) into main (188ebf0) will increase coverage by 0.0%.
The diff coverage is 88.0%.

Impacted file tree graph

@@          Coverage Diff          @@
##            main    #873   +/-   ##
=====================================
  Coverage   69.2%   69.3%           
=====================================
  Files        126     127    +1     
  Lines       5480    5496   +16     
=====================================
+ Hits        3797    3810   +13     
- Misses      1536    1538    +2     
- Partials     147     148    +1     
Impacted Files Coverage Δ
instrumentation/net/http/otelhttp/transport.go 89.0% <66.6%> (-3.3%) ⬇️
instrumentation/net/http/otelhttp/common.go 100.0% <100.0%> (ø)
instrumentation/net/http/otelhttp/config.go 79.3% <100.0%> (-0.7%) ⬇️
instrumentation/net/http/otelhttp/handler.go 78.1% <100.0%> (+1.2%) ⬆️

CHANGELOG.md Outdated Show resolved Hide resolved
CHANGELOG.md Outdated Show resolved Hide resolved
@thaJeztah
Copy link

#879 was merged, so this needs another rebase @tonistiigi

@tonistiigi
Copy link
Contributor Author

The base of this PR was completely refactored while it was stuck in review 😞 . The refactoring was merged in a matter of hours.

@thaJeztah
Copy link

Looks like this needs a re-approval to get CI running; @pellared @Aneurysm9 are you able to help getting this one moving?

@thaJeztah
Copy link

@tonistiigi needs a rebase (again) 😞

@crazy-max
Copy link

Can someone approve CI run please? Thanks!

@thaJeztah
Copy link

Looks to be green ✅

@thaJeztah
Copy link

And needs a rebase again (conflict in CHANGELOG.md) 😞

@XSAM @pellared @Aneurysm9 are you able to help getting this one moving? Trying to get rid of a (what was expected to be a short-lived) fork of this code.

@pellared pellared requested a review from MrAlias October 12, 2021 13:33
Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
@Aneurysm9 Aneurysm9 merged commit e81f85a into open-telemetry:main Oct 29, 2021
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.

None yet

7 participants