-
Notifications
You must be signed in to change notification settings - Fork 814
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
#4147 added tenant_id
tag to tracing spans
#4186
Merged
pracucci
merged 9 commits into
cortexproject:master
from
vlad-diachenko:added_tenant_id_tag_to_tracing_span
May 20, 2021
Merged
Changes from 3 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
3a3cb4b
#4147
vlad-diachenko acef697
#4147 fixed errors reported by linters
vlad-diachenko f3c5648
#4147
vlad-diachenko 4865018
#4147
vlad-diachenko 3ff0b80
#4147 updated CHANGELOG.md
vlad-diachenko 1d15a71
#4147 passed method's span context to mergeDistinctStringSlice functi…
vlad-diachenko 669b8d2
#4147 added mocktracer package for testing purpose
vlad-diachenko f0fb3bd
#4147 fixed code style and removed redundant context param that is no…
vlad-diachenko aed8dab
#4147 fixed code style
vlad-diachenko File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,11 +9,16 @@ import ( | |
"github.com/opentracing/opentracing-go/ext" | ||
otlog "github.com/opentracing/opentracing-go/log" | ||
|
||
"github.com/cortexproject/cortex/pkg/tenant" | ||
util_log "github.com/cortexproject/cortex/pkg/util/log" | ||
) | ||
|
||
type loggerCtxMarker struct{} | ||
|
||
const ( | ||
TenantIDTagName = "tenant_id" | ||
vlad-diachenko marked this conversation as resolved.
Show resolved
Hide resolved
|
||
) | ||
|
||
var ( | ||
loggerCtxKey = &loggerCtxMarker{} | ||
) | ||
|
@@ -34,6 +39,9 @@ func New(ctx context.Context, method string, kvps ...interface{}) (*SpanLogger, | |
// retrieved with FromContext or FromContextWithFallback. | ||
func NewWithLogger(ctx context.Context, l log.Logger, method string, kvps ...interface{}) (*SpanLogger, context.Context) { | ||
span, ctx := opentracing.StartSpanFromContext(ctx, method) | ||
if ids, _ := tenant.TenantIDs(ctx); ids != nil { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I am not too sure what other side effects this could have, but I think in general it is a good idea to always have the context's tenant_id(s) in the tracing span.
vlad-diachenko marked this conversation as resolved.
Show resolved
Hide resolved
|
||
span.SetTag(TenantIDTagName, ids) | ||
} | ||
logger := &SpanLogger{ | ||
Logger: log.With(util_log.WithContext(ctx, l), "method", method), | ||
Span: span, | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it would make sense to create a span during the creation of the queriers and the finish the span once
Close()
of the resulting mergeQuerier is called.I have played with that here:
6ebd273
That's how that looks like:

There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This feels at least like it can group the same tenants nicely together. Obvisouly for a real fix we need context propagation as a part of LabelValues,LabelName, Select.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes, it will help to group spans by tenant_id . thanks, i will implement it
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
however, it might confuse a little bit because all spans

mergeQuerier.NewQuerier
will take almost similar time for each tenant. but inside this span we will see real picture.in current implementation it looks less confusing, i think.
what do you think?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To be honest I agree partly with your point, but I am not too sure, how to fix this properly.
I guess part of the problem is that the a query is only finished once
Close()
is called, which happens at the same time for underlying queriers.I think the most confusing part of not grouping spans by tenant_id is seeing all (and even unrelated) spans together. I think until we implement context passing in those methods, we won't be able to solve that properly.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You could instantiate the queriers (call the callback inside LabelValues, etc.) and the right context will be applied.