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

Open Telemetry : Adds query text in attribute #4664

Open
wants to merge 23 commits into
base: master
Choose a base branch
from

Conversation

sourabh1007
Copy link
Contributor

@sourabh1007 sourabh1007 commented Sep 4, 2024

Description

  1. Added db.query.text attribute to record queries in Traces.
  2. Introduced new ShowQueryMode, which will have valid values as
    a) NONE :Do not show query.
    b) PARAMETERIZED_ONLY : Print parameterized query only.
    b) ALL
  3. It can be set as part of CosmosClientTelemetryOptions and RequestOptions (i.e. QueryRequestOptions and ChangeFeedRequestOptions)

Type of change

  • [] New feature (non-breaking change which adds functionality)

@sourabh1007 sourabh1007 marked this pull request as draft September 4, 2024 17:16
@sourabh1007 sourabh1007 force-pushed the users/sourabhjain/addqueryTextinOtel branch 3 times, most recently from 2f7c8e7 to e663af5 Compare September 11, 2024 01:24
@sourabh1007 sourabh1007 marked this pull request as ready for review September 12, 2024 00:45
@sourabh1007 sourabh1007 requested a review from a team as a code owner September 12, 2024 00:45
@sourabh1007 sourabh1007 force-pushed the users/sourabhjain/addqueryTextinOtel branch from 816b162 to 8e29f00 Compare September 13, 2024 12:32
Copy link
Contributor

@jcocchi jcocchi left a comment

Choose a reason for hiding this comment

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

Do we want to have an opt in to also capture parameter values attributes? This is described in the otel conventions, but we can always go back and add it if there's demand later.

db.query.parameter.<key>

@kirankumarkolli
Copy link
Member

Reqeustlevel override feels over engineering, Thoughts?

@sourabh1007
Copy link
Contributor Author

verride feels over engineering, Thoughts?

It is taken from Java SDK and I believe, It will provide customers with the option to enable or disable the inclusion of query text in OpenTelemetry (OTel) traces for specific types of queries.

@sourabh1007 sourabh1007 force-pushed the users/sourabhjain/addqueryTextinOtel branch from 6343391 to 23b13bf Compare September 25, 2024 10:23
Copy link
Contributor

@philipthomas-MSFT philipthomas-MSFT left a comment

Choose a reason for hiding this comment

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

Nothing major from me. LGTM. just one nit. Everything else looks good.

@sourabh1007 sourabh1007 force-pushed the users/sourabhjain/addqueryTextinOtel branch from 5fd9ce8 to b760982 Compare September 26, 2024 13:54
/// Users have the option to enable printing parameterized or all queries,
/// but has to beware that customer data may be shown when the later option is chosen. It's the user's responsibility to sanitize the queries if necessary.
/// </summary>
public QueryTextMode QueryTextMode { get; set; } = QueryTextMode.None;
Copy link
Member

Choose a reason for hiding this comment

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

Inconsistency, in-other request options nullable used

Copy link
Contributor Author

Choose a reason for hiding this comment

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

what is the inconsistency, you are talking about here. All the telemetry options have some default value.

Copy link
Contributor

Choose a reason for hiding this comment

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

This default value makes sense to me

@@ -26,6 +26,7 @@ internal struct OpenTelemetryCoreRecorder : IDisposable
private readonly OperationType operationType = OperationType.Invalid;
private readonly string connectionModeCache = null;

private readonly QueryTextMode queryTextMode = QueryTextMode.None;
Copy link
Member

Choose a reason for hiding this comment

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

Mark it nullable for consistency and only apply default here?

@@ -245,6 +250,16 @@ OperationType operationType
this.scope.AddAttribute(OpenTelemetryAttributeKeys.ActivityId, this.response.ActivityId);
this.scope.AddAttribute(OpenTelemetryAttributeKeys.CorrelatedActivityId, this.response.CorrelatedActivityId);

if (this.response.QuerySpec is not null)
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
if (this.response.QuerySpec is not null)
if (this.response.QuerySpec.HasValue)

(this.queryTextMode != QueryTextMode.None && this.response.QuerySpec.ShouldSerializeParameters() &&
this.queryTextMode == QueryTextMode.ParameterizedOnly))
{
this.scope.AddAttribute(OpenTelemetryAttributeKeys.QueryText, this.response.QuerySpec?.QueryText);
Copy link
Member

Choose a reason for hiding this comment

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

Expected semantics: Is below expectation correct? If so code needs to aligns with it.

  • All: Full query text including parameterized with parameter values
  • Paramaterized: Query with-out parameters?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

All => The entire query will be included, regardless of whether it is parameterized or not.
Parameterized Only => Only parameterized queries will be included. If the query contains any hardcoded information, it will also be included as is. It is the customer's responsibility to ensure that the query does not contain any sensitive information.
None => The query text will not be included.

Copy link
Contributor

Choose a reason for hiding this comment

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

regardless of whether it is parameterized or not

Sounds like if it is parameterized, we won't "fill" the parameter with real values. I left a comment on this already, but putting it again here since it's relevant. Do we want to have an opt in to also capture parameter values attributes? This is described in the otel conventions, but we can always omit for now and add it if there's demand later.

db.query.parameter.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Adding parameter is kind of unlikely and in Java SDK never demanded for it, so I think we should be good as of now, if we see customers requesting for it, we can include it.

/// Users have the option to enable printing parameterized or all queries,
/// but has to beware that customer data may be shown when the later option is chosen. It's the user's responsibility to sanitize the queries if necessary.
/// </summary>
public QueryTextMode QueryTextMode { get; set; } = QueryTextMode.None;
Copy link
Contributor

Choose a reason for hiding this comment

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

This default value makes sense to me

jcocchi
jcocchi previously approved these changes Sep 27, 2024
Copy link
Contributor

@jcocchi jcocchi left a comment

Choose a reason for hiding this comment

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

LGTM

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.

6 participants