Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Exclude default processes and services #2431

Merged
merged 1 commit into from
Sep 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions docs/setup-auto-instrumentation.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -392,12 +392,26 @@ For example, `dotnet.exe;powershell.exe`. Can be used in scenarios where profile
environment variables have a global scope that would end up auto-instrumenting
applications that should not be.

The following processes are _*always*_ excluded from profiling by default.

* powershell.exe
* ServerManager.exe
* ReportingServicesService.exe
* RSHostingService.exe
* RSMananagement.exe
* RSPortal.exe
* RSConfigTool.exe

`ELASTIC_APM_PROFILER_EXCLUDE_SERVICE_NAMES` _(optional)_::

A semi-colon separated list of APM service names to exclude from auto-instrumentation.
Values defined are checked against the value of <<config-service-name,`ELASTIC_APM_SERVICE_NAME`>>
environment variable.

The following service names are _*always*_ excluded from profiling by default.

* SQLServerReportingServices

`ELASTIC_OTEL_LOG_LEVEL` _(optional)_::

The log level at which the profiler should log. Valid values are
Expand Down
26 changes: 24 additions & 2 deletions src/profiler/elastic_apm_profiler/src/profiler/env.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,22 @@ const ELASTIC_APM_LOG_DIRECTORY_ENV_VAR: &str = "ELASTIC_APM_LOG_DIRECTORY";

const ELASTIC_APM_SERVICE_NAME_ENV_VAR: &str = "ELASTIC_APM_SERVICE_NAME";

// These are opinionated defaults for processes that should be excluded from profiling.
const DEFAULT_EXCLUDED_PROCESSES: &[&str] = &[
"powershell.exe",
"ServerManager.exe",
"ReportingServicesService.exe",
"RSHostingService.exe",
"RSMananagement.exe",
"RSPortal.exe",
"RSConfigTool.exe"
];

// These are opinionated defaults for services that should be excluded from profiling.
const DEFAULT_EXCLUDED_SERVICE_NAMES: &[&str] = &[
"SQLServerReportingServices" // We have reports that this "breaks" when running in IIS with global profiling enabled
];

pub static ELASTIC_APM_PROFILER_LOG_IL: Lazy<bool> =
Lazy::new(|| read_bool_env_var(ELASTIC_APM_PROFILER_LOG_IL_ENV_VAR, false));

Expand Down Expand Up @@ -134,11 +150,17 @@ fn read_semicolon_separated_env_var(key: &str) -> Option<Vec<String>> {
}

pub fn get_exclude_processes() -> Option<Vec<String>> {
read_semicolon_separated_env_var(ELASTIC_APM_PROFILER_EXCLUDE_PROCESSES_ENV_VAR)
let mut processes = read_semicolon_separated_env_var(ELASTIC_APM_PROFILER_EXCLUDE_PROCESSES_ENV_VAR)
.unwrap_or_else(Vec::new);
processes.extend(DEFAULT_EXCLUDED_PROCESSES.iter().map(|s| s.to_string()));
Some(processes)
}

pub fn get_exclude_service_names() -> Option<Vec<String>> {
read_semicolon_separated_env_var(ELASTIC_APM_PROFILER_EXCLUDE_SERVICE_NAMES_ENV_VAR)
let mut services = read_semicolon_separated_env_var(ELASTIC_APM_PROFILER_EXCLUDE_SERVICE_NAMES_ENV_VAR)
.unwrap_or_else(Vec::new);
services.extend(DEFAULT_EXCLUDED_SERVICE_NAMES.iter().map(|s| s.to_string()));
Some(services)
}

pub fn get_service_name() -> Option<String> {
Expand Down
4 changes: 2 additions & 2 deletions src/profiler/elastic_apm_profiler/src/profiler/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -522,7 +522,7 @@ impl Profiler {

if let Some(exclude_process_names) = env::get_exclude_processes() {
for exclude_process_name in exclude_process_names {
if process_file_name == exclude_process_name {
if process_file_name.to_lowercase() == exclude_process_name.to_lowercase() {
log::info!(
"Initialize: process name {} matches excluded name {}. Profiler disabled",
&process_file_name,
Expand All @@ -536,7 +536,7 @@ impl Profiler {
if let Some(exclude_service_names) = env::get_exclude_service_names() {
if let Some(service_name) = env::get_service_name() {
for exclude_service_name in exclude_service_names {
if service_name == exclude_service_name {
if service_name.to_lowercase() == exclude_service_name.to_lowercase() {
log::info!(
"Initialize: service name {} matches excluded name {}. Profiler disabled",
&service_name,
Expand Down
Loading