33
44#include " opentelemetry/resource_detectors/process_detector.h"
55#include " opentelemetry/nostd/variant.h"
6- #include " opentelemetry/resource_detectors/process_detector_utils.h"
6+ #include " opentelemetry/resource_detectors/detail/process_detector_utils.h"
7+ #include " opentelemetry/sdk/common/global_log_handler.h"
78#include " opentelemetry/sdk/resource/resource.h"
89#include " opentelemetry/sdk/resource/resource_detector.h"
910#include " opentelemetry/semconv/incubating/process_attributes.h"
1011#include " opentelemetry/version.h"
1112
1213#include < stdint.h>
14+ #include < exception>
1315#include < string>
1416#include < unordered_map>
1517#include < utility>
@@ -31,16 +33,32 @@ opentelemetry::sdk::resource::Resource ProcessResourceDetector::Detect() noexcep
3133 opentelemetry::sdk::resource::ResourceAttributes attributes;
3234 attributes[semconv::process::kProcessPid ] = pid;
3335
34- std::string executable_path = opentelemetry::resource_detector::detail::GetExecutablePath (pid);
35- if (!executable_path.empty ())
36+ try
3637 {
37- attributes[semconv::process::kProcessExecutablePath ] = std::move (executable_path);
38+ std::string executable_path = opentelemetry::resource_detector::detail::GetExecutablePath (pid);
39+ if (!executable_path.empty ())
40+ {
41+ attributes[semconv::process::kProcessExecutablePath ] = std::move (executable_path);
42+ }
43+ }
44+ catch (const ::std::exception &ex)
45+ {
46+ OTEL_INTERNAL_LOG_ERROR (" [Process Resource Detector] "
47+ << " Error extracting the executable path: " << ex.what ());
3848 }
3949
40- std::string command = opentelemetry::resource_detector::detail::GetCommand (pid);
41- if (!command.empty ())
50+ try
51+ {
52+ std::string command = opentelemetry::resource_detector::detail::GetCommand (pid);
53+ if (!command.empty ())
54+ {
55+ attributes[semconv::process::kProcessCommand ] = std::move (command);
56+ }
57+ }
58+ catch (const std::exception &ex)
4259 {
43- attributes[semconv::process::kProcessCommand ] = std::move (command);
60+ OTEL_INTERNAL_LOG_ERROR (" [Process Resource Detector] " << " Error extracting command: "
61+ << ex.what ());
4462 }
4563
4664 return ResourceDetector::Create (attributes);
0 commit comments