# Basic example of Span with RUM?

**URL:** <https://discuss.elastic.co/t/basic-example-of-span-with-rum/382794>\
**Category:** APM\
**Tags:** rum\
**Created:** [October 16, 2025, 6:20pm UTC](https://discuss.elastic.co/t/basic-example-of-span-with-rum/382794 "2025-10-16T18:20:12Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![learningelastic](https://avatars.discourse-cdn.com/v4/letter/l/958977/32.png) [@learningelastic](https://discuss.elastic.co/u/learningelastic)\
**Post date:** [October 16, 2025, 6:20pm UTC](https://discuss.elastic.co/t/basic-example-of-span-with-rum/382794/1 "2025-10-16T18:20:12Z")

</div>

I am trying to test the span feature of RUM. So i wrote this simple code:

```auto
<!DOCTYPE html>
<html lang="en">
  <head>
	<meta charset="utf-8" />
	<title>Span</title>
	<script src="https://unpkg.com/@elastic/apm-rum@5.12.0/dist/bundles/elastic-apm-rum.umd.min.js"></script>
   <script>
const apm = window.elasticApm.init({
  serviceName: 'rumexperiment',
  serverUrl: 'http://192.168.0.101:8200',
  serviceVersion: '0.90'
});
const sendSpan = (msg, isBlocking) => {
  //const transaction = apm.startTransaction(msg + '-transaction', 'user-interaction');
  const transaction = apm.getCurrentTransaction();

  //const span = apm.startSpan(msg, 'custom', {blocking: isBlocking});
  const span = transaction.startSpan(msg, 'custom', {blocking: isBlocking});

  setTimeout(() => {
	span.end();
	transaction.end();
	console.log('End Span');
  }, 1000);
};
   </script>
  </head>
  <body>
	<button id="blocking" name="blocking" onClick="sendSpan('MySpanBlocking', true)">Send Span - Blocking</button>
	<button id="non_blocking" name="non_blocking" onClick="sendSpan('MySpanNonBlocking', false)">Send Span - Not Blocking</button>
  </body>
</html>

```

I visit the web page in either firefox or chrome. Then I go to my `Kibana>Observability>Services>rumexperiment` and I can see that Kibana APM has recorded my web page visit. Pressing refresh in my browser for my web page successfully transmits a log to Kibana APM and i see each page load in the `Transaction` widget.

However, when I press any of the buttons on the web page, that information is NOT sent over to Kibana Observability Services rumexperiment. I do not see any of my span details sent over. Can someone tell me how to test a basic example of a span or what i did wrong in my code above?

---

<div class="post-metadata">

**Author:** ![carly.richmond](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/carly.richmond/32/104935_2.png) [@carly.richmond](https://discuss.elastic.co/u/carly.richmond)\
**Post date:** [October 16, 2025, 8:33pm UTC](https://discuss.elastic.co/t/basic-example-of-span-with-rum/382794/2 "2025-10-16T20:33:05Z")

</div>

Hi @learningelastic,

Are there any errors in the DevTools console? It's a long shot but it's probably worth confirming that you're using a supported browser [as per the supported technologies](https://www.elastic.co/docs/reference/apm/agents/rum-js/supported-technologies)

It might be worth trying out some of the [debugging steps](https://www.elastic.co/docs/troubleshoot/observability/apm-agent-rum-js/apm-real-user-monitoring-javascript-agent) to see if you can see an error. But alternatively you could be being caught out by [the agent discarding transactions with no spans](https://www.elastic.co/docs/reference/apm/agents/rum-js/supported-technologies#user-interactions):

> The RUM agent automatically instruments click event listeners that are registered by the application. The click events are captured as `user-interaction` transactions. However, to avoid sending too many `user-interaction` transactions to the server, the agent discards transactions with no spans (e.g. no network activity). Furthermore, if the click interaction results in route change, then a `route-change` transaction would be captured instead.
> 
> The transaction name can be influenced either by using the `name` or preferably the `data-transaction-name` HTML attribute.

Do share any debug information that you manage to collect.

Hope that helps!

---

<div class="post-metadata">

**Author:** ![learningelastic](https://avatars.discourse-cdn.com/v4/letter/l/958977/32.png) [@learningelastic](https://discuss.elastic.co/u/learningelastic)\
**Post date:** [October 16, 2025, 10:22pm UTC](https://discuss.elastic.co/t/basic-example-of-span-with-rum/382794/3 "2025-10-16T22:22:00Z")

</div>

thanks, i’m still working through this, and here’s what i discovered so far:

i do not see any errors in the developer tools of either Firefox or Chrome. In both firefox and chrome, i always see a `202` status for post submissions to a `http://192.168.0.101:8200/intake/v2/rum/events`every time i click either of the buttons.

But when I look in Kibana, sometimes the span appears, and sometimes it doesn’t. I can’t consistently reproduce either outcome. When the span DOES appear in kibana, it would be found under: `Transactions>Click - button[“blocking”]`, and then shown in the graph here:

 ![image](https://us1.discourse-cdn.com/elastic/original/3X/9/3/93753cb11f4904e6a6d76a67e54332ecf290c70c.png)

But I can’t consistently reproduce this outcome. I’m not sure why it works sometimes and not other times. Maybe one out of every 20 random button clicks, does my span actually appear in Kibana

@carly.richmond

---

<div class="post-metadata">

**Author:** ![David\_Luna\_Bistuer](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/david_luna_bistuer/32/122147_2.png) [@David\_Luna\_Bistuer](https://discuss.elastic.co/u/David_Luna_Bistuer)\
**Post date:** [October 17, 2025, 2:23pm UTC](https://discuss.elastic.co/t/basic-example-of-span-with-rum/382794/4 "2025-10-17T14:23:50Z")

</div>

> [@learningelastic](#):
>
> i do not see any errors in the developer tools of either Firefox or Chrome. In both firefox and chrome, i always see a `202` status for post submissions to a `http://192.168.0.101:8200/intake/v2/rum/events`every time i click either of the buttons.

Hi @learningelastic

If you see these requests it means the transactions have been sent to the APM server. So we can check if the documents are stored in ES by doing a search in the discover section. Just use a simple query to get the documents that have `transaction.name` property. Put this filter in the filter box.

```auto
transaction.name: *

```

Another way to check it is if you go to Observability → Traces menu. Since the RUM transactions are the start of the trace you will see them listed there.

I did some tests and found a similar issue. I see the transaction documents in discover and in traces menu but they do not appear in the service summary. I’ll check with the team.

PS: The code you showed is straight forward but I would suggest to use blocking spans always. Click transaction is managed and we need a blacking span to keep it open. ref: [Custom Transactions | APM RUM JavaScript agent](https://www.elastic.co/docs/reference/apm/agents/rum-js/custom-transactions#custom-managed-transactions)

Cheers,

David

---

<div class="post-metadata">

**Author:** ![learningelastic](https://avatars.discourse-cdn.com/v4/letter/l/958977/32.png) [@learningelastic](https://discuss.elastic.co/u/learningelastic)\
**Post date:** [November 5, 2025, 2:45am UTC](https://discuss.elastic.co/t/basic-example-of-span-with-rum/382794/5 "2025-11-05T02:45:12Z")

</div>

@David_Luna_Bistuer Thank you! I confirmed that I can consistently see my `Span` events when I click into `Observabilty>Applications>Traces>Click - button[“blocking or non blocking or anything”}]`

For example, click here first:

 ![image](https://us1.discourse-cdn.com/elastic/original/3X/2/0/20dceb58dbaa65e8273a247ac03e55542ef43ea3.png)  
Then click on any of the Click - button[“\*”] and you will see it at the bottom:

 ![image](https://us1.discourse-cdn.com/elastic/original/3X/d/c/dc8291afa0ec6f4651788546e7eb6dc8a15a0dff.png)

So my folow up question is how come it consistenly appears under Traces, but not under the `Service Inventory> {application name} > Transactions`?

I remember there was some documentation explaining the relationship between Span, Transaction and Traces. But I had difficulty understanding it when I first read it….would it be related to what I just experienced here?
