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

Add customTraceAttributes to session #22179

Conversation

mduggan-starburst
Copy link

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 the QueryInfo object passed to the QueryMonitor, which logs information regarding completed queries. By creating a member in the Session (as well as the associated SessionContext and SessionRepresentation) 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:

# Section
* Add custom trace attributes to query session. ({issue}`22178`)

Copy link

cla-bot bot commented May 28, 2024

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

@mduggan-starburst
Copy link
Author

[email protected]

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)
Copy link
Member

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?

Copy link
Author

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.

Copy link
Member

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?

Copy link
Author

@mduggan-starburst mduggan-starburst Jun 3, 2024

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)
Copy link
Member

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)
Copy link
Member

Choose a reason for hiding this comment

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

addExtraTraceAttributes

{
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()
Copy link
Member

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?

Copy link
Author

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.

Copy link
Member

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.

@mduggan-starburst mduggan-starburst force-pushed the duggan/add-session-properties-query-monitor branch from f3bc68c to f2e91cc Compare May 29, 2024 15:51
Copy link

cla-bot bot commented May 29, 2024

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

@mduggan-starburst mduggan-starburst force-pushed the duggan/add-session-properties-query-monitor branch from f2e91cc to 05c17ad Compare May 29, 2024 19:31
Copy link

cla-bot bot commented May 29, 2024

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

@mduggan-starburst mduggan-starburst force-pushed the duggan/add-session-properties-query-monitor branch from 05c17ad to c15fdd9 Compare May 30, 2024 15:08
Copy link

cla-bot bot commented May 30, 2024

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

@mduggan-starburst mduggan-starburst force-pushed the duggan/add-session-properties-query-monitor branch from c15fdd9 to 002892e Compare May 30, 2024 15:20
Copy link

cla-bot bot commented May 30, 2024

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

@mduggan-starburst mduggan-starburst force-pushed the duggan/add-session-properties-query-monitor branch from 002892e to 22857a7 Compare May 30, 2024 15:50
Copy link

cla-bot bot commented May 30, 2024

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));
Copy link
Member

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.

Comment on lines +49 to +55
/**
* @throws java.util.NoSuchElementException if the query is not found
*/
public String getClientTags(QueryId queryId)
{
return getExtraTraceAttributes(queryId).get(CLIENT_TAGS);
}
Copy link
Member

Choose a reason for hiding this comment

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

not used drop

Comment on lines +59 to +60
PriorityQueue<String> valQueue = new PriorityQueue<>(vals);
return valQueue.stream().collect(Collectors.joining(","));
Copy link
Member

@losipiuk losipiuk Jun 3, 2024

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(","));

Copy link

This pull request has gone a while without any activity. Tagging the Trino developer relations team: @bitsondatadev @colebow @mosabua

@github-actions github-actions bot added the stale label Jun 24, 2024
@mosabua
Copy link
Member

mosabua commented Jun 24, 2024

@cla-bot check

@cla-bot cla-bot bot added the cla-signed label Jun 24, 2024
Copy link

cla-bot bot commented Jun 24, 2024

The cla-bot has been summoned, and re-checked this pull request!

@mosabua
Copy link
Member

mosabua commented Jun 24, 2024

@mduggan-starburst can you address comments?

@electrum and @mattstep can you chime in?

@mduggan-starburst
Copy link
Author

Closed as unnecessary.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

Successfully merging this pull request may close these issues.

None yet

3 participants