I am running into an issue when working with the .NET Core Microservices Agent for Windows agent. I have a sample webapi that I wrote that just has a couple of basic controllers in it. I am trying to follow the instructions listed in the below URL.
https://docs.appdynamics.com/display/PRO45/Install+the+.NET+Core+Microservices+Agent+for+Windows
I am able to install the nuget package identified, I was able to configure the config file and I can launch the application and see it added to the AppD dashboard. What I cannot do is add the reference "using AppDynamics" to any of my classes so that I can define a business transaction in my controllers. When I try to add it, intellisense cannot find the package and if I add it manually, I get a "missing namespace" error when I try to build the project.
Am I missing something in the setup? I know it is at least partially setup correctly or else I would not be able to the app in the Applications list on the website. Any guidance would be appreciated.
Thanks,
You don't have to manually add reference. I do not that mentioned as part of the documentation.
Just make sure to set Copy Always to True for each of the Agent files/dlls and then just publish your application after creating necessary environment variables. BTs will get identified OOTB.
On Windows, we support fully functional Agent. On Linux, we offer an SDK for now.
Thanks,
Raunak
Hi Robert,
The container itself is Windows or Linux ? I am talking about the actual container host on which application is hosted.
Thanks,
Raunak
Raunak,
Thanks for the response. This is an interesting scenario. I am developing on Windows but will be deploying into Microsoft's Ubuntu Linux container. I have been able to get the Windows Agent to work when running locally, not in a container, after making some adjustments to the configuration. I mostly wanted to verify that I can connect to the controller and that the settings were right. I then switched over to using the Linux SDK in the MS Linux Docker container. It was not working at all and there were no logs to tell me what was going on. So I took a step back and moved my code to an Ubuntu server and was trying to build the code there. I followed the instructions that I can see online (https://docs.appdynamics.com/display/PRO45/.NET+Core+for+Linux+SDK) for the linux SDK. At the bottong of that page there is a screenshot for adding the code to start and stop a business transaction though when I try to replicate that the "using" statement cannot find the namespace "AppDynamics". When I tried to build it fails. So I assumed that maybe it is like the Windows Agent plugin and does not need the transaction references, so I removed them.
Now when I build the project it builds without issues. When I try to run the project, on the other hand, it failed. I am getting the error
An assembly i the application dependencies manifest {project name} was not found: package: 'AppDynamics.AgentSDK', version: '4.5.1' path: 'lib/netstandard2.0/AppDynamics.Agent.SDK.dll'
Per the instructions, I copied the sdk files to a folder in the project, instead of mapping to the nuget location, called packages(./packages/appdynamics.agentsdk/4.5.1/....). I made sure that there was a reference in the csproj file to copy the sdk folders to the build location and I can verify that the path exists when the build process runs. The project builds fine and the files are copied to the build folder, but when I try to launch the project I get the previously mentioned error.
My next step was going to be moving the SDK folders down a few levels so that the lib and runtime folders are at the root of the project. Though I have not tried that yet.
Any advice would be welcome. If there is a sample project that you all have that shows how the project should be layed out and build and runs fine I would love to use that as a template.
Hi Robert,
I have written basic steps needed to setup a sample application using linux docker containers.
Instructions for setting up sample environment for using Linux SDK -
Step 1: Getting the Sample Code
mkdir MvcApp
cd MvcApp
dotnet new mvc
Step 2: Test the App if it is working fine
dotnet restore
dotnet run
Check in Browser -> http://localhost:5000
Step 3: Add Nuget Package in the Project -
dotnet add package AppDynamics.AgentSDK
Step 4: Modify your project to use the AppDynamics SDK -
e.g: Edit HomeController.cs and add following -
using AppDynamics;
...
namespace MvcApp.Controllers
{
public class HomeController : Controller
{
public IActionResult SomePage()
{
var currCtxId = AgentSDK.StartBusinessTransaction("DemoBT", "ASP_DOTNET", "");
// Code here calls to other ASP_DOTNET component
...
AgentSDK.StopBusinessTransaction(currCtxId);
return View();
}
...
For further reading and usage - https://docs.appdynamics.com/display/PRO45/.NET+Core+for+Linux+SDK+Use+Cases
Step 5: Run "dotnet build" Note: This step should fail with warning-> "AppDynamicsConfig.json : warning APPD001: AppDynamics config was not updated"
Step 6: Edit the AppDynamicsConfig.json file with the following information:
{
"controller": {
"host": "<controller_host_name>",
"port": <controller_port_name>,
"account": "<controller_account_name>",
"password": "<controller_account_key>",
"ssl": <true if using https controller, or false>
},
"application": {
"name": "<application_name>",
"tier": "<tier_name>",
"node": "<node_name>"
},
"log": {
"directory": "<log_folder_path, e.g. /tmp/AppDLogs>",
"level": "<log_level, e.g. INFO>"
}
}
Step 7: Create Dockerfile under MvcApp folder and Add Following -
#FROM microsoft/dotnet:2.0-sdk
#FROM microsoft/aspnetcore-build:2.0
FROM microsoft/dotnet:2.0-sdk
COPY . /app
WORKDIR /app
RUN ["dotnet", "restore"]
RUN ["dotnet", "build"]
#RUN ["apt-get","update"]
#RUN ["apt-get", "install", "lsof"]
ENV CORECLR_PROFILER="{57e1aa68-2229-41aa-9931-a6e93bbc64d8}"
ENV CORECLR_ENABLE_PROFILING=1
ENV CORECLR_PROFILER_PATH="/<user,e.g:root>/.nuget/packages/appdynamics.agentsdk/4.5.0/runtimes/linux-x64/native/libappdprofiler.so"
EXPOSE 5000/tcp
ENV ASPNETCORE_URLS http://*:5000
ENTRYPOINT ["dotnet", "run"]
Note: For CORECLR_PROFILER_PATH refer the last section on https://docs.appdynamics.com/display/PRO45/Using+.NET+Core+for+Linux+SDK
Step 8: Build the Image (make sure cd MvcApp, if not already the current directory)-
docker build -t appdsample:MvcApp .
Step 9: Launch the Image -
docker run -d -p 8088:5000 -t appdsample:MvcApp
Step 10: Apply Load on the application (http://localhost:8088/) and check the reporting in controller and logs under e.g. /tmp/AppDLogs
Doc references -
https://docs.appdynamics.com/display/PRO45/.NET+Core+for+Linux+SDK
https://docs.appdynamics.com/display/PRO45/Using+.NET+Core+for+Linux+SDK
https://docs.appdynamics.com/display/PRO45/.NET+Core+for+Linux+SDK+Use+Cases
Please follow the instructions to setup the sample environment and do let us know if it works in your environment?
Also once verified, please perform needed changes into your original applications setup process and let us know if it works with your application as well or not ?
Thanks,
Kartikay
Thanks, this was very helpfull and I suggest you to update the official documentation with this guide. It is much better than the original one.
I still have an issue: since my application is running in containers, I have multiple instances of it. This means that I can't simply apply a fixed node-name, it needs to vary according to the container instance so it will be properly visible at appDynamics dashboards.
Any suggestions on how to do that?
Thanks,
Gabriel
Gabriel,
I have discovered some of the causes of the issues I have been having and am now able to get the client to see the namespace for my "using" statements. There are some issues with a couple of the config files that the nuget process creates/modifies. It is also interesting to note, that their solutions assume that if you are running code in a linux environment that you are also developing on a linux environment. Their nuget backages are OS dependent. I have been playing with them a bit since I develop in Windows and Deploy to Linux containers. You would think that since they support dotnet core that their packages would also be cross platform, but currently they are not. I think that I might have something that will work for me though I have one last issue I am trying to figure out. AppDynamic's documentation has not been helpful in the least in resolving these issues, so I have been having to hack around to figure things out.
What is your enviornment that you are working in? Are you deploying to Windows containers or Linux containers? I would be more than willing to share my experiences if it helps someone else.
Robert,
I'm developing in a windows environment and my application is running in a linux container. Actually, I achieved the instrumentation following the steps posted in this thread by @Kartikay.Tripathi. I only needed to modify a little bit the dockerfile because my application is installed with a framework-dependent way. Now the only issue that I'm facing is the fact that I need to set up the node-name dinamically according to the container hostname, but I found out that there is some environment variables that are capable of doing that.
This is the dockerfile that I'm using:
FROM microsoft/dotnet:2.0-sdk COPY . . RUN dotnet restore WORKDIR /MyApplication RUN dotnet build -c Release -o /app RUN dotnet publish -c Release -o /app WORKDIR /app EXPOSE 80/tcp ENV ASPNETCORE_URLS http://*:80 ENTRYPOINT ["dotnet", "MyApplication.dll"]
I'm also using docker-compose to deploy my containers so there is my docker-compose.yml file:
version: '2' services: my-application: environment: - CORECLR_PROFILER={57e1aa68-2229-41aa-9931-a6e93bbc64d8} - CORECLR_ENABLE_PROFILING=1 - CORECLR_PROFILER_PATH=/app/runtimes/linux-x64/native/libappdprofiler.so image: my-application build: . ports: - "8086:5000"
You can notice that the CORECLR_PROFILER_PATH is the one generated after the 'dotnet publish' command. I searched for it inside of the container using the 'find' command and this was the path that I found.
Also, I didn't got some problems installing the AppDynamics nuget package directly from nuget.org, using the VS package manager. The name of the package is AppDynamics.AgentSDK v4.5.2.
Finally, those are the environment variables that can be used to treat the node-name point:
APPDYNAMICS_AGENT_NODE_NAME = <name>
APPDYNAMICS_AGENT_REUSE_NODE_NAME = (true | false)
APPDYNAMICS_AGENT_REUSE_NODE_NAME_PREFIX = <prefix>
@Kartikay.Tripathi is there any guide where we can check all of the environment variables that are available to use?
Hope it helps,
Gabriel
Gabriel,
Thanks for the response. I was using v4.5.1. They must have fixed some of the glitches with the v4.5.2 version. I will try playing with that when I get a spare moment. The issue you mentioned about dynamic naming is something I was trying to solve as well. I wrote some code, which may not be the best way to do this, to read in the AppD config file that is generated then get the container host name and a few other values and update the node name then write that data back to the config file. I am running this code in startup and it seems to be running decently well. What I want to be able to do is control those values via environment variables so that I have complete control over what shows up in AppD. If you are interested in what I put together, let me know.
With the v4.5.1 version the issue with the "so" file was that the nuget setup was not automatically adding the file to the project but was adding it to the generic nuget path (something like /root/.nuget/...) and the app was having a hard time finding that path. Even though I put the same path that showed up using the "find" linux command it was not working. I will try what you provided to see if that resolved my issue. I am hopeful.
Thanks,
Kartikay,
I tried to continue on with the instructions skipping step 4 (since it is not working). I am guessing that the instructionsare out of date since they reference the previous version of .net core (2.0 instead of 2.1) as well as the previous version of the sdk API (4.5.0 v 4.5.1). I also had to change a couple of items in the project file because by default it was using the URLs defined in the launchSettings.json file which does a redirect from port 5000 to 5001 and this was causing an issue with the exposed port in Docker (which was set to 5000 per the instructions).
After making all those changes, I was able to get the project to build and run in Docker, though the profiler still does not work. When I comment out the "ENTRYPOINT" command in the docker file and run the image in interactive mode and then build the solution I get the following warning messages from the build.
profiler(Warn): Failed to locate config file from
profiler(Warn): Failed to load configuration, profiler will not attach.
profiler(Warn): Failed to locate config file from
profiler(Warn): Failed to load configuration, profiler will not attach.
I verified that the nuget package existed in the docker image, and after updating the path to 4.5.1 that the path to the libappdprofiler.so file was correct. I also verified that the AppDynamicsConfig.json file with the correct settings was in the root of the project files (/app) and that it gets copied correctly to the build folder (though with a new name of MvcApp.AppDynamicsConfig.json in the /app/bin/Debug/netcoreapp2.1 folder).
I added a copy of the project to a public repo that I own (though I removed our controller connection details).