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

usage reporting: add sendTraces, rename sendErrorsInTraces, etc #6855

Merged
merged 2 commits into from
Aug 26, 2022

Conversation

glasser
Copy link
Member

@glasser glasser commented Aug 26, 2022

  • We've decided to leave the usage reporting defaults in AS4 as "field
    level instrumentation on for all operations, send some operations as
    traces". But we'd like to at least provide a non-experimental
    mechanism for entirely disabling sending traces to Studio. So there's
    a new ApolloServerPluginUsageReporting: sendTraces: false.
  • Rename the (new in AS4) usage reporting option sendErrorsInTraces to
    sendErrors, because it does also affect error statistics in stats
    reports if your transform function returns null.
  • Remove Apollo-internal internal_includeTracesContributingToStats
    option. This enabled some internal consistency monitoring which we are
    no longer paying attention to.
  • If you enable debugPrintReports, send the reports as info rather
    than warn, which primarily lets us delete some large comments (and
    makes sense because these debug messages are not warnings).

Fixes #6051. Fixes #6078.

@netlify
Copy link

netlify bot commented Aug 26, 2022

Deploy Preview for apollo-server-docs ready!

Name Link
🔨 Latest commit 0c2ffa7
🔍 Latest deploy log https://app.netlify.com/sites/apollo-server-docs/deploys/63090a453c22f3000984fcfd
😎 Deploy Preview https://deploy-preview-6855--apollo-server-docs.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site settings.

@codesandbox-ci
Copy link

codesandbox-ci bot commented Aug 26, 2022

This pull request is automatically built and testable in CodeSandbox.

To see build info of the built libraries, click here or the icon next to each commit SHA.

Latest deployment of this branch, based on commit 0c2ffa7:

Sandbox Source
Apollo Server Typescript Configuration
Apollo Server Configuration

@glasser glasser force-pushed the glasser/usage-reporting-tweaks branch from 6cd6f7c to d155b36 Compare August 26, 2022 17:14
- We've decided to leave the usage reporting defaults in AS4 as "field
  level instrumentation on for all operations, send some operations as
  traces". But we'd like to at least provide a non-experimental
  mechanism for entirely disabling sending traces to Studio. So there's
  a new ApolloServerPluginUsageReporting: `sendTraces: false`.
- Rename the (new in AS4) usage reporting option `sendErrorsInTraces` to
  `sendErrors`, because it does also affect error statistics in stats
  reports if your `transform` function returns `null`.
- Remove Apollo-internal `internal_includeTracesContributingToStats`
  option. This enabled some internal consistency monitoring which we are
  no longer paying attention to.
- If you enable `debugPrintReports`, send the reports as `info` rather
  than `warn`, which primarily lets us delete some large comments (and
  makes sense because these debug messages are not warnings).

Fixes #6051. Fixes #6078.
@glasser glasser force-pushed the glasser/usage-reporting-tweaks branch from d155b36 to 596b4f6 Compare August 26, 2022 17:20
Copy link
Contributor

@rkoron007 rkoron007 left a comment

Choose a reason for hiding this comment

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

Small tweaks for clarity in the options.ts docs, but besides that, this looks good to me!

*
* By setting the `sendTraces` option to `false`, Apollo Server will describe
* *all* operations as stats; individual requests will never be broken out
* into separate traces. If you set `sendTraces: false`, the Traces view in
Copy link
Contributor

Choose a reason for hiding this comment

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

How would you feel about rephrasing the second sentence to something like this:

Suggested change
* into separate traces. If you set `sendTraces: false`, the Traces view in
* into separate traces. If you set `sendTraces: false`, then Apollo Studio's Traces view won't show any traces ( other Studio functionality will be unaffected).

* Note that the values of `sendVariableValues`, `sendHeaders`, and
* `sendUnexecutableOperationDocuments` are irrelevant if you set
* `sendTraces: false`, because those options control data that is contained
* only in traces and not in stats.
Copy link
Contributor

Choose a reason for hiding this comment

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

I feel like parenthesis here help punctuate the point:

Suggested change
* only in traces and not in stats.
* only in traces (not in stats).

Copy link
Member Author

Choose a reason for hiding this comment

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

pun intended?

Copy link
Contributor

Choose a reason for hiding this comment

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

You know it 😂

* be removed, and keys removed will be added back with an empty value. For security reasons, if an error occurs within this function, all variable values will be replaced with `[PREDICATE_FUNCTION_ERROR]`.
* - { exceptNames: ... }: a case-sensitive list of names of variables whose values should not be sent to Apollo servers
* - { onlyNames: ... }: A case-sensitive list of names of variables whose values will be sent to Apollo servers
* - { transform: ... }: a custom function for modifying variable values. Keys
Copy link
Contributor

Choose a reason for hiding this comment

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

I know this was in the original file, but the sentence: "Keys added by the custom function will be removed, and keys removed will be added back with an empty value" is confusing on the first read.

