Hi,
I'm trying to get insights in our MySQL queries in our APM transactions.
I've been following this guide: Profiler Auto instrumentation | APM .NET Agent Reference [master] | Elastic
Our application is containerized (normally hosted in kubernetes, used local docker for this test).
The docker file I've created
FROM mcr.microsoft.com/dotnet/aspnet:6.0 as base
WORKDIR /app
EXPOSE 80
FROM mcr.microsoft.com/dotnet/sdk:6.0 AS build
ARG AGENT_VERSION=1.14.0
WORKDIR /src
COPY . .
WORKDIR /src/API
RUN apt-get -y update && apt-get -yq install unzip
RUN curl -L -o elastic_apm_profiler_${AGENT_VERSION}.zip https://github.com/elastic/apm-agent-dotnet/releases/download/${AGENT_VERSION}/ElasticApmAgent_${AGENT_VERSION}.zip
RUN unzip elastic_apm_profiler_${AGENT_VERSION}.zip -d /elastic_apm_profiler_${AGENT_VERSION}
RUN dotnet publish API.csproj -c Release -o /app
FROM base AS final
WORKDIR /app
ARG AGENT_VERSION=1.14.0
COPY --from=build /app .
COPY --from=build /elastic_apm_profiler_${AGENT_VERSION} /elastic_apm_profiler
RUN mkdir /test
ENV CORECLR_ENABLE_PROFILING=1
ENV CORECLR_PROFILER={FA65FE15-F085-4681-9B20-95E04F6C03CC}
ENV CORECLR_PROFILER_PATH=/elastic_apm_profiler/libelastic_apm_profiler.so
ENV ELASTIC_APM_PROFILER_HOME=/elastic_apm_profiler
ENV ELASTIC_APM_PROFILER_INTEGRATIONS=/elastic_apm_profiler/integrations.yml
ENTRYPOINT ["dotnet", "API.dll"]
In the Startup.cs of the API project:
Environment.SetEnvironmentVariable("ELASTIC_APM_ENVIRONMENT", "env.");
Environment.SetEnvironmentVariable("ELASTIC_APM_SERVICE_NAME", "permission-api");
Environment.SetEnvironmentVariable("ELASTIC_APM_SECRET_TOKEN", "##");
Environment.SetEnvironmentVariable("ELASTIC_APM_SERVER_URL", "##");
app.UseAllElasticApm();
And an example of a DB query in 1 of our repositories:
using var connection = await _ConnectionFactory.CreateConnectionAsync();
const string statement = "SELECT * FROM partner_permission WHERE ActorId = @actorId;";
return await connection.QueryAsync<PartnerPermission>(statement, new { actorId });
Even tried adding a transaction:
using var connection = await _ConnectionFactory.CreateConnectionAsync();
using var transaction = connection.BeginTransaction();
const string statement = "SELECT * FROM partner_permission WHERE ActorId = @actorId;";
return await connection.QueryAsync<PartnerPermission>(statement, new { actorId }, transaction);
In the APM traces I still see a gap where the MySQL queries are being executed.
(relevant) Nuget packages used:
Elastic.Apm.NetCoreAll 1.14.0
MySql.Data 8.0.28
Dapper 2.0.123
What am I missing?
Thanks,
Danny