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

Not able to exclude URL on page-load transaction #1331

Open
talhaawan7 opened this issue Jan 24, 2023 · 2 comments
Open

Not able to exclude URL on page-load transaction #1331

talhaawan7 opened this issue Jan 24, 2023 · 2 comments

Comments

@talhaawan7
Copy link

talhaawan7 commented Jan 24, 2023

Hi team!

We're trying to stop a certain URL from appearing in the APM dashboard.

Here's the example code in React:

import { useEffect } from "react";
import axios from "axios";
import { init as initApm } from "@elastic/apm-rum";

const EXCLUDE_URL = "https://catfact.ninja/fact";

function App() {
  useEffect(() => {
    initApm({
      serviceName: "{{serviceNAme}}",
      serverUrl: "{{url}}",
      environment: "testing",
      ignoreTransactions: [new RegExp(EXCLUDE_URL)],
    }).addFilter((payload) => {
      // addFilter not useful
      return payload;
    });
  }, []);

  useEffect(() => {
    axios.get(EXCLUDE_URL).then((res) => {
      console.log(res.data);
    });
  }, []);

  return <div className="App"></div>;
}

export default App;
 

Using version @elastic/apm-rum": "^5.12.0,

I've put the URL in ignoreTransactions, but that doesn't seem to work on page-load. It only works in later transactions. The other suggested way was to use addFilter, but the URL I'm trying to exclude doesn't get in this filter for the first transaction on page-load.

If I delay the call by some seconds (around 2 or above), I get two transactions, and the ignore works for the second call. But I want to avoid this workaround and send the call immediately but exclude it from APM.

useEffect(() => {
    setTimeout(() => {
      axios.get(EXCLUDE_URL).then((res) => {
        console.log(res.data);
      });
    }, 2000);
  }, []);

Also, when I console.log the payload inside addFilter it only has one transaction and contains no span (as mentioned in the docs here)
Screenshot 2023-01-24 at 6 48 07 PM

@devcorpio
Copy link
Contributor

devcorpio commented Jan 24, 2023

Hi @talhaawan7,

Thanks for reaching us!

If I delay the call by some seconds (around 2 or above), I get two transactions, and the ignore works for the second call. But I want to avoid this workaround and send the call immediately but exclude it from APM.

The first time doesn't work because the request that you are doing (with axios) is being included as a span of the ongoing transaction (the page load one). This is important given that the ignoreTransactions checks transactionNames and not spans. More info on this link

The second time works because there is no ongoing transaction, so the agent creates an http-request transaction from the request, so, since this time is not a span the ignoreTransaction config applies properly.

There is a pending issue whose goal is to implement an ignoreSpan config: #1130. You will also find there a workaround that should help you.

The other suggested way was to use addFilter, but the URL I'm trying to exclude doesn't get in this filter for the first transaction on page-load.

Could you check if it starts working with the workaround provided shared above?

Btw, in case helps you for debugging purposes, there is a way to see the payload of the beacons sent to the server decoded that is available since 5.11.1. More info here: https://www.elastic.co/guide/en/apm/agent/rum-js/current/troubleshooting.html#disable-events-payload-compression

Let me know if this helps you.

Thanks,
Alberto

@talhaawan7
Copy link
Author

Hi @devcorpio

Thank you for the reply!

The workaround only helps remove a particular span from showing up on the APM dashboard, but it's still calculated in the total time calculation. So the whole purpose of ignoring it is lost.

I see another issue related to this, which in turn is linked again with the ignoreSpan feature request.

Just want to confirm: As of now, is there any way to exclude the url AND exclude it from the total time calculation?

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

No branches or pull requests

2 participants