# Custom Stacktrace for Transaction

**URL:** <https://discuss.elastic.co/t/custom-stacktrace-for-transaction/329160>\
**Category:** APM\
**Tags:** dotnet\
**Created:** [April 3, 2023, 6:37am UTC](https://discuss.elastic.co/t/custom-stacktrace-for-transaction/329160 "2023-04-03T06:37:57Z")\
**Posts on this page:** 1\
**Showing post:** 1

<div class="post-metadata">

**Author:** ![AbhijithCV](https://avatars.discourse-cdn.com/v4/letter/a/ed655f/32.png) [@AbhijithCV](https://discuss.elastic.co/u/AbhijithCV)\
**Post date:** [April 3, 2023, 6:37am UTC](https://discuss.elastic.co/t/custom-stacktrace-for-transaction/329160/1 "2023-04-03T06:37:57Z")

</div>

**Elasticsearch version** : v8.1.2  
**APM Agent language and version** : dotnet Agent v1.18.0  
Hi,  
I have a requirement for fetching details of every function calls happened during execution of one transaction. The way I am currently doing it is by making code changes in the agent source code. Inside `End()` function of `Transaction.cs`  
[source link](https://github.com/elastic/apm-agent-dotnet/blob/31bb64353e9cc005906ea29bc086604fcdeda388/src/Elastic.Apm/Model/Transaction.cs#L598).  
And I understood that this function will be called at the end of a transaction, so thought its the best place to collect the stacktrace.

```auto
public void End()
{
            StackTrace stackTrace = new StackTrace(true);
            // external function call to filter out library function calls from stack frame 
            // and convert it into json to store in custom field of the transaction 
            String jsonString = ConvertStackTraceToJSON(stackTrace);
            this.Custom.Add("stacktrace", jsonString);
            ....
}

```

but the issue is I am only getting stacktrace of few function calls and missing lot of other functions in the code.  
Is there a better way to capture details of every function call ocurred during the transaction, across all the active threads in the dotnet core application.

**Update** : I have tracked down the error to my custom code which was filtering out stackframe with namespace of **System.**  **Microsoft.** But the span stacktrace reported for db query was reporting the filename wrongly:

```auto
{
                "exclude_from_grouping" : false,
                "filename" : """C:\Program Files\dotnet\shared\Microsoft.NETCore.App\3.1.32\System.Private.CoreLib.dll""",
                "classname" : "CourseLibrary.API.Services.CourseLibraryRepository",
                "line" : {
                  "number" : 0
                },
                "function" : "GetAuthors x 1",
                "module" : "CourseLibrary.API, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null"
 }

```

The **GetAuthorx1** function is part of the my application code and not in the C:\Program Files\dotnet\shared\Microsoft.NETCore.App\3.1.32\System.Private.CoreLib.dll

The application being traced is using netcoreapp3.1

Issue: file name reported by the span stacktrace is wrong

---

_[View the full topic](https://discuss.elastic.co/t/custom-stacktrace-for-transaction/329160)._
