diff --git a/eden/common/telemetry/Stats.h b/eden/common/telemetry/Stats.h new file mode 100644 index 0000000..edcee87 --- /dev/null +++ b/eden/common/telemetry/Stats.h @@ -0,0 +1,18 @@ +/* + * Copyright (c) Meta Platforms, Inc. and affiliates. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + */ + +#pragma once + +#include "eden/common/telemetry/StatsGroup.h" + +namespace facebook::eden { + +struct TelemetryStats : StatsGroup { + Counter subprocessLoggerFailure{"telemetry.subprocess_logger_failure"}; +}; + +} // namespace facebook::eden diff --git a/eden/common/telemetry/StructuredLoggerFactory.h b/eden/common/telemetry/StructuredLoggerFactory.h new file mode 100644 index 0000000..c6a34dd --- /dev/null +++ b/eden/common/telemetry/StructuredLoggerFactory.h @@ -0,0 +1,62 @@ +/* + * Copyright (c) Meta Platforms, Inc. and affiliates. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + */ + +#pragma once + +#include +#include +#include + +#include "eden/common/telemetry/NullStructuredLogger.h" +#include "eden/common/telemetry/ScubaStructuredLogger.h" +#include "eden/common/telemetry/Stats.h" +#include "eden/common/telemetry/SubprocessScribeLogger.h" +#include "eden/common/utils/RefPtr.h" + +namespace facebook::eden { + +class StructuredLogger; +struct SessionInfo; + +/** + * Returns a StructuredLogger appropriate for this platform and + * configuration. + */ +template +std::shared_ptr makeDefaultStructuredLogger( + const std::string& binary, + const std::string& category, + SessionInfo sessionInfo, + StatsPtr stats) { + if (binary.empty()) { + return std::make_shared(); + } + + if (category.empty()) { + XLOGF( + WARN, + "Scribe binary '{}' specified, but no category specified. Structured logging is disabled.", + binary); + return std::make_shared(); + } + + try { + auto logger = + std::make_unique(binary.c_str(), category); + return std::make_shared( + std::move(logger), std::move(sessionInfo)); + } catch (const std::exception& ex) { + stats->increment(&TelemetryStats::subprocessLoggerFailure, 1); + XLOGF( + ERR, + "Failed to create SubprocessScribeLogger: {}. Structured logging is disabled.", + folly::exceptionStr(ex)); + return std::make_shared(); + } +} + +} // namespace facebook::eden