From c8809e65f8c63402fc399a0efbe9bcc2c6448f61 Mon Sep 17 00:00:00 2001 From: Brett McBride Date: Tue, 16 Jan 2024 17:30:30 +1100 Subject: [PATCH 1/2] update proto to 1.1.0 updates generated protobuf files to 1.1.0, and adds trace flags to OTLP-encoded spans and span links --- .../Opentelemetry/Proto/Trace/V1/Trace.php | Bin 2533 -> 2637 bytes .../Proto/Logs/V1/LogRecordFlags.php | 8 +- .../Proto/Logs/V1/ResourceLogs.php | 12 +++ .../Opentelemetry/Proto/Logs/V1/ScopeLogs.php | 12 +++ .../Opentelemetry/Proto/Metrics/V1/Metric.php | 8 +- .../Proto/Metrics/V1/ResourceMetrics.php | 12 +++ .../Proto/Metrics/V1/ScopeMetrics.php | 12 +++ .../Proto/Trace/V1/ResourceSpans.php | 12 +++ .../Proto/Trace/V1/ScopeSpans.php | 12 +++ .../Opentelemetry/Proto/Trace/V1/Span.php | 74 ++++++++++++++++++ .../Proto/Trace/V1/Span/Link.php | 58 ++++++++++++++ .../Proto/Trace/V1/SpanFlags.php | 65 +++++++++++++++ proto/otel/VERSION | 2 +- src/Contrib/Otlp/SpanConverter.php | 2 + tests/Unit/Contrib/Otlp/SpanConverterTest.php | 2 + 15 files changed, 283 insertions(+), 8 deletions(-) create mode 100644 proto/otel/Opentelemetry/Proto/Trace/V1/SpanFlags.php diff --git a/proto/otel/GPBMetadata/Opentelemetry/Proto/Trace/V1/Trace.php b/proto/otel/GPBMetadata/Opentelemetry/Proto/Trace/V1/Trace.php index 35c1ebbf10a8227e0573d937bb405e17c18534ca..b8dda19860435f0a09f73a92ed0be80bfb131541 100644 GIT binary patch delta 148 zcmaDVd{$&bJ`>X<{>_C<0!&OT9Fv<_!ufc)SkrP6(~Bhp6c{zwH{WE5U}9V|*@%5U zzYtuC4J>t$-Iviz%Y%zExF9jl4Wvg%l1nr=z|k+>&BxI_INrrS-p@ZIJ~Y@>fI&!s aOBzWkB*@X(6{^hFG1yz+KjUOM&f@@$M<`YR delta 53 zcmV-50LuT(6y+1JZvq0U4zqCr5CQ_`2a|&YSF`B^R{{Z@lR*ccv+oB@0R}>M3Lj~2 LlMw?Qlc@=$?tl@( diff --git a/proto/otel/Opentelemetry/Proto/Logs/V1/LogRecordFlags.php b/proto/otel/Opentelemetry/Proto/Logs/V1/LogRecordFlags.php index de6f38899..343a6cc7b 100644 --- a/proto/otel/Opentelemetry/Proto/Logs/V1/LogRecordFlags.php +++ b/proto/otel/Opentelemetry/Proto/Logs/V1/LogRecordFlags.php @@ -7,9 +7,11 @@ use UnexpectedValueException; /** - * LogRecordFlags is defined as a protobuf 'uint32' type and is to be used as - * bit-fields. Each non-zero value defined in this enum is a bit-mask. - * To extract the bit-field, for example, use an expression like: + * LogRecordFlags represents constants used to interpret the + * LogRecord.flags field, which is protobuf 'fixed32' type and is to + * be used as bit-fields. Each non-zero value defined in this enum is + * a bit-mask. To extract the bit-field, for example, use an + * expression like: * (logRecord.flags & LOG_RECORD_FLAGS_TRACE_FLAGS_MASK) * * Protobuf type opentelemetry.proto.logs.v1.LogRecordFlags diff --git a/proto/otel/Opentelemetry/Proto/Logs/V1/ResourceLogs.php b/proto/otel/Opentelemetry/Proto/Logs/V1/ResourceLogs.php index 2049339d4..b78f6d86c 100644 --- a/proto/otel/Opentelemetry/Proto/Logs/V1/ResourceLogs.php +++ b/proto/otel/Opentelemetry/Proto/Logs/V1/ResourceLogs.php @@ -29,6 +29,9 @@ class ResourceLogs extends \Google\Protobuf\Internal\Message */ private $scope_logs; /** + * The Schema URL, if known. This is the identifier of the Schema that the resource data + * is recorded in. To learn more about Schema URL see + * https://opentelemetry.io/docs/specs/otel/schemas/#schema-url * This schema_url applies to the data in the "resource" field. It does not apply * to the data in the "scope_logs" field which have their own schema_url field. * @@ -48,6 +51,9 @@ class ResourceLogs extends \Google\Protobuf\Internal\Message * @type \Opentelemetry\Proto\Logs\V1\ScopeLogs[]|\Google\Protobuf\Internal\RepeatedField $scope_logs * A list of ScopeLogs that originate from a resource. * @type string $schema_url + * The Schema URL, if known. This is the identifier of the Schema that the resource data + * is recorded in. To learn more about Schema URL see + * https://opentelemetry.io/docs/specs/otel/schemas/#schema-url * This schema_url applies to the data in the "resource" field. It does not apply * to the data in the "scope_logs" field which have their own schema_url field. * } @@ -122,6 +128,9 @@ public function setScopeLogs($var) } /** + * The Schema URL, if known. This is the identifier of the Schema that the resource data + * is recorded in. To learn more about Schema URL see + * https://opentelemetry.io/docs/specs/otel/schemas/#schema-url * This schema_url applies to the data in the "resource" field. It does not apply * to the data in the "scope_logs" field which have their own schema_url field. * @@ -134,6 +143,9 @@ public function getSchemaUrl() } /** + * The Schema URL, if known. This is the identifier of the Schema that the resource data + * is recorded in. To learn more about Schema URL see + * https://opentelemetry.io/docs/specs/otel/schemas/#schema-url * This schema_url applies to the data in the "resource" field. It does not apply * to the data in the "scope_logs" field which have their own schema_url field. * diff --git a/proto/otel/Opentelemetry/Proto/Logs/V1/ScopeLogs.php b/proto/otel/Opentelemetry/Proto/Logs/V1/ScopeLogs.php index 8c5a94821..38839ee9e 100644 --- a/proto/otel/Opentelemetry/Proto/Logs/V1/ScopeLogs.php +++ b/proto/otel/Opentelemetry/Proto/Logs/V1/ScopeLogs.php @@ -30,6 +30,9 @@ class ScopeLogs extends \Google\Protobuf\Internal\Message */ private $log_records; /** + * The Schema URL, if known. This is the identifier of the Schema that the log data + * is recorded in. To learn more about Schema URL see + * https://opentelemetry.io/docs/specs/otel/schemas/#schema-url * This schema_url applies to all logs in the "logs" field. * * Generated from protobuf field string schema_url = 3; @@ -49,6 +52,9 @@ class ScopeLogs extends \Google\Protobuf\Internal\Message * @type \Opentelemetry\Proto\Logs\V1\LogRecord[]|\Google\Protobuf\Internal\RepeatedField $log_records * A list of log records. * @type string $schema_url + * The Schema URL, if known. This is the identifier of the Schema that the log data + * is recorded in. To learn more about Schema URL see + * https://opentelemetry.io/docs/specs/otel/schemas/#schema-url * This schema_url applies to all logs in the "logs" field. * } */ @@ -124,6 +130,9 @@ public function setLogRecords($var) } /** + * The Schema URL, if known. This is the identifier of the Schema that the log data + * is recorded in. To learn more about Schema URL see + * https://opentelemetry.io/docs/specs/otel/schemas/#schema-url * This schema_url applies to all logs in the "logs" field. * * Generated from protobuf field string schema_url = 3; @@ -135,6 +144,9 @@ public function getSchemaUrl() } /** + * The Schema URL, if known. This is the identifier of the Schema that the log data + * is recorded in. To learn more about Schema URL see + * https://opentelemetry.io/docs/specs/otel/schemas/#schema-url * This schema_url applies to all logs in the "logs" field. * * Generated from protobuf field string schema_url = 3; diff --git a/proto/otel/Opentelemetry/Proto/Metrics/V1/Metric.php b/proto/otel/Opentelemetry/Proto/Metrics/V1/Metric.php index 3d2538314..b15f53d39 100644 --- a/proto/otel/Opentelemetry/Proto/Metrics/V1/Metric.php +++ b/proto/otel/Opentelemetry/Proto/Metrics/V1/Metric.php @@ -86,7 +86,7 @@ class Metric extends \Google\Protobuf\Internal\Message { /** - * name of the metric, including its DNS name prefix. It must be unique. + * name of the metric. * * Generated from protobuf field string name = 1; */ @@ -113,7 +113,7 @@ class Metric extends \Google\Protobuf\Internal\Message * Optional. Data for populating the Message object. * * @type string $name - * name of the metric, including its DNS name prefix. It must be unique. + * name of the metric. * @type string $description * description of the metric, which can be used in documentation. * @type string $unit @@ -132,7 +132,7 @@ public function __construct($data = NULL) { } /** - * name of the metric, including its DNS name prefix. It must be unique. + * name of the metric. * * Generated from protobuf field string name = 1; * @return string @@ -143,7 +143,7 @@ public function getName() } /** - * name of the metric, including its DNS name prefix. It must be unique. + * name of the metric. * * Generated from protobuf field string name = 1; * @param string $var diff --git a/proto/otel/Opentelemetry/Proto/Metrics/V1/ResourceMetrics.php b/proto/otel/Opentelemetry/Proto/Metrics/V1/ResourceMetrics.php index a5e2a7b0d..3cc316594 100644 --- a/proto/otel/Opentelemetry/Proto/Metrics/V1/ResourceMetrics.php +++ b/proto/otel/Opentelemetry/Proto/Metrics/V1/ResourceMetrics.php @@ -29,6 +29,9 @@ class ResourceMetrics extends \Google\Protobuf\Internal\Message */ private $scope_metrics; /** + * The Schema URL, if known. This is the identifier of the Schema that the resource data + * is recorded in. To learn more about Schema URL see + * https://opentelemetry.io/docs/specs/otel/schemas/#schema-url * This schema_url applies to the data in the "resource" field. It does not apply * to the data in the "scope_metrics" field which have their own schema_url field. * @@ -48,6 +51,9 @@ class ResourceMetrics extends \Google\Protobuf\Internal\Message * @type \Opentelemetry\Proto\Metrics\V1\ScopeMetrics[]|\Google\Protobuf\Internal\RepeatedField $scope_metrics * A list of metrics that originate from a resource. * @type string $schema_url + * The Schema URL, if known. This is the identifier of the Schema that the resource data + * is recorded in. To learn more about Schema URL see + * https://opentelemetry.io/docs/specs/otel/schemas/#schema-url * This schema_url applies to the data in the "resource" field. It does not apply * to the data in the "scope_metrics" field which have their own schema_url field. * } @@ -122,6 +128,9 @@ public function setScopeMetrics($var) } /** + * The Schema URL, if known. This is the identifier of the Schema that the resource data + * is recorded in. To learn more about Schema URL see + * https://opentelemetry.io/docs/specs/otel/schemas/#schema-url * This schema_url applies to the data in the "resource" field. It does not apply * to the data in the "scope_metrics" field which have their own schema_url field. * @@ -134,6 +143,9 @@ public function getSchemaUrl() } /** + * The Schema URL, if known. This is the identifier of the Schema that the resource data + * is recorded in. To learn more about Schema URL see + * https://opentelemetry.io/docs/specs/otel/schemas/#schema-url * This schema_url applies to the data in the "resource" field. It does not apply * to the data in the "scope_metrics" field which have their own schema_url field. * diff --git a/proto/otel/Opentelemetry/Proto/Metrics/V1/ScopeMetrics.php b/proto/otel/Opentelemetry/Proto/Metrics/V1/ScopeMetrics.php index 71f5cdb86..0f0632c41 100644 --- a/proto/otel/Opentelemetry/Proto/Metrics/V1/ScopeMetrics.php +++ b/proto/otel/Opentelemetry/Proto/Metrics/V1/ScopeMetrics.php @@ -30,6 +30,9 @@ class ScopeMetrics extends \Google\Protobuf\Internal\Message */ private $metrics; /** + * The Schema URL, if known. This is the identifier of the Schema that the metric data + * is recorded in. To learn more about Schema URL see + * https://opentelemetry.io/docs/specs/otel/schemas/#schema-url * This schema_url applies to all metrics in the "metrics" field. * * Generated from protobuf field string schema_url = 3; @@ -49,6 +52,9 @@ class ScopeMetrics extends \Google\Protobuf\Internal\Message * @type \Opentelemetry\Proto\Metrics\V1\Metric[]|\Google\Protobuf\Internal\RepeatedField $metrics * A list of metrics that originate from an instrumentation library. * @type string $schema_url + * The Schema URL, if known. This is the identifier of the Schema that the metric data + * is recorded in. To learn more about Schema URL see + * https://opentelemetry.io/docs/specs/otel/schemas/#schema-url * This schema_url applies to all metrics in the "metrics" field. * } */ @@ -124,6 +130,9 @@ public function setMetrics($var) } /** + * The Schema URL, if known. This is the identifier of the Schema that the metric data + * is recorded in. To learn more about Schema URL see + * https://opentelemetry.io/docs/specs/otel/schemas/#schema-url * This schema_url applies to all metrics in the "metrics" field. * * Generated from protobuf field string schema_url = 3; @@ -135,6 +144,9 @@ public function getSchemaUrl() } /** + * The Schema URL, if known. This is the identifier of the Schema that the metric data + * is recorded in. To learn more about Schema URL see + * https://opentelemetry.io/docs/specs/otel/schemas/#schema-url * This schema_url applies to all metrics in the "metrics" field. * * Generated from protobuf field string schema_url = 3; diff --git a/proto/otel/Opentelemetry/Proto/Trace/V1/ResourceSpans.php b/proto/otel/Opentelemetry/Proto/Trace/V1/ResourceSpans.php index 521250920..efaa375c2 100644 --- a/proto/otel/Opentelemetry/Proto/Trace/V1/ResourceSpans.php +++ b/proto/otel/Opentelemetry/Proto/Trace/V1/ResourceSpans.php @@ -29,6 +29,9 @@ class ResourceSpans extends \Google\Protobuf\Internal\Message */ private $scope_spans; /** + * The Schema URL, if known. This is the identifier of the Schema that the resource data + * is recorded in. To learn more about Schema URL see + * https://opentelemetry.io/docs/specs/otel/schemas/#schema-url * This schema_url applies to the data in the "resource" field. It does not apply * to the data in the "scope_spans" field which have their own schema_url field. * @@ -48,6 +51,9 @@ class ResourceSpans extends \Google\Protobuf\Internal\Message * @type \Opentelemetry\Proto\Trace\V1\ScopeSpans[]|\Google\Protobuf\Internal\RepeatedField $scope_spans * A list of ScopeSpans that originate from a resource. * @type string $schema_url + * The Schema URL, if known. This is the identifier of the Schema that the resource data + * is recorded in. To learn more about Schema URL see + * https://opentelemetry.io/docs/specs/otel/schemas/#schema-url * This schema_url applies to the data in the "resource" field. It does not apply * to the data in the "scope_spans" field which have their own schema_url field. * } @@ -122,6 +128,9 @@ public function setScopeSpans($var) } /** + * The Schema URL, if known. This is the identifier of the Schema that the resource data + * is recorded in. To learn more about Schema URL see + * https://opentelemetry.io/docs/specs/otel/schemas/#schema-url * This schema_url applies to the data in the "resource" field. It does not apply * to the data in the "scope_spans" field which have their own schema_url field. * @@ -134,6 +143,9 @@ public function getSchemaUrl() } /** + * The Schema URL, if known. This is the identifier of the Schema that the resource data + * is recorded in. To learn more about Schema URL see + * https://opentelemetry.io/docs/specs/otel/schemas/#schema-url * This schema_url applies to the data in the "resource" field. It does not apply * to the data in the "scope_spans" field which have their own schema_url field. * diff --git a/proto/otel/Opentelemetry/Proto/Trace/V1/ScopeSpans.php b/proto/otel/Opentelemetry/Proto/Trace/V1/ScopeSpans.php index 098376f7d..0565539e2 100644 --- a/proto/otel/Opentelemetry/Proto/Trace/V1/ScopeSpans.php +++ b/proto/otel/Opentelemetry/Proto/Trace/V1/ScopeSpans.php @@ -30,6 +30,9 @@ class ScopeSpans extends \Google\Protobuf\Internal\Message */ private $spans; /** + * The Schema URL, if known. This is the identifier of the Schema that the span data + * is recorded in. To learn more about Schema URL see + * https://opentelemetry.io/docs/specs/otel/schemas/#schema-url * This schema_url applies to all spans and span events in the "spans" field. * * Generated from protobuf field string schema_url = 3; @@ -49,6 +52,9 @@ class ScopeSpans extends \Google\Protobuf\Internal\Message * @type \Opentelemetry\Proto\Trace\V1\Span[]|\Google\Protobuf\Internal\RepeatedField $spans * A list of Spans that originate from an instrumentation scope. * @type string $schema_url + * The Schema URL, if known. This is the identifier of the Schema that the span data + * is recorded in. To learn more about Schema URL see + * https://opentelemetry.io/docs/specs/otel/schemas/#schema-url * This schema_url applies to all spans and span events in the "spans" field. * } */ @@ -124,6 +130,9 @@ public function setSpans($var) } /** + * The Schema URL, if known. This is the identifier of the Schema that the span data + * is recorded in. To learn more about Schema URL see + * https://opentelemetry.io/docs/specs/otel/schemas/#schema-url * This schema_url applies to all spans and span events in the "spans" field. * * Generated from protobuf field string schema_url = 3; @@ -135,6 +144,9 @@ public function getSchemaUrl() } /** + * The Schema URL, if known. This is the identifier of the Schema that the span data + * is recorded in. To learn more about Schema URL see + * https://opentelemetry.io/docs/specs/otel/schemas/#schema-url * This schema_url applies to all spans and span events in the "spans" field. * * Generated from protobuf field string schema_url = 3; diff --git a/proto/otel/Opentelemetry/Proto/Trace/V1/Span.php b/proto/otel/Opentelemetry/Proto/Trace/V1/Span.php index 4b1dc138c..c5ac91009 100644 --- a/proto/otel/Opentelemetry/Proto/Trace/V1/Span.php +++ b/proto/otel/Opentelemetry/Proto/Trace/V1/Span.php @@ -51,6 +51,22 @@ class Span extends \Google\Protobuf\Internal\Message * Generated from protobuf field bytes parent_span_id = 4; */ protected $parent_span_id = ''; + /** + * Flags, a bit field. 8 least significant bits are the trace + * flags as defined in W3C Trace Context specification. Readers + * MUST not assume that 24 most significant bits will be zero. + * To read the 8-bit W3C trace flag, use `flags & SPAN_FLAGS_TRACE_FLAGS_MASK`. + * When creating span messages, if the message is logically forwarded from another source + * with an equivalent flags fields (i.e., usually another OTLP span message), the field SHOULD + * be copied as-is. If creating from a source that does not have an equivalent flags field + * (such as a runtime representation of an OpenTelemetry span), the high 24 bits MUST + * be set to zero. + * [Optional]. + * See https://www.w3.org/TR/trace-context-2/#trace-flags for the flag definitions. + * + * Generated from protobuf field fixed32 flags = 16; + */ + protected $flags = 0; /** * A description of the span's operation. * For example, the name can be a qualified method name or a file name @@ -175,6 +191,18 @@ class Span extends \Google\Protobuf\Internal\Message * @type string $parent_span_id * The `span_id` of this span's parent span. If this is a root span, then this * field must be empty. The ID is an 8-byte array. + * @type int $flags + * Flags, a bit field. 8 least significant bits are the trace + * flags as defined in W3C Trace Context specification. Readers + * MUST not assume that 24 most significant bits will be zero. + * To read the 8-bit W3C trace flag, use `flags & SPAN_FLAGS_TRACE_FLAGS_MASK`. + * When creating span messages, if the message is logically forwarded from another source + * with an equivalent flags fields (i.e., usually another OTLP span message), the field SHOULD + * be copied as-is. If creating from a source that does not have an equivalent flags field + * (such as a runtime representation of an OpenTelemetry span), the high 24 bits MUST + * be set to zero. + * [Optional]. + * See https://www.w3.org/TR/trace-context-2/#trace-flags for the flag definitions. * @type string $name * A description of the span's operation. * For example, the name can be a qualified method name or a file name @@ -362,6 +390,52 @@ public function setParentSpanId($var) return $this; } + /** + * Flags, a bit field. 8 least significant bits are the trace + * flags as defined in W3C Trace Context specification. Readers + * MUST not assume that 24 most significant bits will be zero. + * To read the 8-bit W3C trace flag, use `flags & SPAN_FLAGS_TRACE_FLAGS_MASK`. + * When creating span messages, if the message is logically forwarded from another source + * with an equivalent flags fields (i.e., usually another OTLP span message), the field SHOULD + * be copied as-is. If creating from a source that does not have an equivalent flags field + * (such as a runtime representation of an OpenTelemetry span), the high 24 bits MUST + * be set to zero. + * [Optional]. + * See https://www.w3.org/TR/trace-context-2/#trace-flags for the flag definitions. + * + * Generated from protobuf field fixed32 flags = 16; + * @return int + */ + public function getFlags() + { + return $this->flags; + } + + /** + * Flags, a bit field. 8 least significant bits are the trace + * flags as defined in W3C Trace Context specification. Readers + * MUST not assume that 24 most significant bits will be zero. + * To read the 8-bit W3C trace flag, use `flags & SPAN_FLAGS_TRACE_FLAGS_MASK`. + * When creating span messages, if the message is logically forwarded from another source + * with an equivalent flags fields (i.e., usually another OTLP span message), the field SHOULD + * be copied as-is. If creating from a source that does not have an equivalent flags field + * (such as a runtime representation of an OpenTelemetry span), the high 24 bits MUST + * be set to zero. + * [Optional]. + * See https://www.w3.org/TR/trace-context-2/#trace-flags for the flag definitions. + * + * Generated from protobuf field fixed32 flags = 16; + * @param int $var + * @return $this + */ + public function setFlags($var) + { + GPBUtil::checkUint32($var); + $this->flags = $var; + + return $this; + } + /** * A description of the span's operation. * For example, the name can be a qualified method name or a file name diff --git a/proto/otel/Opentelemetry/Proto/Trace/V1/Span/Link.php b/proto/otel/Opentelemetry/Proto/Trace/V1/Span/Link.php index 3096739de..0199570f4 100644 --- a/proto/otel/Opentelemetry/Proto/Trace/V1/Span/Link.php +++ b/proto/otel/Opentelemetry/Proto/Trace/V1/Span/Link.php @@ -52,6 +52,18 @@ class Link extends \Google\Protobuf\Internal\Message * Generated from protobuf field uint32 dropped_attributes_count = 5; */ protected $dropped_attributes_count = 0; + /** + * Flags, a bit field. 8 least significant bits are the trace + * flags as defined in W3C Trace Context specification. Readers + * MUST not assume that 24 most significant bits will be zero. + * When creating new spans, the most-significant 24-bits MUST be + * zero. To read the 8-bit W3C trace flag (use flags & + * SPAN_FLAGS_TRACE_FLAGS_MASK). [Optional]. + * See https://www.w3.org/TR/trace-context-2/#trace-flags for the flag definitions. + * + * Generated from protobuf field fixed32 flags = 6; + */ + protected $flags = 0; /** * Constructor. @@ -73,6 +85,14 @@ class Link extends \Google\Protobuf\Internal\Message * @type int $dropped_attributes_count * dropped_attributes_count is the number of dropped attributes. If the value is 0, * then no attributes were dropped. + * @type int $flags + * Flags, a bit field. 8 least significant bits are the trace + * flags as defined in W3C Trace Context specification. Readers + * MUST not assume that 24 most significant bits will be zero. + * When creating new spans, the most-significant 24-bits MUST be + * zero. To read the 8-bit W3C trace flag (use flags & + * SPAN_FLAGS_TRACE_FLAGS_MASK). [Optional]. + * See https://www.w3.org/TR/trace-context-2/#trace-flags for the flag definitions. * } */ public function __construct($data = NULL) { @@ -218,6 +238,44 @@ public function setDroppedAttributesCount($var) return $this; } + /** + * Flags, a bit field. 8 least significant bits are the trace + * flags as defined in W3C Trace Context specification. Readers + * MUST not assume that 24 most significant bits will be zero. + * When creating new spans, the most-significant 24-bits MUST be + * zero. To read the 8-bit W3C trace flag (use flags & + * SPAN_FLAGS_TRACE_FLAGS_MASK). [Optional]. + * See https://www.w3.org/TR/trace-context-2/#trace-flags for the flag definitions. + * + * Generated from protobuf field fixed32 flags = 6; + * @return int + */ + public function getFlags() + { + return $this->flags; + } + + /** + * Flags, a bit field. 8 least significant bits are the trace + * flags as defined in W3C Trace Context specification. Readers + * MUST not assume that 24 most significant bits will be zero. + * When creating new spans, the most-significant 24-bits MUST be + * zero. To read the 8-bit W3C trace flag (use flags & + * SPAN_FLAGS_TRACE_FLAGS_MASK). [Optional]. + * See https://www.w3.org/TR/trace-context-2/#trace-flags for the flag definitions. + * + * Generated from protobuf field fixed32 flags = 6; + * @param int $var + * @return $this + */ + public function setFlags($var) + { + GPBUtil::checkUint32($var); + $this->flags = $var; + + return $this; + } + } // Adding a class alias for backwards compatibility with the previous class name. diff --git a/proto/otel/Opentelemetry/Proto/Trace/V1/SpanFlags.php b/proto/otel/Opentelemetry/Proto/Trace/V1/SpanFlags.php new file mode 100644 index 000000000..7a29e3504 --- /dev/null +++ b/proto/otel/Opentelemetry/Proto/Trace/V1/SpanFlags.php @@ -0,0 +1,65 @@ +opentelemetry.proto.trace.v1.SpanFlags + */ +class SpanFlags +{ + /** + * The zero value for the enum. Should not be used for comparisons. + * Instead use bitwise "and" with the appropriate mask as shown above. + * + * Generated from protobuf enum SPAN_FLAGS_DO_NOT_USE = 0; + */ + const SPAN_FLAGS_DO_NOT_USE = 0; + /** + * Bits 0-7 are used for trace flags. + * + * Generated from protobuf enum SPAN_FLAGS_TRACE_FLAGS_MASK = 255; + */ + const SPAN_FLAGS_TRACE_FLAGS_MASK = 255; + + private static $valueToName = [ + self::SPAN_FLAGS_DO_NOT_USE => 'SPAN_FLAGS_DO_NOT_USE', + self::SPAN_FLAGS_TRACE_FLAGS_MASK => 'SPAN_FLAGS_TRACE_FLAGS_MASK', + ]; + + public static function name($value) + { + if (!isset(self::$valueToName[$value])) { + throw new UnexpectedValueException(sprintf( + 'Enum %s has no name defined for value %s', __CLASS__, $value)); + } + return self::$valueToName[$value]; + } + + + public static function value($name) + { + $const = __CLASS__ . '::' . strtoupper($name); + if (!defined($const)) { + throw new UnexpectedValueException(sprintf( + 'Enum %s has no value defined for name %s', __CLASS__, $name)); + } + return constant($const); + } +} + diff --git a/proto/otel/VERSION b/proto/otel/VERSION index 0ec25f750..795460fce 100644 --- a/proto/otel/VERSION +++ b/proto/otel/VERSION @@ -1 +1 @@ -v1.0.0 +v1.1.0 diff --git a/src/Contrib/Otlp/SpanConverter.php b/src/Contrib/Otlp/SpanConverter.php index 1a8b4369e..dd3c8c21f 100644 --- a/src/Contrib/Otlp/SpanConverter.php +++ b/src/Contrib/Otlp/SpanConverter.php @@ -148,6 +148,7 @@ private function convertSpan(SpanDataInterface $span): Span $pSpan = new Span(); $pSpan->setTraceId($this->serializer->serializeTraceId($span->getContext()->getTraceIdBinary())); $pSpan->setSpanId($this->serializer->serializeSpanId($span->getContext()->getSpanIdBinary())); + $pSpan->setFlags($span->getContext()->getTraceFlags()); $pSpan->setTraceState((string) $span->getContext()->getTraceState()); if ($span->getParentContext()->isValid()) { $pSpan->setParentSpanId($this->serializer->serializeSpanId($span->getParentContext()->getSpanIdBinary())); @@ -172,6 +173,7 @@ private function convertSpan(SpanDataInterface $span): Span $pSpan->getLinks()[] = $pLink = new Link(); $pLink->setTraceId($this->serializer->serializeTraceId($link->getSpanContext()->getTraceIdBinary())); $pLink->setSpanId($this->serializer->serializeSpanId($link->getSpanContext()->getSpanIdBinary())); + $pLink->setFlags($span->getContext()->getTraceFlags()); $pLink->setTraceState((string) $link->getSpanContext()->getTraceState()); $this->setAttributes($pLink, $link->getAttributes()); } diff --git a/tests/Unit/Contrib/Otlp/SpanConverterTest.php b/tests/Unit/Contrib/Otlp/SpanConverterTest.php index 51fae64d1..d3f46bea2 100644 --- a/tests/Unit/Contrib/Otlp/SpanConverterTest.php +++ b/tests/Unit/Contrib/Otlp/SpanConverterTest.php @@ -46,6 +46,7 @@ public function test_convert_span_to_payload(): void $this->assertSame($span->getContext()->getSpanId(), bin2hex($row->getSpanId())); $this->assertSame($span->getContext()->getTraceId(), bin2hex($row->getTraceId())); + $this->assertSame($span->getContext()->getTraceFlags(), $row->getFlags()); $this->assertSame($span->getName(), $row->getName()); $this->assertCount(2, $row->getAttributes()); @@ -56,6 +57,7 @@ public function test_convert_span_to_payload(): void $this->assertSame($context->getTraceId(), bin2hex($link->getTraceId())); $this->assertSame($context->getSpanId(), bin2hex($link->getSpanId())); + $this->assertSame($context->getTraceFlags(), $link->getFlags()); $this->assertCount(1, $link->getAttributes()); } From 4be571c23e81dcd67d92b334f0d3cb833c1f8abe Mon Sep 17 00:00:00 2001 From: Brett McBride Date: Wed, 17 Jan 2024 08:30:47 +1100 Subject: [PATCH 2/2] adding trace flags to friendly span exporter --- src/SDK/Trace/SpanExporter/FriendlySpanConverter.php | 2 ++ .../Unit/SDK/Trace/SpanExporter/FriendlySpanConverterTest.php | 3 +++ 2 files changed, 5 insertions(+) diff --git a/src/SDK/Trace/SpanExporter/FriendlySpanConverter.php b/src/SDK/Trace/SpanExporter/FriendlySpanConverter.php index 1f8178e10..f18893298 100644 --- a/src/SDK/Trace/SpanExporter/FriendlySpanConverter.php +++ b/src/SDK/Trace/SpanExporter/FriendlySpanConverter.php @@ -22,6 +22,7 @@ class FriendlySpanConverter implements SpanConverterInterface private const TRACE_ID_ATTR = 'trace_id'; private const SPAN_ID_ATTR = 'span_id'; private const TRACE_STATE_ATTR = 'trace_state'; + private const TRACE_FLAGS_ATTR = 'trace_flags'; private const RESOURCE_ATTR = 'resource'; private const PARENT_SPAN_ATTR = 'parent_span_id'; private const KIND_ATTR = 'kind'; @@ -78,6 +79,7 @@ private function convertContext(SpanContextInterface $context): array self::TRACE_ID_ATTR => $context->getTraceId(), self::SPAN_ID_ATTR => $context->getSpanId(), self::TRACE_STATE_ATTR => (string) $context->getTraceState(), + self::TRACE_FLAGS_ATTR => $context->getTraceFlags(), ]; } diff --git a/tests/Unit/SDK/Trace/SpanExporter/FriendlySpanConverterTest.php b/tests/Unit/SDK/Trace/SpanExporter/FriendlySpanConverterTest.php index 33cc9db5f..0e81c3219 100644 --- a/tests/Unit/SDK/Trace/SpanExporter/FriendlySpanConverterTest.php +++ b/tests/Unit/SDK/Trace/SpanExporter/FriendlySpanConverterTest.php @@ -31,6 +31,7 @@ class FriendlySpanConverterTest extends TestCase 'trace_id' => '00000000000000000000000000000000', 'span_id' => '0000000000000000', 'trace_state' => 'foz=baz,foo=bar', + 'trace_flags' => 0, ], 'resource' => [ 'telemetry.sdk.name' => 'opentelemetry', @@ -62,6 +63,7 @@ class FriendlySpanConverterTest extends TestCase 'trace_id' => '20000000000000000000000000000000', 'span_id' => '2000000000000000', 'trace_state' => 'foo=baz,foz=bar', + 'trace_flags' => 0, ], 'attributes' => [ 'foo' => 'bar', @@ -70,6 +72,7 @@ class FriendlySpanConverterTest extends TestCase 'trace_id' => '20000000000000000000000000000000', 'span_id' => '3000000000000000', 'trace_state' => 'baz=foz,bar=foo', + 'trace_flags' => 0, ], 'attributes' => [ 'foz' => 'baz',