Copy link
Member Author

Choose a reason for hiding this comment

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

@rkoron007 how's this?

   * - { transform: ... }: a custom function for modifying variable values. The
   *    function receives `variables` and `operationString` and should return a
   *    record of `variables` with the same keys as the `variables` it receives
   *    (added variables will be ignored and removed variables will be reported
   *    with an empty value). For security reasons, if an error occurs within
   *    this function, all variable values will be replaced with
   *    `[PREDICATE_FUNCTION_ERROR]`.

Copy link
Contributor

Choose a reason for hiding this comment

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

That is so clear, wonderful!

@glasser glasser merged commit 3e4ab3f into version-4 Aug 26, 2022
@glasser glasser deleted the glasser/usage-reporting-tweaks branch August 26, 2022 18:08
glasser pushed a commit that referenced this pull request Aug 26, 2022
This PR was opened by the [Changesets release](https://github.com/changesets/action) GitHub action. When you're ready to do a release, you can merge this and the packages will be published to npm automatically. If you're not ready to do a release yet, that's fine, whenever you add more changesets to version-4, this PR will be updated.

⚠️⚠️⚠️⚠️⚠️⚠️

`version-4` is currently in **pre mode** so this branch has prereleases rather than normal releases. If you want to exit prereleases, run `changeset pre exit` on `version-4`.

⚠️⚠️⚠️⚠️⚠️⚠️

# Releases
## @apollo/[email protected]

### Patch Changes

-   [#6855](#6855) [`3e4ab3fca`](3e4ab3f) Thanks [@glasser](https://github.com/glasser)! - Rename usage reporting option `sendErrorsInTraces` (added in 4.0.0-alpha.4) to `sendErrors`, as it also affects error statistics outside of traces.

-   Updated dependencies \[[`3e4ab3fca`](3e4ab3f), [`3e4ab3fca`](3e4ab3f), [`3e4ab3fca`](3e4ab3f), [`3e4ab3fca`](3e4ab3f)]:
    -   @apollo/[email protected]

## @apollo/[email protected]

### Patch Changes

-   [#6855](#6855) [`3e4ab3fca`](3e4ab3f) Thanks [@glasser](https://github.com/glasser)! - New usage reporting option `sendTraces: false` to only send usage reports as aggregated statistics, not per-request traces.


-   [#6855](#6855) [`3e4ab3fca`](3e4ab3f) Thanks [@glasser](https://github.com/glasser)! - Remove Apollo-internal `internal_includeTracesContributingToStats`. This should not have been used other than inside Apollo's own servers.


-   [#6855](#6855) [`3e4ab3fca`](3e4ab3f) Thanks [@glasser](https://github.com/glasser)! - The usage reporting option `debugPrintReports` now displays reports via `logger.info` rather than `logger.warn`.


-   [#6855](#6855) [`3e4ab3fca`](3e4ab3f) Thanks [@glasser](https://github.com/glasser)! - Rename usage reporting option `sendErrorsInTraces` (added in 4.0.0-alpha.4) to `sendErrors`, as it also affects error statistics outside of traces.

Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Comment on lines +32 to +35
* Note that the values of `sendVariableValues`, `sendHeaders`, and
* `sendUnexecutableOperationDocuments` are irrelevant if you set
* `sendTraces: false`, because those options control data that is contained
* only in traces (not in stats).
Copy link
Member

@trevor-scheer trevor-scheer Aug 30, 2022

Choose a reason for hiding this comment

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

Maybe we should have sendTraces?: false | { sendVariableValues?, sendHeaders?, ... }

The nesting is a little extra, but there's no room for misconfiguration and the association of those options with traces should eliminate potential confusion.

Copy link
Member Author

Choose a reason for hiding this comment

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

Oops, I should have acted on this feedback earlier.

What you're describing definitely feels like a superior API. Whether it's worth making it be yet another thing for users to mechanically update on upgrade (my intuition says sendVariableValues is a pretty popular option), not so sure.

@@ -483,6 +483,8 @@ The function you pass to `transform` is called for each error (`GraphQLError`) t
- Return a modified form of the error (e.g., by changing the `err.message` to remove potentially sensitive information)
- Return `null` to prevent the error from being reported entirely

Note that returning `null`` also affects Studio's aggregated statistics about how many operations contain errors and at what paths those errors appear.
Copy link
Member

Choose a reason for hiding this comment

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

Extra backtick here

Copy link
Member Author

Choose a reason for hiding this comment

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

you fixed this

// actually captured this as a full trace *and*
// sendOperationAsTrace says so.
// into stats) only if the user didn't set `sendTraces: false`
// *and8 we believe it's possible that our organization's plan
Copy link
Member

Choose a reason for hiding this comment

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

typo *and8

Copy link
Member Author

Choose a reason for hiding this comment

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

@bonnici caught this and fixed it elsewhere

@github-actions github-actions bot mentioned this pull request Oct 10, 2022
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Apr 20, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants