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

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 in console application(using httplistener).so we want create multiple spans in single transaction in vb.net using httplistener. Also is there any other method to creating multiple span excluding httplistener?

Hi @Vinod.Kashid, welcome here :clap:

we want create multiple spans in single transaction

You can do that, that's part of the Public Agent API , 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 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.

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

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.

Does the process terminate right after the transaction is ended? This comment explains it: Transactions using OpenAPI C# is not showing up

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