# DB Span Stacktrace reporting wrong filename

**URL:** <https://discuss.elastic.co/t/db-span-stacktrace-reporting-wrong-filename/329485>\
**Category:** APM\
**Tags:** dotnet\
**Created:** [April 6, 2023, 6:50am UTC](https://discuss.elastic.co/t/db-span-stacktrace-reporting-wrong-filename/329485 "2023-04-06T06:50:34Z")\
**Posts on this page:** 1\
**Showing post:** 4

<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:35am UTC](https://discuss.elastic.co/t/db-span-stacktrace-reporting-wrong-filename/329485/4 "2023-04-08T09:35:46Z")

</div>

> I have also done profiler auto instrumentation for another asp .net core application targeting **net6.0**.  
> [NopCommerce](https://github.com/nopSolutions/nopCommerce/tree/release-4.50.4)  
> For this application I was getting correct filename in the span stacktrace.  
> Can you explain this behaviour?

So, in additional to what I wrote in the previous answer, the agent actually tries to find the `.cs` file if possible - so indeed, the agent has a "best effort" mechanism to figure out the original `.cs` file, if this fails, the agent just reports the assembly (which is the `.dll` file) that is executed during runtime.

For determining the `.cs` file the agent uses this method: [StackFrame.GetFileName Method (System.Diagnostics) | Microsoft Learn](https://learn.microsoft.com/en-us/dotnet/api/System.Diagnostics.StackFrame.GetFileName?view=net-7.0)

That can determine the `.cs` file when debugging symbols are present and currently set up. If that method returns `null`, the agent just reports `.dll` files as the file name.

You can see this logic here: [https://github.com/elastic/apm-agent-dotnet/blob/main/src/Elastic.Apm/Helpers/StacktraceHelper.cs#L87](https://github.com/elastic/apm-agent-dotnet/blob/main/src/Elastic.Apm/Helpers/StacktraceHelper.cs#L87)

> How does the agent determine to which source file the function belongs to?

You opened another entry as well, I just see: [Custom Stacktrace for Transaction](https://discuss.elastic.co/t/custom-stacktrace-for-transaction/329160/1)

Is this question related to that entry. That indeed seems to be a bug (not sure yet, I need to dig deeper).

---

_[View the full topic](https://discuss.elastic.co/t/db-span-stacktrace-reporting-wrong-filename/329485)._
