MetricsEventBuilder.h 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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 <MetricsEvent.h>
  11. #include <AzCore/std/smart_ptr/unique_ptr.h>
  12. #include <AzCore/std/containers/vector.h>
  13. namespace AWSMetrics
  14. {
  15. //! MetricsEventBuilder builds a new metrics event and adds metrics attributes to it.
  16. class MetricsEventBuilder
  17. {
  18. public:
  19. MetricsEventBuilder();
  20. virtual ~MetricsEventBuilder() = default;
  21. //! Add default attributes to the metrics event including event_id, source and timestamp.
  22. //! @param clientId Unique identifier for the client.
  23. //! @param metricSourceOverride Event source used to override the default value.
  24. //! @return The builder itself.
  25. virtual MetricsEventBuilder& AddDefaultMetricsAttributes(const AZStd::string& clientId, const AZStd::string& metricSourceOverride = "");
  26. //! Add attributes to the metrics event.
  27. //! @param attributes List of attributes to add to the metrics event.
  28. //! @return The builder itself.
  29. virtual MetricsEventBuilder& AddMetricsAttributes(const AZStd::vector<MetricsAttribute>& attributes);
  30. //! Set the priority of the metrics event.
  31. //! @param priority Priority of the metrics event.
  32. //! @return The builder itself.
  33. MetricsEventBuilder& SetMetricsPriority(int priority);
  34. //! Build a metrics event.
  35. //! Make sure that this function is only called once for each builder instance. Otherwise it will a new metrics event.
  36. //! @return Metrics event constructed by the builder.
  37. MetricsEvent Build();
  38. private:
  39. //! Add the client Id attribute to the metrics event.
  40. //! @param clientId Unique identifier for the client.
  41. void AddClientIdAttribute(const AZStd::string& clientId);
  42. //! Add the event Id attribute (an UUID) to the metrics event.
  43. void AddEventIdAttribute();
  44. //! Add the event source attribute to the metrics event.
  45. //! Default to be AWSMetricsGem.
  46. //! @param metricSourceOverride Event source used to override the default value.
  47. void AddSourceAttribute(const AZStd::string& metricSourceOverride = "");
  48. //! Add the event timestamp attribute in the UTC ISO8601 format to the metrics event.
  49. void AddTimestampAttribute();
  50. MetricsEvent m_currentMetricsEvent; //!< Metrics event constructed by the builder.
  51. };
  52. } // namespace AWSMetrics