Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Example of using the Elastic APM Helper in a controller.
// NuGet: Elastic.Apm
using Blitzkrieg.ElasticApmHelper;
using Elastic.Apm.Api;
// ...
namespace Blitzkrieg.DemoWeb {
public class ValuesController : ApiController
{
private Libs.ElasticWrapper alm = new ElasticWrapper();
public string Get(int id)
{
string result = string.Empty;
alm.ElasticTransactionHelper($"Get({id})", ApiConstants.TypeRequest, () =>
{
alm.ElasticSpanHelper("Fake DB", ApiConstants.TypeDb, () =>
{
// notice it has access to the containing scope so you can set those variable (no returns or out needed)
result = "value1";
});
});
return result;
}
public void Post([FromBody]string value)
{
alm.ElasticTransactionHelper($"Post({value})", ApiConstants.TypeRequest, () =>
{
// You can have zero to many of these blocks inside the transaction scope
alm.ElasticSpanHelper("Fake DB", ApiConstants.TypeDb, () =>
{
// your unit of work inside a span
});
});
}
}
}
@BlitzkriegSoftware

This comment has been minimized.

Copy link
Owner Author

BlitzkriegSoftware commented Sep 10, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.