Skip to content

(fix) Prevent log on rhai scripts that short circuit#8364

Merged
BrynCooke merged 4 commits intodevfrom
bryn/rhai-logging
Oct 7, 2025
Merged

(fix) Prevent log on rhai scripts that short circuit#8364
BrynCooke merged 4 commits intodevfrom
bryn/rhai-logging

Conversation

@BrynCooke
Copy link
Contributor

@BrynCooke BrynCooke commented Oct 1, 2025

In Rhai we use throw to indicate that the pipeline should no longer proceed and should instead immediately return to the user.

Previously wherever this happened this would log an error.

However, when a user wants to return an error response it is not helpful to always log the entire body as an error, and causes a flood of logs.

This PR adds logic to only log if there is no body associated with the response.

For example the following will NOT log

    throw #{
        status: 403,
        body: #{
            errors: [#{
                message: "Custom error with body",
                extensions: #{
                    code: "FORBIDDEN"
                }
            }]
        }
    };

For example the following WILL log

throw "An error occurred without a body";

Checklist

Complete the checklist (and note appropriate exceptions) before the PR is marked ready-for-review.

  • PR description explains the motivation for the change and relevant context for reviewing
  • PR description links appropriate GitHub/Jira tickets (creating when necessary)
  • Changeset is included for user-facing changes
  • Changes are compatible1
  • Documentation2 completed
  • Performance impact assessed and acceptable
  • Metrics and logs are added3 and documented
  • Tests added and passing4
    • Unit tests
    • Integration tests
    • Manual tests, as necessary

Exceptions

No perf impact as code is simple and reduces logging
No metrics needed
Unit tests cover all scenarios

Notes

Footnotes

  1. It may be appropriate to bring upcoming changes to the attention of other (impacted) groups. Please endeavour to do this before seeking PR approval. The mechanism for doing this will vary considerably, so use your judgement as to how and when to do this.

  2. Configuration is an important part of many changes. Where applicable please try to document configuration examples.

  3. A lot of (if not most) features benefit from built-in observability and debug-level logs. Please read this guidance on metrics best-practices.

  4. Tick whichever testing boxes are applicable. If you are adding Manual Tests, please document the manual testing (extensively) in the Exceptions.

@apollo-librarian
Copy link

apollo-librarian bot commented Oct 1, 2025

✅ Docs preview ready

The preview is ready to be viewed. View the preview

File Changes

3 new, 9 changed, 4 removed
+ graphos/routing/(latest)/observability/router-telemetry-otel/apm-guides/datadog/observing-and-monitoring/dashboard-template.mdx
+ graphos/routing/(latest)/self-hosted/managed-hosting/railway.mdx
+ graphos/routing/(latest)/self-hosted/managed-hosting/render.mdx
* graphos/routing/(latest)/customization/rhai/index.mdx
* graphos/routing/(latest)/observability/graphos/graphos-reporting.mdx
* graphos/routing/(latest)/observability/router-telemetry-otel/apm-guides/datadog/connecting-to-datadog/datadog-agent/datadog-agent-metrics.mdx
* graphos/routing/(latest)/observability/router-telemetry-otel/apm-guides/datadog/connecting-to-datadog/datadog-agent/datadog-agent-traces.mdx
* graphos/routing/(latest)/observability/router-telemetry-otel/apm-guides/prometheus/otel-traces-to-prometheus.mdx
* graphos/routing/(latest)/observability/router-telemetry-otel/enabling-telemetry/selectors.mdx
* graphos/routing/(latest)/observability/router-telemetry-otel/enabling-telemetry/spans.mdx
* graphos/routing/(latest)/self-hosted/containerization/docker.mdx
* graphos/routing/(latest)/_sidebar.yaml
- graphos/routing/(latest)/observability/router-telemetry-otel/apm-guides/datadog/index.mdx
- graphos/routing/(latest)/observability/router-telemetry-otel/apm-guides/datadog/router-instrumentation.mdx
- graphos/routing/(latest)/observability/router-telemetry-otel/apm-guides/datadog/connecting-to-datadog/index.mdx
- graphos/routing/(latest)/observability/router-telemetry-otel/apm-guides/datadog/connecting-to-datadog/otel-collector.mdx

Build ID: cad1fcca7c152295fab1b9f5
Build Logs: View logs

URL: https://www.apollographql.com/docs/deploy-preview/cad1fcca7c152295fab1b9f5

@github-actions

This comment has been minimized.

Rhai script that short circuit with a response should not log. If the user want to explicitly log then they can do so using the rhai logging facilities.
errors thrown will still log.
@BrynCooke BrynCooke marked this pull request as ready for review October 1, 2025 10:24
@BrynCooke BrynCooke requested a review from a team October 1, 2025 10:24
@BrynCooke BrynCooke requested a review from a team as a code owner October 1, 2025 10:24
@BrynCooke BrynCooke requested a review from aaronArinder October 1, 2025 11:57
Co-authored-by: Iryna Shestak <shestak.irina@gmail.com>
@BrynCooke BrynCooke enabled auto-merge (squash) October 7, 2025 09:38
@BrynCooke BrynCooke merged commit b10faf2 into dev Oct 7, 2025
15 checks passed
@BrynCooke BrynCooke deleted the bryn/rhai-logging branch October 7, 2025 10:57
@abernix abernix mentioned this pull request Oct 27, 2025
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.

2 participants