# How to create multiple span within single transaction(using Httplistener) using vb.net

**URL:** <https://discuss.elastic.co/t/how-to-create-multiple-span-within-single-transaction-using-httplistener-using-vb-net/222638>\
**Category:** APM\
**Tags:** dotnet\
**Created:** [March 9, 2020, 4:47am UTC](https://discuss.elastic.co/t/how-to-create-multiple-span-within-single-transaction-using-httplistener-using-vb-net/222638 "2020-03-09T04:47:35Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Vinod.Kashid](https://avatars.discourse-cdn.com/v4/letter/v/8baadc/32.png) [@Vinod.Kashid](https://discuss.elastic.co/u/Vinod.Kashid)\
**Post date:** [March 9, 2020, 4:47am UTC](https://discuss.elastic.co/t/how-to-create-multiple-span-within-single-transaction-using-httplistener-using-vb-net/222638/1 "2020-03-09T04:47:35Z")

</div>

**Kibana version** :7.6.0

**Elasticsearch version** :7.6.0

**APM Server version** :7.6.0

**APM Agent language and version** : Elastic APM .NET Agent 1.3.1.0

**Browser version** :Chrome 80.0.3987.122 (Official Build) (64-bit)

\*\*Fresh install or upgraded from other version?\*\*Fresh

**Description of the problem** : we are creating transaction using [vb.net](http://vb.net) in console application(using httplistener).so we want create multiple spans in single transaction in [vb.net](http://vb.net) using httplistener. Also is there any other method to creating multiple span excluding httplistener?

---

<div class="post-metadata">

**Author:** ![GregKalapos](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/gregkalapos/32/37205_2.png) [@GregKalapos](https://discuss.elastic.co/u/GregKalapos)\
**Post date:** [March 14, 2020, 9:41pm UTC](https://discuss.elastic.co/t/how-to-create-multiple-span-within-single-transaction-using-httplistener-using-vb-net/222638/2 "2020-03-14T21:41:38Z")

</div>

Hi @Vinod.Kashid, welcome here 👏

> we want create multiple spans in single transaction

You can do that, that's part of the [Public Agent API](https://www.elastic.co/guide/en/apm/agent/dotnet/current/public-api.html) , once you have an `ITransaction` instance you can just call either the `StartSpan` or the `CaptureSpan` function - each time you do this you'll capture a new span for your transaction. The `CaptureSpan` method receives a lambda, so you can basically just wrap any code into that method, the `StartSpan` gives you an `ISpan` instance that you need to end by calling `.End()` on it.

[Here](https://www.elastic.co/guide/en/apm/agent/dotnet/current/public-api.html) are the docs - all C#, but I hope it helps.

I also drafted a small sample for you - maybe that's helpful. I don't use `HttpListener` here, but it does not really change anything - instead of `Sub Main` you can do the same in the part where the incoming HTTP request is handled.

```auto
Imports System
Imports System.Threading

Module Program
    Sub Main(args As String())
            
        Dim transaction = Elastic.Apm.Agent.Tracer.StartTransaction("MyTransaction", "SampleTransaction")
        
        'Start 1. span on the transaction:
        Dim span1 = transaction.StartSpan("Span1", "SampleSpan")
        
        'Execute code here which encapsulated into span1
            
        'Start 2. span on the transaction:
        Dim span2 = transaction.StartSpan("Span2", "SampleSpan")
            
        'Execute code here which encapsulated into span2
   
        'Start a subspan on span1
        Dim span3 = span1.StartSpan("Span3", "SampleSpan")
        
        'Execute code here which encapsulated into span3
            
        'end all spans
        span1.End()
        span2.End()
        span3.End()
            
        'end the transaction
        transaction.End()

        'Make sure the process does not terminate before the agent sends all data
        Thread.Sleep(15000)
    End Sub
End Module

```

---

<div class="post-metadata">

**Author:** ![Vinod.Kashid](https://avatars.discourse-cdn.com/v4/letter/v/8baadc/32.png) [@Vinod.Kashid](https://discuss.elastic.co/u/Vinod.Kashid)\
**Post date:** [March 24, 2020, 8:59am UTC](https://discuss.elastic.co/t/how-to-create-multiple-span-within-single-transaction-using-httplistener-using-vb-net/222638/3 "2020-03-24T08:59:37Z")

</div>

We did the same thing but kibana does not show the transaction and span. I think spans and transactions together are not getting captured in apm. Please help for this issue.

---

<div class="post-metadata">

**Author:** ![GregKalapos](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/gregkalapos/32/37205_2.png) [@GregKalapos](https://discuss.elastic.co/u/GregKalapos)\
**Post date:** [March 24, 2020, 9:20am UTC](https://discuss.elastic.co/t/how-to-create-multiple-span-within-single-transaction-using-httplistener-using-vb-net/222638/4 "2020-03-24T09:20:05Z")

</div>

Does the process terminate right after the transaction is ended? This comment explains it: [Transactions using OpenAPI C# is not showing up](https://discuss.elastic.co/t/transactions-using-openapi-c-is-not-showing-up/221492/18)

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [April 14, 2020, 5:20am UTC](https://discuss.elastic.co/t/how-to-create-multiple-span-within-single-transaction-using-httplistener-using-vb-net/222638/5 "2020-04-14T05:20:16Z")

</div>

This topic was automatically closed 20 days after the last reply. New replies are no longer allowed.
