-
Notifications
You must be signed in to change notification settings - Fork 2.9k
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
Add customTraceAttributes to session #22179
Add customTraceAttributes to session #22179
Conversation
Thank you for your pull request and welcome to the Trino community. We require contributors to sign our Contributor License Agreement, and we don't seem to have you on file. Continue to work with us on the review and improvements in this PR, and submit the signed CLA to [email protected]. Photos, scans, or digitally-signed PDF files are all suitable. Processing may take a few days. The CLA needs to be on file before we merge your changes. For more information, see https://github.com/trinodb/cla |
CTA sent. |
@@ -118,7 +120,8 @@ public Session( | |||
SessionPropertyManager sessionPropertyManager, | |||
Map<String, String> preparedStatements, | |||
ProtocolHeaders protocolHeaders, | |||
Optional<Slice> exchangeEncryptionKey) | |||
Optional<Slice> exchangeEncryptionKey, | |||
Map<String, String> customTraceAttributes) |
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.
can you call it extraTraceAttributes
or extraTracingAttributes
?
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 originally used the term "extra" but when it came to adding a prefix to avoid collisions with other top level names "extra" seemed confusing. I figured "custom" was less confusing so I used that and followed with this name too.
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.
What was the confusing place with extra
?
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.
When I try to put myself in the place of an admin looking at some attribute for a query with a prefix "extra:..." I think what "extra" is referring to is ambiguous. I don't think that it would be evident that "extra" is referring to the fact that it's an extra attribute in addition to the typical ones and that it could mean that the extra is in reference to the name of the attribute. "custom", however, I think is much more clear that the attribute itself is custom and the semantic is more clear. That might just be me though.
@@ -930,6 +951,31 @@ public SessionBuilder setProtocolHeaders(ProtocolHeaders protocolHeaders) | |||
return this; | |||
} | |||
|
|||
@CanIgnoreReturnValue | |||
public SessionBuilder addCustomTraceAttribute(String name, String value) |
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.
addExtraTraceAttribute
} | ||
|
||
@CanIgnoreReturnValue | ||
public SessionBuilder addAllCustomTraceAttribute(Map<String, String> customTraceAttributes) |
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.
addExtraTraceAttributes
core/trino-main/src/main/java/io/trino/dispatcher/QueuedStatementResource.java
Outdated
Show resolved
Hide resolved
{ | ||
log.info("TIMELINE: Query %s :: %s%s :: elapsed %sms :: planning %sms :: waiting %sms :: scheduling %sms :: running %sms :: finishing %sms :: begin %s :: end %s", | ||
String customAttributeSection = customTraceAttributes.entrySet().stream() |
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.
why do we need to change this log message?
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 was the goal of the tracking, along with adding to the trace objects. It allows for profiling query performance for specific client types from these results along with the traces.
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 see it quite arbitrary to put this specific information in this log message. I would keep it just in opentelemetry for now.
f3bc68c
to
f2e91cc
Compare
Thank you for your pull request and welcome to the Trino community. We require contributors to sign our Contributor License Agreement, and we don't seem to have you on file. Continue to work with us on the review and improvements in this PR, and submit the signed CLA to [email protected]. Photos, scans, or digitally-signed PDF files are all suitable. Processing may take a few days. The CLA needs to be on file before we merge your changes. For more information, see https://github.com/trinodb/cla |
f2e91cc
to
05c17ad
Compare
Thank you for your pull request and welcome to the Trino community. We require contributors to sign our Contributor License Agreement, and we don't seem to have you on file. Continue to work with us on the review and improvements in this PR, and submit the signed CLA to [email protected]. Photos, scans, or digitally-signed PDF files are all suitable. Processing may take a few days. The CLA needs to be on file before we merge your changes. For more information, see https://github.com/trinodb/cla |
05c17ad
to
c15fdd9
Compare
Thank you for your pull request and welcome to the Trino community. We require contributors to sign our Contributor License Agreement, and we don't seem to have you on file. Continue to work with us on the review and improvements in this PR, and submit the signed CLA to [email protected]. Photos, scans, or digitally-signed PDF files are all suitable. Processing may take a few days. The CLA needs to be on file before we merge your changes. For more information, see https://github.com/trinodb/cla |
c15fdd9
to
002892e
Compare
Thank you for your pull request and welcome to the Trino community. We require contributors to sign our Contributor License Agreement, and we don't seem to have you on file. Continue to work with us on the review and improvements in this PR, and submit the signed CLA to [email protected]. Photos, scans, or digitally-signed PDF files are all suitable. Processing may take a few days. The CLA needs to be on file before we merge your changes. For more information, see https://github.com/trinodb/cla |
002892e
to
22857a7
Compare
Thank you for your pull request and welcome to the Trino community. We require contributors to sign our Contributor License Agreement, and we don't seem to have you on file. Continue to work with us on the review and improvements in this PR, and submit the signed CLA to [email protected]. Photos, scans, or digitally-signed PDF files are all suitable. Processing may take a few days. The CLA needs to be on file before we merge your changes. For more information, see https://github.com/trinodb/cla |
SpanBuilder spanBuilder = tracer.spanBuilder("query") | ||
.setAttribute(TrinoAttributes.QUERY_ID, queryId.toString()); | ||
sessionContext.getCustomTraceAttributes().forEach((key, value) -> | ||
spanBuilder.setAttribute("custom:%s".formatted(key), value)); |
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.
docs suggest:
Note: It is strongly recommended to use setAttribute(AttributeKey, Object), and pre-allocate your keys, if possible.
consider having a map String->AttributeKey so your keys are ~singletons.
/** | ||
* @throws java.util.NoSuchElementException if the query is not found | ||
*/ | ||
public String getClientTags(QueryId queryId) | ||
{ | ||
return getExtraTraceAttributes(queryId).get(CLIENT_TAGS); | ||
} |
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.
not used drop
PriorityQueue<String> valQueue = new PriorityQueue<>(vals); | ||
return valQueue.stream().collect(Collectors.joining(",")); |
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.
return vals.stream().sorted().collect(joining(","));
This pull request has gone a while without any activity. Tagging the Trino developer relations team: @bitsondatadev @colebow @mosabua |
@cla-bot check |
The cla-bot has been summoned, and re-checked this pull request! |
@mduggan-starburst can you address comments? |
Closed as unnecessary. |
Description
This change is support custom trace attributes for both the
QueryMonitor
logging of completed queries and OpenTelemetry Trace objects for queries. It has no effect other than the additional information logged for queries that are run on Trino.The attributes will be printed with a prefix "custom:" so that there will not be a collision with any existing attributes.
Additional context and related issues
When a query is created, it has an associated
Session
. This session contains context information regarding the query and additionally is part of theQueryInfo
object passed to theQueryMonitor
, which logs information regarding completed queries. By creating a member in theSession
(as well as the associatedSessionContext
andSessionRepresentation
) the custom trace attributes are available downstream in the query lifecycle.Release notes
( ) This is not user-visible or is docs only, and no release notes are required.
( ) Release notes are required. Please propose a release note for me.
( ) Release notes are required, with the following suggested text: