Azure / azure-sdk-for-js

This repository is for active development of the Azure SDK for JavaScript (NodeJS & Browser). For consumers of the SDK we recommend visiting our public developer docs at https://docs.microsoft.com/javascript/azure/ or our versioned developer docs at https://azure.github.io/azure-sdk-for-js.
MIT License
2.09k stars 1.2k forks source link

Long Running Operation polling doesn't work in playback mode since #30428

Closed danielszaniszlo closed 3 months ago

danielszaniszlo commented 3 months ago

Describe the bug I recently regenerated our SDK and upgraded @azure/core-lro package to v3.0.1. Since then the LRO polling is not working in playback mode. I think it is related to test proxy somehow removes parts of the URL. In live mode everything works fine test cases are passing. I think something is related to sanitizers. I just recently did the same task for JAVA and there I was removing these two sanitizers: "AZSDK2003", "AZSDK2030" but if I remove them here I get the following error: RecorderError: removeSanitizers request failed. When I look at the new recording under .assets\xt6hYh2zvq\js\sdk\healthdataaiservices\azure-health-deidentification\recordings\browsers\batch\recording_jobe2e_wait_until_success.json I can notice that the first request has the operation-location in ResponseHeaders but after that the polling requests doesn't have the operation-location in the ResponseHeaders. Also the initial request is going to https://example.com/jobs/js-sdk-job-recorded-003i?api-version=2024-07-12-preview and after that the polling requests are https://example.com/?api-version=2024-07-12-preview somehow the /jobs/js-sdk-job-recorded-003i got removed.

I have the following setup for sanitizers and env variables:

const fakeServiceEndpoint = "example.com";
const replaceableVariables: Record<string, string> = {
  DEID_SERVICE_ENDPOINT: fakeServiceEndpoint,
  STORAGE_ACCOUNT_SAS_URI:
    "https://fake_storage_account_sas_uri.blob.core.windows.net/container-sdk-dev-fakeid",
};
.
.
recorder = await createRecorder(context);
await recorder.start({
  envSetupForPlayback: replaceableVariables,
  sanitizerOptions: {
    bodyKeySanitizers: [
      {
        value: replaceableVariables.STORAGE_ACCOUNT_SAS_URI,
        jsonPath: "$..location",
        regex: "^(?!.*FAKE_STORAGE_ACCOUNT).*",
      },
    ],
  },
  removeCentralSanitizers: ["AZSDK3493", "AZSDK4001", "AZSDK3430"],
});

This is my PR: https://github.com/Azure/azure-sdk-for-js/pull/30049

Screenshots image

Additional context Add any other context about the problem here.

danielszaniszlo commented 3 months ago

I was able to fix the issue by modifying the removeSanitizers:

await recorder.start({
      envSetupForPlayback: replaceableVariables,
      sanitizerOptions: {
        bodyKeySanitizers: [
          {
            value: replaceableVariables.STORAGE_ACCOUNT_SAS_URI,
            jsonPath: "$..location",
            regex: "^(?!.*FAKE_STORAGE_ACCOUNT).*",
          }
        ],
      },
      removeCentralSanitizers: ["AZSDK4001", "AZSDK2030", "AZSDK3430","AZSDK3493"],
    });