Kibana version: 6.8.0
Elasticsearch version: 6.8.0
APM Server version: 6.8.0
APM Agent language and version: dotnet 1.0.0-beta1
Browser version: Firefox Quantum 67.0.4 (64-bit)
Original install method: Download pages, all versions listed above.
Fresh install or upgraded from other version? Fresh installs.
Is there anything special in your setup? Everything is installed and accessed locally.
Description of the problem including expected versus actual behavior. Please include screenshots (if relevant):
My goal is to utilize the agent with non-ASP .net (i.e., non-web) C# applications, but I’m having difficulties getting the dotnet APM agent to talk to the APM server using the public API.
I have tried a few different approaches: straightforward public API calls (with configuration set via appsettings.json and/or Environment.SetEnvironmentVariable calls) do not seem to send entries to the APM server. Projects using the web ASP.net agent implementation (via the call in Startup.cs) do send entries to the APM server, including those from public API calls.
I tried the code RenauldGelai posted in an issue on the agent’s Github repo (https://github.com/elastic/apm-agent-dotnet/issues/304) – notably their CustomLogger and CustomConfigurationReader classes for the purposes of calling Agent.Setup(). This does work but seemingly contradicts the notion that the public API doesn’t require setup.
I tried the HttpListenerSample from the Github repo’s sample code – I literally copied and pasted the provided code into a new project’s Program.cs and ran it. This sample code worked, even with the Agent.Subscribe() call commented out – so only the public API was called - there was no configuration, so the defaults all worked.
I’m really puzzled and probably missing something simple, but for example the following code does not send entries to the APM server. I admit that I’m a little outside my comfort zone here and understand that I’m about to ask a pretty broad question, but can you provide any guidance as to what I’m missing, and futher – what is the best way to get at configurations via files e.g., appsettings.json or via environment variables?
using System;
using System.Threading;
using Elastic.Apm;
using Elastic.Apm.Api;
namespace apmapp2
{
internal class Program
{
private static void Main(string[] args)
{
Thread.Sleep(150);
Agent.Tracer.CaptureTransaction("ApmApp2.Transaction", ApiConstants.ActionExec, () =>
{
Console.WriteLine("Hello World! " + (GetRandomNum()).ToString());
});
}
private static int GetRandomNum() => Agent.Tracer.CurrentTransaction.CaptureSpan("ApmApp2.Transaction.GetRandomNum", "Random", () =>
{
Thread.Sleep(150);
return new Random().Next();
});
}
}
And corresponsding appsettings.json:
{
"Logging": {
"LogLevel": {
"Default": "Warning"
}
},
"AllowedHosts": "*",
"ElasticApm":
{
"ServiceName": "ApmTest3",
"LogLevel": "Debug",
"ServerUrls": "http://localhost:8200",
"TransactionSampleRate": 1.0
}
}