elastic / apm-agent-dotnet

https://www.elastic.co/guide/en/apm/agent/dotnet/current/index.html
Apache License 2.0
582 stars 209 forks source link

Profiler auto instrumentation #1522

Closed russcam closed 2 years ago

russcam commented 3 years ago

The current approaches to instrumenting an application with the APM .NET agent are:

or

Whilst these two approaches work for the common use cases, there are some challenges:

  1. Some libraries that we wish to provide instrumentations for do not lend themselves well to being instrumented
    1. they may not provide relevant API hooks that allow an APM agent integration to be written
    2. their usage pattern may take a form which makes it unfeasible to capture a meaningful transaction or span
  2. Requiring the installation of NuGet packages into a project will not work with our aims of .NET application auto instrumentation with Elastic Agent
  3. Startup hooks would work with our aims for Elastic agent but is limited to .NET Core 3.0+
  4. Instrumentations may be dependent/compatible with specific assembly versions

With these challenges in mind, we are looking at leveraging the CLR profiling APIs to instrument at runtime. This is a fairly common approach to instrumenting methods at runtime, using a profiler to rewrite IL instructions at JIT/reJIT.

The initial set of instrumentations to target are:

  1. ADO.NET providers for SQL Server, MySQL, Postgres, Oracle and Sqlite
  2. Kafka
  3. RabbitMQ
dannystommen commented 2 years ago

Hi @russcam,

This issues should have resolved not seeing DB queries using ADO.NET for MySQL in our APM. However I'm still not able to see any MySQL queries in APM. Is there anything adionational we need to configure?

Thanks, Danny

russcam commented 2 years ago

@dannystommen Ensure that

  1. the profiler is configured to instrument your application
  2. The MySQL library and version used is supported (currently MySql.Data 6.7.0 - 8.x.x. all supported libraries are on the docs page)
  3. There is an active transaction when a MySql command is executed. For many of the APM agent integrations like ASP.NET and ASP.NET Core, there will be an active transaction created by the integration for the incoming request.

If all of this looks OK, but you're still not seeing spans for MySql commands, you may need to share more details from the profiler logs. If this is the case, I would recommend opening a Discuss topic to discuss, as it'll be a better place to help. Feel free to @ me on the topic.

nakbsaxo commented 5 months ago

Hi I have added below environment variables as suggested in documentation but not seeing any data coming up

https://www.elastic.co/guide/en/apm/agent/dotnet/current/setup-auto-instrumentation.html

set CORECLR_ENABLE_PROFILING = "1" set CORECLR_PROFILER = "{FA65FE15-F085-4681-9B20-95E04F6C03CC}" set CORECLR_PROFILER_PATH = "\elastic_apm_profiler.dll" set ELASTIC_APM_PROFILER_HOME = "" set ELASTIC_APM_PROFILER_INTEGRATIONS = "\integrations.yml" set ELASTIC_APM_SERVER_URL = "" set ELASTIC_APM_SECRET_TOKEN = ""

any idea what's wrong or i am I missing something?

stevejgordon commented 5 months ago

@nakbsaxo Commenting on a closed issue is not the best place to get assistance with your query. Please post to our community forum; we will try to assist there.