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

fix: set operation_name tracing attribute to empty on unnamed, single-op requests #525

Merged
merged 5 commits into from
Feb 23, 2022

Conversation

abernix
Copy link
Member

@abernix abernix commented Feb 22, 2022

When GraphQL operation names are not nececessary to execute an operation (i.e., when there is only a single operation in a GraphQL document) and the GraphQL operation is not named (i.e., it is anonymous), the operation_name attribute on the trace spans that are associated with the request will no longer contain a single hyphen character (-) but will instead be an empty string. This matches the way that these operations are represented during the GraphQL operation's life-cycle as well.

Fixes #481

…le-op requests

When GraphQL operation names are not nececessary to execute an operation
(i.e., when there is only a single operation in a GraphQL document) and the
GraphQL operation is _not_ named (i.e., it is anonymous), the
`operation_name` attribute on the trace spans that are associated with the
request will no longer contain a single hyphen character (`-`) but will
instead be an empty string.  This matches the way that these operations are
represented during the GraphQL operation's life-cycle as well.

Fixes #481
Copy link
Contributor

@garypen garypen left a comment

Choose a reason for hiding this comment

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

If my comment doesn't make sense, let me know.

@@ -345,7 +345,7 @@ where
name = "graphql_request",
fields(
query = %request.query.clone().unwrap_or_default(),
operation_name = %request.operation_name.clone().unwrap_or_else(|| "-".to_string()),
operation_name = %request.operation_name.clone().unwrap_or_else(|| "".to_string()),
Copy link
Contributor

Choose a reason for hiding this comment

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

That's going to break the studio usage though. If you look at stats_report_key() in apollo_open you'll note that we assume the default name for an operation there is "-" which is what we want for stats reporting.

To keep things working, you'll need to modify stats_report_key() to check if op_name is "" and, if it is, then update that logic to substitute "-" as the op_name. The comment there will need to be updated as well.

Copy link
Member Author

@abernix abernix Feb 22, 2022

Choose a reason for hiding this comment

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

Ah, that makes sense. Thanks! I was under the impression that this was added within the APQ issue (since that's where the review comment was) and had assumed we were doing the default for Studio reporting elsewhere.

Copy link
Contributor

Choose a reason for hiding this comment

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

There should have been a comment above that instrument block to explain why we did that...

As noted in [comment][1], the previous [commit][2] I made wasn't sufficient to
avoid exposing the (meant to be internal) implementation detail of the `-`
(hyphen) character being used as a representation for "anonymous operation"
since all my previous comment did was remove it from the tracing span
attribute where it is later extracted from by Spaceport.

This commit takes things a step further, and updates the `stats_report_key`
method to take a required first parameter of a string.  That string _may_ be
empty, but empty merely matches the expectation of unnamed operation.  Keep
in mind that operations only MUST be named when there are multiple
operations in the document.  In the case of multiple operations, the
out-of-band `operationName` parameter must be passed to the request (either
via POST-body or GET query parameters).

[1]: #525 (comment)
[2]: adb7bdd
Copy link
Contributor

@garypen garypen left a comment

Choose a reason for hiding this comment

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

One tiny comment about {empty} vs - . This is a nice improvement on existing behaviour.

apollo-router/src/apollo_telemetry.rs Show resolved Hide resolved
apollo-router/src/apollo_telemetry.rs Outdated Show resolved Hide resolved
CHANGELOG.md Outdated Show resolved Hide resolved
@abernix abernix merged commit 571f9cd into main Feb 23, 2022
@abernix abernix deleted the abernix/issue-481 branch February 23, 2022 13:42
@abernix abernix added this to the v0.1.0-alpha.7 milestone Feb 25, 2022
@abernix abernix mentioned this pull request Feb 25, 2022
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.

Remove "-" as default operation_name if none is provided, and add it in the stats result key only
2 participants