origin_attributes.h 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. #pragma once
  2. #include <library/cpp/yt/global/access.h>
  3. #include <library/cpp/yt/memory/ref.h>
  4. #include <library/cpp/yt/misc/guid.h>
  5. #include <library/cpp/yt/misc/thread_name.h>
  6. #include <library/cpp/yt/threading/public.h>
  7. #include <util/datetime/base.h>
  8. #include <util/system/getpid.h>
  9. namespace NYT {
  10. ////////////////////////////////////////////////////////////////////////////////
  11. //! When this guard is set, newly created errors do not have non-deterministic
  12. //! system attributes and have "datetime" and "host" attributes overridden with a given values.
  13. class TErrorSanitizerGuard
  14. : public TNonCopyable
  15. {
  16. public:
  17. TErrorSanitizerGuard(TInstant datetimeOverride, TSharedRef localHostNameOverride);
  18. ~TErrorSanitizerGuard();
  19. private:
  20. const bool SavedEnabled_;
  21. const TInstant SavedDatetimeOverride_;
  22. const TSharedRef SavedLocalHostNameOverride_;
  23. };
  24. bool IsErrorSanitizerEnabled() noexcept;
  25. ////////////////////////////////////////////////////////////////////////////////
  26. struct TOriginAttributes
  27. {
  28. static constexpr size_t ExtensionDataByteSizeCap = 64;
  29. using TErasedExtensionData = TErasedStorage<ExtensionDataByteSizeCap>;
  30. TProcessId Pid;
  31. NThreading::TThreadId Tid;
  32. TThreadName ThreadName;
  33. TInstant Datetime;
  34. TSharedRef HostHolder;
  35. mutable TStringBuf Host;
  36. // Opaque storage for data from yt/yt/core.
  37. // Currently may contain FiberId, TraceId, SpandId.
  38. std::optional<TErasedExtensionData> ExtensionData;
  39. bool operator==(const TOriginAttributes& other) const noexcept;
  40. void Capture();
  41. };
  42. ////////////////////////////////////////////////////////////////////////////////
  43. namespace NDetail {
  44. inline constexpr NGlobal::TVariableTag GetExtensionDataTag = {};
  45. inline constexpr NGlobal::TVariableTag FormatOriginTag = {};
  46. inline constexpr NGlobal::TVariableTag ExtractFromDictionaryTag = {};
  47. ////////////////////////////////////////////////////////////////////////////////
  48. // These are "weak" symbols.
  49. // NB(arkady-e1ppa): ExtractFromDictionary symbol is left in yt/yt/core/misc/origin_attributes
  50. // because it depends on ytree for now.
  51. std::optional<TOriginAttributes::TErasedExtensionData> GetExtensionData();
  52. TString FormatOrigin(const TOriginAttributes& attributes);
  53. } // namespace NDetail
  54. ////////////////////////////////////////////////////////////////////////////////
  55. } // namespace NYT