# How set context in new transaction manually for APM Agent .NET Framework

**URL:** <https://discuss.elastic.co/t/how-set-context-in-new-transaction-manually-for-apm-agent-net-framework/294318>\
**Category:** APM\
**Tags:** dotnet\
**Created:** [January 13, 2022, 7:06pm UTC](https://discuss.elastic.co/t/how-set-context-in-new-transaction-manually-for-apm-agent-net-framework/294318 "2022-01-13T19:06:18Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![juliano.maciel](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/juliano.maciel/32/100169_2.png) [@juliano.maciel](https://discuss.elastic.co/u/juliano.maciel)\
**Post date:** [January 13, 2022, 7:06pm UTC](https://discuss.elastic.co/t/how-set-context-in-new-transaction-manually-for-apm-agent-net-framework/294318/1 "2022-01-13T19:06:18Z")

</div>

Hi, I'm instrumenting an app manually because it uses the windows self-host to run as a local service, when creating a new transaction how can I get the content of the body and set it manually in the new transaction?

 ![image](https://us1.discourse-cdn.com/elastic/original/3X/6/2/622c1d6189a9f84df01049b623616b8bb669e14d.png)

The objective is to know the information that the client passes to an api when there is an object reference error.

---

<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:** [January 17, 2022, 5:01pm UTC](https://discuss.elastic.co/t/how-set-context-in-new-transaction-manually-for-apm-agent-net-framework/294318/2 "2022-01-17T17:01:37Z")

</div>

The body is stored in the `transaction.Context.Request` property - in general things that the agent stores on specific events is on the `Context`.

So you'd do something like this:

```auto
transaction.Context.Request = new Request(method, new Url{Full = url}){Body = "[SET BODY HERE]"};

```

Remaining question is, how do you get the URL values, the method and the body itself. I don't know the specifics of your app, but don't you have access to the static `HttpContext` property? These things are usually stored there. So, ideally you'd be able to read the values via the `HttpContext` and just store those on `Transaction.Context`.

---

<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:** [February 7, 2022, 1:01pm UTC](https://discuss.elastic.co/t/how-set-context-in-new-transaction-manually-for-apm-agent-net-framework/294318/3 "2022-02-07T13:01:40Z")

</div>

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