span_startoptions.h 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. // Copyright The OpenTelemetry Authors
  2. // SPDX-License-Identifier: Apache-2.0
  3. #pragma once
  4. #include "opentelemetry/common/timestamp.h"
  5. #include "opentelemetry/context/context.h"
  6. #include "opentelemetry/nostd/variant.h"
  7. #include "opentelemetry/trace/span_context.h"
  8. #include "opentelemetry/trace/span_metadata.h"
  9. #include "opentelemetry/version.h"
  10. OPENTELEMETRY_BEGIN_NAMESPACE
  11. namespace trace
  12. {
  13. /**
  14. * StartSpanOptions provides options to set properties of a Span at the time of
  15. * its creation
  16. */
  17. struct StartSpanOptions
  18. {
  19. // Optionally sets the start time of a Span.
  20. //
  21. // If the start time of a Span is set, timestamps from both the system clock
  22. // and steady clock must be provided.
  23. //
  24. // Timestamps from the steady clock can be used to most accurately measure a
  25. // Span's duration, while timestamps from the system clock can be used to most
  26. // accurately place a Span's
  27. // time point relative to other Spans collected across a distributed system.
  28. common::SystemTimestamp start_system_time;
  29. common::SteadyTimestamp start_steady_time;
  30. // Explicitly set the parent of a Span.
  31. //
  32. // The `parent` field is designed to establish parent-child relationships
  33. // in tracing spans. It can be set to either a `SpanContext` or a
  34. // `context::Context` object.
  35. //
  36. // - When set to valid `SpanContext`, it directly assigns a specific Span as the parent
  37. // of the newly created Span.
  38. //
  39. // - Alternatively, setting the `parent` field to a `context::Context` allows for
  40. // more nuanced parent identification:
  41. // 1. If the `Context` contains a Span object, this Span is treated as the parent.
  42. // 2. If the `Context` contains the boolean flag `is_root_span` set to `true`,
  43. // it indicates that the new Span should be treated as a root Span, i.e., it
  44. // does not have a parent Span.
  45. // Example Usage:
  46. // ```cpp
  47. // trace_api::StartSpanOptions options;
  48. // opentelemetry::context::Context root;
  49. // root = root.SetValue(kIsRootSpanKey, true);
  50. // options.parent = root;
  51. // auto root_span = tracer->StartSpan("span root", options);
  52. // ```
  53. //
  54. // - If the `parent` field is not set, the newly created Span will inherit the
  55. // parent of the currently active Span (if any) in the current context.
  56. //
  57. nostd::variant<SpanContext, context::Context> parent = SpanContext::GetInvalid();
  58. // TODO:
  59. // SpanContext remote_parent;
  60. // Links
  61. SpanKind kind = SpanKind::kInternal;
  62. };
  63. } // namespace trace
  64. OPENTELEMETRY_END_NAMESPACE