# 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:** 4\
**Page:** 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

---

<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:** [April 8, 2023, 9:40am UTC](https://discuss.elastic.co/t/custom-stacktrace-for-transaction/329160/2 "2023-04-08T09:40:03Z")

</div>

Hi @AbhijithCV,

could you give us a minimal reproducer of this issue?

---

<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 10, 2023, 6:22am UTC](https://discuss.elastic.co/t/custom-stacktrace-for-transaction/329160/3 "2023-04-10T06:22:31Z")

</div>

Hi @GregKalapos  
I have given steps to reproduce the bug in [DB span stacktrace wrong filename](https://discuss.elastic.co/t/db-span-stacktrace-reporting-wrong-filename/329485/5)

---

<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:** [May 1, 2023, 2:22am UTC](https://discuss.elastic.co/t/custom-stacktrace-for-transaction/329160/4 "2023-05-01T02:22:49Z")

</div>

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