I’ve been following the article to enable Nginx logs enrichment and to include the DT in the Nginx logs however, I have Dynatrace implemented in one environment and it works fine but when I try to run Nginx on my local machine I get the following error:
Is nginx instrumented locally? What version of nginx is being run? Do you have the oneagent installed?
Nginx logs enrichment that can work whether Dynatrace is enabled or not? -- using this method depends on the nginx process being instrumented by the OneAgent
We also have dev and test environments without Dynatrace. My strategy is to run a startup script to detect if Dynatrace is instrumenting the Docker container my nginx server is running in. The script tests if the /etc/ld.so.preload is set to load the dynatrace one agent library. If it is detected then I update the logging config with the Dynatrace specific logging patterns. e.g.
<span># Check if the Dynatrace OneAgent is installed by checking for the presence of</span><br><span># liboneagentproc in the /etc/ld.so.preload file.</span><br><span>if</span> <span>grep</span> <span>-q</span> "<span>liboneagentproc"</span> "<span>/etc/ld.so.preload"</span><span> ; </span><span>then</span> <br><span>echo</span> <span>"Enabling Dynatrace logging instrumentation"<br></span># Update or replace nginx.conf to insert Dynatrace pattern [!dt dt.trace_id=$dt_trace_id]<br># into the logging config here.<br>fi
You can try solving this by defining fallback values for the Dynatrace variables using the map directive in NGINX. This is useful when Dynatrace OneAgent is not installed (e.g., in local environments), and NGINX would otherwise throw an error due to unknown variables like $dt_trace_id.
Hello @radek_jasinski, do you have a working example of this that you can share? I’d like to see where you placed that and in which file, the nginx.conf or another? I also have a need for Nginx log enrichment, but I get the same error as @ahmad did.
I have the agent monitoring the nginx process in full stack, the OneAgent module dt_one_agent shows up in the modules list.