azure-core
tracing.hpp
Go to the documentation of this file.
1 // Copyright (c) Microsoft Corporation. All rights reserved.
2 // SPDX-License-Identifier: MIT
3 
9 #pragma once
10 
11 #include "azure/core/datetime.hpp"
13 #include "azure/core/nullable.hpp"
14 #include "azure/core/url.hpp"
15 #include <array>
16 #include <memory>
17 #include <string>
18 #include <vector>
19 
20 // Forward declare Azure::Core::Http::Request to resolve an include file ordering problem.
21 namespace Azure { namespace Core { namespace Http {
22  class Request;
23 }}} // namespace Azure::Core::Http
24 
25 namespace Azure { namespace Core { namespace Tracing {
26 
27  namespace _internal {
28 
59  class AttributeSet {
60  public:
67  virtual void AddAttribute(std::string const& attributeName, bool value) = 0;
74  virtual void AddAttribute(std::string const& attributeName, int32_t value) = 0;
81  virtual void AddAttribute(std::string const& attributeName, int64_t value) = 0;
88  virtual void AddAttribute(std::string const& attributeName, uint64_t value) = 0;
95  virtual void AddAttribute(std::string const& attributeName, double value) = 0;
102  virtual void AddAttribute(std::string const& attributeName, const char* value) = 0;
109  virtual void AddAttribute(std::string const& attributeName, std::string const& value) = 0;
110 
115  virtual ~AttributeSet() = default;
116  };
117 
120  class SpanKind final : public Azure::Core::_internal::ExtendableEnumeration<SpanKind> {
121  public:
122  explicit SpanKind(std::string const& kind) : ExtendableEnumeration(kind) {}
123  SpanKind() = default;
124 
129  AZ_CORE_DLLEXPORT const static SpanKind Internal;
134  AZ_CORE_DLLEXPORT const static SpanKind Client;
139  AZ_CORE_DLLEXPORT const static SpanKind Server;
144  AZ_CORE_DLLEXPORT const static SpanKind Producer;
149  AZ_CORE_DLLEXPORT const static SpanKind Consumer;
150  };
151 
155  class SpanStatus final : public Azure::Core::_internal::ExtendableEnumeration<SpanStatus> {
156 
157  public:
158  explicit SpanStatus(std::string const& status) : ExtendableEnumeration(status) {}
159  SpanStatus() = default;
160 
164  AZ_CORE_DLLEXPORT const static SpanStatus Unset;
168  AZ_CORE_DLLEXPORT const static SpanStatus Ok;
172  AZ_CORE_DLLEXPORT const static SpanStatus Error;
173  };
174 
178  class Span {
179  public:
183  virtual void End(Azure::Nullable<Azure::DateTime> endTime = {}) = 0;
184 
190  virtual void AddAttributes(AttributeSet const& attributeToAdd) = 0;
191 
198  virtual void AddAttribute(std::string const& attributeName, std::string const& attributeValue)
199  = 0;
200 
210  virtual void AddEvent(std::string const& eventName, AttributeSet const& eventAttributes) = 0;
211 
219  virtual void AddEvent(std::string const& eventName) = 0;
225  virtual void AddEvent(std::exception const& exception) = 0;
226 
233  virtual void SetStatus(SpanStatus const& status, std::string const& description = "") = 0;
234 
241  virtual void PropagateToHttpHeaders(Azure::Core::Http::Request& request) = 0;
242  };
243 
248  struct CreateSpanOptions final
249  {
254  SpanKind Kind{SpanKind::Internal};
259  std::unique_ptr<AttributeSet> Attributes;
260 
264  std::shared_ptr<Span> ParentSpan;
265  };
266 
271  class Tracer {
272  public:
286  virtual std::shared_ptr<Span> CreateSpan(
287  std::string const& spanName,
288  CreateSpanOptions const& options = {}) const = 0;
289 
290  virtual std::unique_ptr<AttributeSet> CreateAttributeSet() const = 0;
291  };
292  } // namespace _internal
293 
298  public:
307  virtual std::shared_ptr<Azure::Core::Tracing::_internal::Tracer> CreateTracer(
308  std::string const& name,
309  std::string const& version = "") const = 0;
310  };
311 }}} // namespace Azure::Core::Tracing
AZ_CORE_DLLEXPORT
#define AZ_CORE_DLLEXPORT
Applies DLL export attribute, when applicable.
Definition: dll_import_export.hpp:93
datetime.hpp
Support for date and time standardized string formats.
Azure::Nullable< Azure::DateTime >
Azure::Core::Http::Request
A request message from a client to a server.
Definition: http.hpp:176
url.hpp
Uniform Resource Locator (URL).
Azure
Azure SDK abstractions.
Definition: azure_assert.hpp:55
extendable_enumeration.hpp
Internal utility functions for extendable enumerations.
nullable.hpp
Manages an optional contained value, i.e. a value that may or may not be present.
Azure::Core::Tracing::TracerProvider::CreateTracer
virtual std::shared_ptr< Azure::Core::Tracing::_internal::Tracer > CreateTracer(std::string const &name, std::string const &version="") const =0
Create a Tracer object.
Azure::Core::Tracing::TracerProvider
Trace Provider - factory for creating Tracer objects.
Definition: tracing.hpp:297
Azure::Core::Http::HttpStatusCode::Ok
@ Ok
HTTP 200 OK.