AWSMetricsBus.h 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. /*
  2. * Copyright (c) Contributors to the Open 3D Engine Project.
  3. * For complete copyright and license terms please see the LICENSE at the root of this distribution.
  4. *
  5. * SPDX-License-Identifier: Apache-2.0 OR MIT
  6. *
  7. */
  8. #pragma once
  9. #include <MetricsAttribute.h>
  10. #include <AzCore/EBus/EBus.h>
  11. namespace AWSMetrics
  12. {
  13. //! AWSMetrics request interface
  14. class AWSMetricsRequests
  15. : public AZ::EBusTraits
  16. {
  17. public:
  18. // Allow multiple threads to concurrently make requests
  19. using MutexType = AZStd::recursive_mutex;
  20. //////////////////////////////////////////////////////////////////////////
  21. // EBusTraits overrides
  22. static const AZ::EBusHandlerPolicy HandlerPolicy = AZ::EBusHandlerPolicy::Single;
  23. static const AZ::EBusAddressPolicy AddressPolicy = AZ::EBusAddressPolicy::Single;
  24. //////////////////////////////////////////////////////////////////////////
  25. //! Submit metrics to the backend or a local file.
  26. //! @param eventName Name of the metrics event.
  27. //! @param metricsAttributes Attributes of the metrics.
  28. //! @param eventPriority Priority of the event. Default to 0 which is considered as the highest priority.
  29. //! @param eventSourceOverride Event source used to override the default value.
  30. //! @param bufferMetrics Whether to buffer metrics and send them in batch.
  31. //! @return Whether the request is sent successfully.
  32. virtual bool SubmitMetrics(const AZStd::vector<MetricsAttribute>& metricsAttributes, int eventPriority = 0,
  33. const AZStd::string& eventSourceOverride = "", bool bufferMetrics = true)
  34. {
  35. AZ_UNUSED(metricsAttributes);
  36. AZ_UNUSED(eventPriority);
  37. AZ_UNUSED(eventSourceOverride);
  38. AZ_UNUSED(bufferMetrics);
  39. return true;
  40. };
  41. //! Flush all metrics buffered in memory.
  42. virtual void FlushMetrics()
  43. {
  44. };
  45. };
  46. using AWSMetricsRequestBus = AZ::EBus<AWSMetricsRequests>;
  47. //! Bus used to send notifications about the result of AWSMetrics requests
  48. class AWSMetricsNotifications
  49. : public AZ::EBusTraits
  50. {
  51. public:
  52. // Allow multiple threads to concurrently send notification
  53. using MutexType = AZStd::recursive_mutex;
  54. //////////////////////////////////////////////////////////////////////////
  55. // EBusTraits overrides
  56. static const AZ::EBusHandlerPolicy HandlerPolicy = AZ::EBusHandlerPolicy::Multiple;
  57. static const AZ::EBusAddressPolicy AddressPolicy = AZ::EBusAddressPolicy::Single;
  58. //////////////////////////////////////////////////////////////////////////
  59. //! Notification for sending metrics successfully.
  60. //! @param requestId Id of the request.
  61. virtual void OnSendMetricsSuccess(int requestId)
  62. {
  63. AZ_UNUSED(requestId);
  64. }
  65. //! Notification for failing to send metrics.
  66. //! @param requestId Id of the request.
  67. virtual void OnSendMetricsFailure(int requestId, const AZStd::string& errorMessage)
  68. {
  69. AZ_UNUSED(requestId);
  70. AZ_UNUSED(errorMessage);
  71. }
  72. };
  73. using AWSMetricsNotificationBus = AZ::EBus<AWSMetricsNotifications>;
  74. } // namespace AWSMetrics