Skip to content

Commit

Permalink
require integrations (#121)
Browse files Browse the repository at this point in the history
* don't attach profiler if no integrations are loaded

* use "Profiler" instead of "CorProfiler" in logs

* always add process name to logs
  • Loading branch information
lucaspimentel authored Sep 12, 2018
1 parent 67e141c commit 529ca08
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions src/Datadog.Trace.ClrProfiler.Native/cor_profiler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,15 @@ CorProfiler::Initialize(IUnknown* cor_profiler_info_unknown) {
is_attached_ = FALSE;

const auto process_name = GetCurrentProcessName();
auto allowed_process_names = GetEnvironmentValues(kProcessesEnvironmentName);
LOG_APPEND(L"Initialize() called for " << process_name);

if (integrations_.empty()) {
LOG_APPEND(L"Profiler disabled: " << kIntegrationsEnvironmentName
<< L" environment variable not set.");
return E_FAIL;
}

const auto allowed_process_names = GetEnvironmentValues(kProcessesEnvironmentName);

if (allowed_process_names.empty()) {
LOG_APPEND(
Expand All @@ -41,7 +49,7 @@ CorProfiler::Initialize(IUnknown* cor_profiler_info_unknown) {

if (std::find(allowed_process_names.begin(), allowed_process_names.end(),
process_name) == allowed_process_names.end()) {
LOG_APPEND(L"CorProfiler disabled: module name \""
LOG_APPEND(L"Profiler disabled: module name \""
<< process_name << "\" does not match "
<< kProcessesEnvironmentName << " environment variable.");
return E_FAIL;
Expand All @@ -51,14 +59,14 @@ CorProfiler::Initialize(IUnknown* cor_profiler_info_unknown) {
HRESULT hr = cor_profiler_info_unknown->QueryInterface<ICorProfilerInfo3>(
&this->info_);
LOG_IFFAILEDRET(hr,
L"CorProfiler disabled: interface ICorProfilerInfo3 or "
L"Profiler disabled: interface ICorProfilerInfo3 or "
L"higher not found.");

hr = this->info_->SetEventMask(kEventMask);
LOG_IFFAILEDRET(hr, L"Failed to attach profiler: unable to set event mask.");

// we're in!
LOG_APPEND(L"CorProfiler attached to process " << process_name);
LOG_APPEND(L"Profiler attached to process " << process_name);
this->info_->AddRef();
is_attached_ = true;
profiler = this;
Expand Down

0 comments on commit 529ca08

Please sign in to comment.