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

[ShopifyVM] 'app logs' Show input query variables in output for FunctionRunLog #4566

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

mssalemi
Copy link
Contributor

@mssalemi mssalemi commented Oct 2, 2024

Part of: https://github.com/Shopify/script-service/issues/6233

We're enhancing the debugging experience for developers by providing visibility into the input query variables used during a function run.

WHY are these changes introduced?

This PR will add an input query variables section that will conditionally show based on if input query variables are used. Input query variables will be used when the values are specified in the toml.

WHAT is this pull request doing?

Add input query variables section to the app logs command:

I also added some visual improvements to make the output and input sections more clear for partners to view. And updated the ouput and input sections to match.

Changes: with improved styling

imrpovestyle-no-color
With coloring (also will need to update other sections - alternate idea) new_idea_app_logs

and when no metafield is found:
Screenshot 2024-10-03 at 9 59 41 AM

How to test your changes?

From local cli, to your spin instance:

SHOPIFY_CLI_ENABLE_APP_LOG_POLLING=1  NODE_TLS_REJECT_UNAUTHORIZED=0 SPIN=1 SPIN_INSTANCE=68fh pnpm run shopify app logs --path=./efficient-capital-app

** replace spin id and app path

Post-release steps

  • part of a CLI release
  • potentially add change log indicating that the input query variables are now present in logs and has visual improvements
  • use of colouring in text, I kept everything white in current commit, but use red text when metafield is not found.
  • NOTE: might be worth splitting up logic for displaying FunctionRunLog and NetworkAccessResponseFromCacheLog, NetworkAccessRequestExecutedLog into separate files.

Measuring impact

How do we know this change was effective? Please choose one:

  • n/a - this doesn't need measurement, e.g. a linting rule or a bug-fix
  • Existing analytics will cater for this addition
  • PR includes analytics changes to measure impact

Checklist

  • I've considered possible cross-platform impacts (Mac, Linux, Windows)
  • I've considered possible documentation changes

Copy link
Contributor

github-actions bot commented Oct 2, 2024

Thanks for your contribution!

Depending on what you are working on, you may want to request a review from a Shopify team:

  • Themes: @shopify/advanced-edits
  • UI extensions: @shopify/ui-extensions-cli
    • Checkout UI extensions: @shopify/checkout-ui-extensions-api-stewardship
  • Hydrogen: @shopify/hydrogen
  • Other: @shopify/app-inner-loop

@mssalemi mssalemi changed the title [WIP] Show input query variables in app logs command for function runs [ShopifyVM] 'app logs` Show input query variables in output for function runs Oct 3, 2024
Copy link
Contributor

github-actions bot commented Oct 3, 2024

Coverage report

St.
Category Percentage Covered / Total
🟡 Statements
72.64% (+0.03% 🔼)
8379/11535
🟡 Branches
69.19% (+0.08% 🔼)
4124/5960
🟡 Functions
71.92% (-0.02% 🔻)
2190/3045
🟡 Lines
72.95% (+0.03% 🔼)
7922/10860
Show files with reduced coverage 🔻
St.
File Statements Branches Functions Lines
🟢
... / utils.ts
87.25% (-0.11% 🔻)
74.51% (+2.17% 🔼)
82.35% (-5.15% 🔻)
86.87% (-0.09% 🔻)

Test suite run success

1911 tests passing in 867 suites.

Report generated by 🧪jest coverage report action from b318ad7

@mssalemi mssalemi marked this pull request as ready for review October 3, 2024 14:43
Copy link
Contributor

github-actions bot commented Oct 3, 2024

