From 80114317f8ab0b982d0c3ca64aefcfb866e0f2bb Mon Sep 17 00:00:00 2001 From: Tobias Bachert Date: Tue, 30 Apr 2024 20:28:30 +0200 Subject: [PATCH] Set OTLP 1.2.0 span parent/link remote flags (#1298) * Generate protobuf 1.3.0 * Set otlp exporter proto 1.2.0 remote flags --- .../Proto/Metrics/V1/Metrics.php | Bin 4526 -> 4586 bytes .../Opentelemetry/Proto/Trace/V1/Trace.php | Bin 2637 -> 2722 bytes .../Opentelemetry/Proto/Metrics/V1/Metric.php | 58 +++++++++++++++ .../Opentelemetry/Proto/Trace/V1/Span.php | 68 +++++++++++------- .../Proto/Trace/V1/Span/Link.php | 68 +++++++++++------- .../Proto/Trace/V1/SpanFlags.php | 14 ++++ proto/otel/VERSION | 2 +- src/Contrib/Otlp/SpanConverter.php | 17 ++++- src/Contrib/composer.json | 2 +- tests/Unit/Contrib/Otlp/SpanConverterTest.php | 21 +++++- tests/Unit/Contrib/Otlp/SpanExporterTest.php | 2 + 11 files changed, 198 insertions(+), 54 deletions(-) diff --git a/proto/otel/GPBMetadata/Opentelemetry/Proto/Metrics/V1/Metrics.php b/proto/otel/GPBMetadata/Opentelemetry/Proto/Metrics/V1/Metrics.php index cbb09509a4ae1996c19a6098dd0ea09b6caf6af3..8fe61287a368e15d1c2dd6b5a4ec73ea1cff961d 100644 GIT binary patch delta 46 zcmZ3d{7QL4ITO=jxy_YKx=f5`H!o+YV&oID8$ne4!&w^@;`mm2_Q Ciw+zB delta 27 jcmaE*yiR#TITOrvPg78J`>~f%>_(n*_h@qPPXIph!WD`QVkAp^ow`%adZ!kclP%Sag7Lx_izl3 u_Y95?a`p8OagFzN4E7diU=mW}QpBPbT^);4IhTB9{$xRB*~u$8mjD2l+as|6 delta 24 gcmZ1^dRAmZJ`>}l%>_(n*%&=0+jDwMzRh_Y0B(y2?*IS* diff --git a/proto/otel/Opentelemetry/Proto/Metrics/V1/Metric.php b/proto/otel/Opentelemetry/Proto/Metrics/V1/Metric.php index b15f53d39..e6d51588f 100644 --- a/proto/otel/Opentelemetry/Proto/Metrics/V1/Metric.php +++ b/proto/otel/Opentelemetry/Proto/Metrics/V1/Metric.php @@ -104,6 +104,18 @@ class Metric extends \Google\Protobuf\Internal\Message * Generated from protobuf field string unit = 3; */ protected $unit = ''; + /** + * Additional metadata attributes that describe the metric. [Optional]. + * Attributes are non-identifying. + * Consumers SHOULD NOT need to be aware of these attributes. + * These attributes MAY be used to encode information allowing + * for lossless roundtrip translation to / from another data model. + * Attribute keys MUST be unique (it is not allowed to have more than one + * attribute with the same key). + * + * Generated from protobuf field repeated .opentelemetry.proto.common.v1.KeyValue metadata = 12; + */ + private $metadata; protected $data; /** @@ -124,6 +136,14 @@ class Metric extends \Google\Protobuf\Internal\Message * @type \Opentelemetry\Proto\Metrics\V1\Histogram $histogram * @type \Opentelemetry\Proto\Metrics\V1\ExponentialHistogram $exponential_histogram * @type \Opentelemetry\Proto\Metrics\V1\Summary $summary + * @type \Opentelemetry\Proto\Common\V1\KeyValue[]|\Google\Protobuf\Internal\RepeatedField $metadata + * Additional metadata attributes that describe the metric. [Optional]. + * Attributes are non-identifying. + * Consumers SHOULD NOT need to be aware of these attributes. + * These attributes MAY be used to encode information allowing + * for lossless roundtrip translation to / from another data model. + * Attribute keys MUST be unique (it is not allowed to have more than one + * attribute with the same key). * } */ public function __construct($data = NULL) { @@ -346,6 +366,44 @@ public function setSummary($var) return $this; } + /** + * Additional metadata attributes that describe the metric. [Optional]. + * Attributes are non-identifying. + * Consumers SHOULD NOT need to be aware of these attributes. + * These attributes MAY be used to encode information allowing + * for lossless roundtrip translation to / from another data model. + * Attribute keys MUST be unique (it is not allowed to have more than one + * attribute with the same key). + * + * Generated from protobuf field repeated .opentelemetry.proto.common.v1.KeyValue metadata = 12; + * @return \Google\Protobuf\Internal\RepeatedField + */ + public function getMetadata() + { + return $this->metadata; + } + + /** + * Additional metadata attributes that describe the metric. [Optional]. + * Attributes are non-identifying. + * Consumers SHOULD NOT need to be aware of these attributes. + * These attributes MAY be used to encode information allowing + * for lossless roundtrip translation to / from another data model. + * Attribute keys MUST be unique (it is not allowed to have more than one + * attribute with the same key). + * + * Generated from protobuf field repeated .opentelemetry.proto.common.v1.KeyValue metadata = 12; + * @param \Opentelemetry\Proto\Common\V1\KeyValue[]|\Google\Protobuf\Internal\RepeatedField $var + * @return $this + */ + public function setMetadata($var) + { + $arr = GPBUtil::checkRepeatedField($var, \Google\Protobuf\Internal\GPBType::MESSAGE, \Opentelemetry\Proto\Common\V1\KeyValue::class); + $this->metadata = $arr; + + return $this; + } + /** * @return string */ diff --git a/proto/otel/Opentelemetry/Proto/Trace/V1/Span.php b/proto/otel/Opentelemetry/Proto/Trace/V1/Span.php index c5ac91009..a40d8833a 100644 --- a/proto/otel/Opentelemetry/Proto/Trace/V1/Span.php +++ b/proto/otel/Opentelemetry/Proto/Trace/V1/Span.php @@ -52,17 +52,22 @@ class Span extends \Google\Protobuf\Internal\Message */ 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`. + * Flags, a bit field. + * Bits 0-7 (8 least significant bits) are the trace flags as defined in W3C Trace + * Context specification. To read the 8-bit W3C trace flag, use + * `flags & SPAN_FLAGS_TRACE_FLAGS_MASK`. + * See https://www.w3.org/TR/trace-context-2/#trace-flags for the flag definitions. + * Bits 8 and 9 represent the 3 states of whether a span's parent + * is remote. The states are (unknown, is not remote, is remote). + * To read whether the value is known, use `(flags & SPAN_FLAGS_CONTEXT_HAS_IS_REMOTE_MASK) != 0`. + * To read whether the span is remote, use `(flags & SPAN_FLAGS_CONTEXT_IS_REMOTE_MASK) != 0`. * 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 + * (such as a runtime representation of an OpenTelemetry span), the high 22 bits MUST * be set to zero. + * Readers MUST NOT assume that bits 10-31 (22 most significant bits) will be zero. * [Optional]. - * See https://www.w3.org/TR/trace-context-2/#trace-flags for the flag definitions. * * Generated from protobuf field fixed32 flags = 16; */ @@ -192,17 +197,22 @@ class Span extends \Google\Protobuf\Internal\Message * 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`. + * Flags, a bit field. + * Bits 0-7 (8 least significant bits) are the trace flags as defined in W3C Trace + * Context specification. To read the 8-bit W3C trace flag, use + * `flags & SPAN_FLAGS_TRACE_FLAGS_MASK`. + * See https://www.w3.org/TR/trace-context-2/#trace-flags for the flag definitions. + * Bits 8 and 9 represent the 3 states of whether a span's parent + * is remote. The states are (unknown, is not remote, is remote). + * To read whether the value is known, use `(flags & SPAN_FLAGS_CONTEXT_HAS_IS_REMOTE_MASK) != 0`. + * To read whether the span is remote, use `(flags & SPAN_FLAGS_CONTEXT_IS_REMOTE_MASK) != 0`. * 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 + * (such as a runtime representation of an OpenTelemetry span), the high 22 bits MUST * be set to zero. + * Readers MUST NOT assume that bits 10-31 (22 most significant bits) will be 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 @@ -391,17 +401,22 @@ public function setParentSpanId($var) } /** - * 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`. + * Flags, a bit field. + * Bits 0-7 (8 least significant bits) are the trace flags as defined in W3C Trace + * Context specification. To read the 8-bit W3C trace flag, use + * `flags & SPAN_FLAGS_TRACE_FLAGS_MASK`. + * See https://www.w3.org/TR/trace-context-2/#trace-flags for the flag definitions. + * Bits 8 and 9 represent the 3 states of whether a span's parent + * is remote. The states are (unknown, is not remote, is remote). + * To read whether the value is known, use `(flags & SPAN_FLAGS_CONTEXT_HAS_IS_REMOTE_MASK) != 0`. + * To read whether the span is remote, use `(flags & SPAN_FLAGS_CONTEXT_IS_REMOTE_MASK) != 0`. * 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 + * (such as a runtime representation of an OpenTelemetry span), the high 22 bits MUST * be set to zero. + * Readers MUST NOT assume that bits 10-31 (22 most significant bits) will be 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 @@ -412,17 +427,22 @@ public function getFlags() } /** - * 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`. + * Flags, a bit field. + * Bits 0-7 (8 least significant bits) are the trace flags as defined in W3C Trace + * Context specification. To read the 8-bit W3C trace flag, use + * `flags & SPAN_FLAGS_TRACE_FLAGS_MASK`. + * See https://www.w3.org/TR/trace-context-2/#trace-flags for the flag definitions. + * Bits 8 and 9 represent the 3 states of whether a span's parent + * is remote. The states are (unknown, is not remote, is remote). + * To read whether the value is known, use `(flags & SPAN_FLAGS_CONTEXT_HAS_IS_REMOTE_MASK) != 0`. + * To read whether the span is remote, use `(flags & SPAN_FLAGS_CONTEXT_IS_REMOTE_MASK) != 0`. * 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 + * (such as a runtime representation of an OpenTelemetry span), the high 22 bits MUST * be set to zero. + * Readers MUST NOT assume that bits 10-31 (22 most significant bits) will be 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 diff --git a/proto/otel/Opentelemetry/Proto/Trace/V1/Span/Link.php b/proto/otel/Opentelemetry/Proto/Trace/V1/Span/Link.php index 0199570f4..75290365f 100644 --- a/proto/otel/Opentelemetry/Proto/Trace/V1/Span/Link.php +++ b/proto/otel/Opentelemetry/Proto/Trace/V1/Span/Link.php @@ -53,13 +53,18 @@ class Link extends \Google\Protobuf\Internal\Message */ 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]. + * Flags, a bit field. + * Bits 0-7 (8 least significant bits) are the trace flags as defined in W3C Trace + * Context specification. To read the 8-bit W3C trace flag, use + * `flags & SPAN_FLAGS_TRACE_FLAGS_MASK`. * See https://www.w3.org/TR/trace-context-2/#trace-flags for the flag definitions. + * Bits 8 and 9 represent the 3 states of whether the link is remote. + * The states are (unknown, is not remote, is remote). + * To read whether the value is known, use `(flags & SPAN_FLAGS_CONTEXT_HAS_IS_REMOTE_MASK) != 0`. + * To read whether the link is remote, use `(flags & SPAN_FLAGS_CONTEXT_IS_REMOTE_MASK) != 0`. + * Readers MUST NOT assume that bits 10-31 (22 most significant bits) will be zero. + * When creating new spans, bits 10-31 (most-significant 22-bits) MUST be zero. + * [Optional]. * * Generated from protobuf field fixed32 flags = 6; */ @@ -86,13 +91,18 @@ class Link extends \Google\Protobuf\Internal\Message * 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]. + * Flags, a bit field. + * Bits 0-7 (8 least significant bits) are the trace flags as defined in W3C Trace + * Context specification. To read the 8-bit W3C trace flag, use + * `flags & SPAN_FLAGS_TRACE_FLAGS_MASK`. * See https://www.w3.org/TR/trace-context-2/#trace-flags for the flag definitions. + * Bits 8 and 9 represent the 3 states of whether the link is remote. + * The states are (unknown, is not remote, is remote). + * To read whether the value is known, use `(flags & SPAN_FLAGS_CONTEXT_HAS_IS_REMOTE_MASK) != 0`. + * To read whether the link is remote, use `(flags & SPAN_FLAGS_CONTEXT_IS_REMOTE_MASK) != 0`. + * Readers MUST NOT assume that bits 10-31 (22 most significant bits) will be zero. + * When creating new spans, bits 10-31 (most-significant 22-bits) MUST be zero. + * [Optional]. * } */ public function __construct($data = NULL) { @@ -239,13 +249,18 @@ public function setDroppedAttributesCount($var) } /** - * 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]. + * Flags, a bit field. + * Bits 0-7 (8 least significant bits) are the trace flags as defined in W3C Trace + * Context specification. To read the 8-bit W3C trace flag, use + * `flags & SPAN_FLAGS_TRACE_FLAGS_MASK`. * See https://www.w3.org/TR/trace-context-2/#trace-flags for the flag definitions. + * Bits 8 and 9 represent the 3 states of whether the link is remote. + * The states are (unknown, is not remote, is remote). + * To read whether the value is known, use `(flags & SPAN_FLAGS_CONTEXT_HAS_IS_REMOTE_MASK) != 0`. + * To read whether the link is remote, use `(flags & SPAN_FLAGS_CONTEXT_IS_REMOTE_MASK) != 0`. + * Readers MUST NOT assume that bits 10-31 (22 most significant bits) will be zero. + * When creating new spans, bits 10-31 (most-significant 22-bits) MUST be zero. + * [Optional]. * * Generated from protobuf field fixed32 flags = 6; * @return int @@ -256,13 +271,18 @@ public function getFlags() } /** - * 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]. + * Flags, a bit field. + * Bits 0-7 (8 least significant bits) are the trace flags as defined in W3C Trace + * Context specification. To read the 8-bit W3C trace flag, use + * `flags & SPAN_FLAGS_TRACE_FLAGS_MASK`. * See https://www.w3.org/TR/trace-context-2/#trace-flags for the flag definitions. + * Bits 8 and 9 represent the 3 states of whether the link is remote. + * The states are (unknown, is not remote, is remote). + * To read whether the value is known, use `(flags & SPAN_FLAGS_CONTEXT_HAS_IS_REMOTE_MASK) != 0`. + * To read whether the link is remote, use `(flags & SPAN_FLAGS_CONTEXT_IS_REMOTE_MASK) != 0`. + * Readers MUST NOT assume that bits 10-31 (22 most significant bits) will be zero. + * When creating new spans, bits 10-31 (most-significant 22-bits) MUST be zero. + * [Optional]. * * Generated from protobuf field fixed32 flags = 6; * @param int $var diff --git a/proto/otel/Opentelemetry/Proto/Trace/V1/SpanFlags.php b/proto/otel/Opentelemetry/Proto/Trace/V1/SpanFlags.php index 7a29e3504..5b62be26e 100644 --- a/proto/otel/Opentelemetry/Proto/Trace/V1/SpanFlags.php +++ b/proto/otel/Opentelemetry/Proto/Trace/V1/SpanFlags.php @@ -36,10 +36,24 @@ class SpanFlags * Generated from protobuf enum SPAN_FLAGS_TRACE_FLAGS_MASK = 255; */ const SPAN_FLAGS_TRACE_FLAGS_MASK = 255; + /** + * Bits 8 and 9 are used to indicate that the parent span or link span is remote. + * Bit 8 (`HAS_IS_REMOTE`) indicates whether the value is known. + * Bit 9 (`IS_REMOTE`) indicates whether the span or link is remote. + * + * Generated from protobuf enum SPAN_FLAGS_CONTEXT_HAS_IS_REMOTE_MASK = 256; + */ + const SPAN_FLAGS_CONTEXT_HAS_IS_REMOTE_MASK = 256; + /** + * Generated from protobuf enum SPAN_FLAGS_CONTEXT_IS_REMOTE_MASK = 512; + */ + const SPAN_FLAGS_CONTEXT_IS_REMOTE_MASK = 512; 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', + self::SPAN_FLAGS_CONTEXT_HAS_IS_REMOTE_MASK => 'SPAN_FLAGS_CONTEXT_HAS_IS_REMOTE_MASK', + self::SPAN_FLAGS_CONTEXT_IS_REMOTE_MASK => 'SPAN_FLAGS_CONTEXT_IS_REMOTE_MASK', ]; public static function name($value) diff --git a/proto/otel/VERSION b/proto/otel/VERSION index 795460fce..18fa8e74f 100644 --- a/proto/otel/VERSION +++ b/proto/otel/VERSION @@ -1 +1 @@ -v1.1.0 +v1.3.0 diff --git a/src/Contrib/Otlp/SpanConverter.php b/src/Contrib/Otlp/SpanConverter.php index 9f3be3ca3..94a04150d 100644 --- a/src/Contrib/Otlp/SpanConverter.php +++ b/src/Contrib/Otlp/SpanConverter.php @@ -5,6 +5,7 @@ namespace OpenTelemetry\Contrib\Otlp; use OpenTelemetry\API\Trace as API; +use OpenTelemetry\API\Trace\SpanContextInterface; use Opentelemetry\Proto\Collector\Trace\V1\ExportTraceServiceRequest; use Opentelemetry\Proto\Common\V1\InstrumentationScope; use Opentelemetry\Proto\Common\V1\KeyValue; @@ -15,6 +16,7 @@ use Opentelemetry\Proto\Trace\V1\Span\Event; use Opentelemetry\Proto\Trace\V1\Span\Link; use Opentelemetry\Proto\Trace\V1\Span\SpanKind; +use Opentelemetry\Proto\Trace\V1\SpanFlags; use Opentelemetry\Proto\Trace\V1\Status; use Opentelemetry\Proto\Trace\V1\Status\StatusCode; use OpenTelemetry\SDK\Common\Attribute\AttributesInterface; @@ -147,7 +149,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->setFlags(self::traceFlags($span->getContext())); $pSpan->setTraceState((string) $span->getContext()->getTraceState()); if ($span->getParentContext()->isValid()) { $pSpan->setParentSpanId($this->serializer->serializeSpanId($span->getParentContext()->getSpanIdBinary())); @@ -172,7 +174,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($link->getSpanContext()->getTraceFlags()); + $pLink->setFlags(self::traceFlags($link->getSpanContext())); $pLink->setTraceState((string) $link->getSpanContext()->getTraceState()); $this->setAttributes($pLink, $link->getAttributes()); } @@ -185,4 +187,15 @@ private function convertSpan(SpanDataInterface $span): Span return $pSpan; } + + private static function traceFlags(SpanContextInterface $spanContext): int + { + $flags = $spanContext->getTraceFlags(); + $flags |= SpanFlags::SPAN_FLAGS_CONTEXT_HAS_IS_REMOTE_MASK; + if ($spanContext->isRemote()) { + $flags |= SpanFlags::SPAN_FLAGS_CONTEXT_IS_REMOTE_MASK; + } + + return $flags; + } } diff --git a/src/Contrib/composer.json b/src/Contrib/composer.json index e2a187e0a..deecfba66 100644 --- a/src/Contrib/composer.json +++ b/src/Contrib/composer.json @@ -15,7 +15,7 @@ "ext-json": "*", "open-telemetry/api": "^1.0", "open-telemetry/context": "^1.0", - "open-telemetry/gen-otlp-protobuf": "^1.1", + "open-telemetry/gen-otlp-protobuf": "^1.2", "open-telemetry/sdk": "^1.0", "open-telemetry/sem-conv": "^1.0", "php-http/async-client-implementation": "^1.0", diff --git a/tests/Unit/Contrib/Otlp/SpanConverterTest.php b/tests/Unit/Contrib/Otlp/SpanConverterTest.php index d3f46bea2..5a568e5a9 100644 --- a/tests/Unit/Contrib/Otlp/SpanConverterTest.php +++ b/tests/Unit/Contrib/Otlp/SpanConverterTest.php @@ -7,6 +7,7 @@ use function bin2hex; use OpenTelemetry\API\Trace\SpanContext; use OpenTelemetry\API\Trace\SpanKind; +use OpenTelemetry\API\Trace\TraceFlags; use OpenTelemetry\Contrib\Otlp\SpanConverter; use Opentelemetry\Proto\Common\V1\AnyValue; use Opentelemetry\Proto\Common\V1\ArrayValue; @@ -46,7 +47,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(V1\SpanFlags::SPAN_FLAGS_CONTEXT_HAS_IS_REMOTE_MASK, $row->getFlags()); $this->assertSame($span->getName(), $row->getName()); $this->assertCount(2, $row->getAttributes()); @@ -57,10 +58,26 @@ 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->assertSame(V1\SpanFlags::SPAN_FLAGS_CONTEXT_HAS_IS_REMOTE_MASK, $link->getFlags()); $this->assertCount(1, $link->getAttributes()); } + public function test_span_context_is_remote_flags(): void + { + $span = (new SpanData()) + ->setContext(SpanContext::createFromRemoteParent('0000000000000001', '00000001')) + ->addLink(SpanContext::createFromRemoteParent('0000000000000001', '00000002'), Attributes::create([])) + ->addLink(SpanContext::createFromRemoteParent('0000000000000001', '00000003', TraceFlags::SAMPLED), Attributes::create([])); + + $converter = new SpanConverter(); + /** @psalm-suppress InvalidArgument */ + $row = $converter->convert([$span])->getResourceSpans()[0]->getScopeSpans()[0]->getSpans()[0]; + + $this->assertSame(V1\SpanFlags::SPAN_FLAGS_CONTEXT_HAS_IS_REMOTE_MASK | V1\SpanFlags::SPAN_FLAGS_CONTEXT_IS_REMOTE_MASK, $row->getFlags()); + $this->assertSame(V1\SpanFlags::SPAN_FLAGS_CONTEXT_HAS_IS_REMOTE_MASK | V1\SpanFlags::SPAN_FLAGS_CONTEXT_IS_REMOTE_MASK, $row->getLinks()[0]->getFlags()); + $this->assertSame(V1\SpanFlags::SPAN_FLAGS_CONTEXT_HAS_IS_REMOTE_MASK | V1\SpanFlags::SPAN_FLAGS_CONTEXT_IS_REMOTE_MASK | TraceFlags::SAMPLED, $row->getLinks()[1]->getFlags()); + } + /** * @dataProvider attributeAreCoercedCorrectlyDataProvider */ diff --git a/tests/Unit/Contrib/Otlp/SpanExporterTest.php b/tests/Unit/Contrib/Otlp/SpanExporterTest.php index 89b1ad5f9..c552b80b1 100644 --- a/tests/Unit/Contrib/Otlp/SpanExporterTest.php +++ b/tests/Unit/Contrib/Otlp/SpanExporterTest.php @@ -91,6 +91,7 @@ public function test_json_span_and_trace_id_hex_format(): void "traceId": "0af7651916cd43dd8448eb211c80319c", "spanId": "b7ad6b7169203331", "name": "test-span-data", + "flags": 256, "kind": 1, "startTimeUnixNano": "1505855794194009601", "endTimeUnixNano": "1505855799465726528", @@ -131,6 +132,7 @@ public function test_json_invalid_utf8_sequence_is_encoded_as_bytes_value(): voi "traceId": "0af7651916cd43dd8448eb211c80319c", "spanId": "b7ad6b7169203331", "name": "test-span-data", + "flags": 256, "kind": 1, "startTimeUnixNano": "1505855794194009601", "endTimeUnixNano": "1505855799465726528",