We detected some changes at either packages/*/src or packages/cli-kit/assets/cli-ruby/** and there are no updates in the .changeset.
If the changes are user-facing, run "pnpm changeset add" to track your changes and include them in the next release CHANGELOG.

@mssalemi mssalemi changed the title [ShopifyVM] 'app logs` Show input query variables in output for function runs [ShopifyVM] 'app logs` Show input query variables in output for FunctionRunLog Oct 3, 2024
@mssalemi mssalemi changed the title [ShopifyVM] 'app logs` Show input query variables in output for FunctionRunLog [ShopifyVM] 'app logs' Show input query variables in output for FunctionRunLog Oct 3, 2024
@mssalemi mssalemi force-pushed the ms.app-logs-add-iqv-output branch 3 times, most recently from d104c32 to ef0df79 Compare October 3, 2024 14:52
<Box marginLeft={1} marginTop={1}>
<Text>
{prettyPrintJsonIfPossible(appLog.inputQueryVariablesMetafieldValue) || (
<Text color="red">No metafield data found!</Text>
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe another way of stating this is: Metafield is not set

@nickwesselman WDYT of this?

Copy link
Contributor

@DuncanUszkay1 DuncanUszkay1 left a comment

Choose a reason for hiding this comment

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

LGTM- just the one issue with a lot of use of the word webhook in the tests that I think isn't appropriate- network access relates to network access in functions (though given how often we talk about webhooks in this project and the naming here I can see where the confusion would come from)

@mssalemi mssalemi requested a review from a team as a code owner October 9, 2024 16:15
@mssalemi mssalemi requested review from jamieguerrero and jantnovi and removed request for a team October 9, 2024 16:15
Copy link
Contributor

@andrewhassan andrewhassan left a comment

Choose a reason for hiding this comment

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

Didn't 🎩 but code LGTM!

@mssalemi mssalemi force-pushed the ms.app-logs-add-iqv-output branch 4 times, most recently from 47ba46e to 86135c0 Compare October 10, 2024 13:38
@mssalemi
Copy link
Contributor Author

Quick video if anyone wants to take a look at changes. Will rebase PR before merging.

@nickwesselman
Copy link
Contributor

Thanks for the video @mssalemi! Things look good in app logs, how do they look in the JSON log file that you might open when using app dev?

@mssalemi
Copy link
Contributor Author

mssalemi commented Oct 17, 2024

Thanks for the video @mssalemi! Things look good in app logs, how do they look in the JSON log file that you might open when using app dev?

The variables get added to the payload in the logs:

  "payload": {
.....
    "inputQueryVariablesMetafieldValue": "{\"value\":\"42\"}",
    "inputQueryVariablesMetafieldNamespace": "meow",
    "inputQueryVariablesMetafieldKey": "key"
  }

perhaps we want to decode the the value 👀

@nickwesselman
Copy link
Contributor

The variables get added to the payload in the logs:

  "payload": {
.....
    "inputQueryVariablesMetafieldValue": "{\"value\":\"42\"}",
    "inputQueryVariablesMetafieldNamespace": "meow",
    "inputQueryVariablesMetafieldKey": "key"
  }

Can we attempt to parse the value and output it as an object if successful?

} else if (typeof json === 'object' && json !== null) {
return JSON.stringify(json, null, 2)
} else {
if (typeof json === 'string') {
Copy link
Contributor

Choose a reason for hiding this comment

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

Could you explain the reasoning for this change here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Will look into this, its related to Nicks comment above. Right now with PR we dont decode that part of the payload, so to display the JSON string better I added that. But thinking, it probably makes more sense to decode the inner payload here. Will look into it.

Copy link
Contributor

Choose a reason for hiding this comment

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

Would be great if you could add a return type so it's easier to grok what this function is trying to return!

My main question is why you removed the other cases from within the try/catch block instead of just changing the throw to return json.

Additionally, why are we changing this to return json instead of throwing an error?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah sounds good, reverting this change. I changed up how I call this method and ensure the metafield is an object, that we can we leave this unchanged.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

why are we changing this to return json instead of throwing an error?

Reverted this, but originally was because this values the we needed to use this method on is from a metafield, and it could technically just be a string, and we dont want to error in those cases and just show whatever the value was. That way partners can use it to debug any issue related to the input query variables.

@mssalemi
Copy link
Contributor Author

Can we attempt to parse the value and output it as an object if successful?

Updated this so we the value is object instead of string, partners should be able to more easily read them.

Screenshot 2024-10-17 at 3 48 55 PM

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.

5 participants