From 5a4f17d6efff173be4960c85215ab85bcd62eea2 Mon Sep 17 00:00:00 2001 From: Jeevan Opel Date: Tue, 29 Oct 2024 21:46:32 -0700 Subject: [PATCH] Cleanup code --- .../otlp/proto/common/_internal/__init__.py | 52 +++-- .../common/_internal/_log_encoder/__init__.py | 20 +- .../_internal/metrics_encoder/__init__.py | 189 +++--------------- .../_internal/trace_encoder/__init__.py | 56 +++--- 4 files changed, 93 insertions(+), 224 deletions(-) diff --git a/src/snowflake/telemetry/_internal/opentelemetry/exporter/otlp/proto/common/_internal/__init__.py b/src/snowflake/telemetry/_internal/opentelemetry/exporter/otlp/proto/common/_internal/__init__.py index 73b77ff..9a3436b 100644 --- a/src/snowflake/telemetry/_internal/opentelemetry/exporter/otlp/proto/common/_internal/__init__.py +++ b/src/snowflake/telemetry/_internal/opentelemetry/exporter/otlp/proto/common/_internal/__init__.py @@ -15,32 +15,26 @@ import logging from collections.abc import Sequence -from itertools import count from typing import ( Any, Mapping, Optional, List, - Callable, TypeVar, - Dict, - Iterator, ) from opentelemetry.sdk.util.instrumentation import InstrumentationScope from snowflake.telemetry._internal.opentelemetry.proto.common.v1.common import ( - InstrumentationScope as PB2InstrumentationScope, + InstrumentationScope as MarshalInstrumentationScope, ) from snowflake.telemetry._internal.opentelemetry.proto.resource.v1.resource import ( - Resource as PB2Resource, + Resource as MarshalResource, ) -from snowflake.telemetry._internal.opentelemetry.proto.common.v1.common import AnyValue as PB2AnyValue -from snowflake.telemetry._internal.opentelemetry.proto.common.v1.common import KeyValue as PB2KeyValue from snowflake.telemetry._internal.opentelemetry.proto.common.v1.common import ( - KeyValueList as PB2KeyValueList, -) -from snowflake.telemetry._internal.opentelemetry.proto.common.v1.common import ( - ArrayValue as PB2ArrayValue, + KeyValueList as MarshalKeyValueList, + ArrayValue as MarshalArrayValue, + KeyValue as MarshalKeyValue, + AnyValue as MarshalAnyValue, ) from opentelemetry.sdk.trace import Resource from opentelemetry.util.types import Attributes @@ -53,43 +47,43 @@ def _encode_instrumentation_scope( instrumentation_scope: InstrumentationScope, -) -> PB2InstrumentationScope: +) -> bytes: if instrumentation_scope is None: - return PB2InstrumentationScope() - return PB2InstrumentationScope( + return MarshalInstrumentationScope() + return MarshalInstrumentationScope( name=instrumentation_scope.name, version=instrumentation_scope.version, ) -def _encode_resource(resource: Resource) -> PB2Resource: - return PB2Resource(attributes=_encode_attributes(resource.attributes)) +def _encode_resource(resource: Resource) -> bytes: + return MarshalResource(attributes=_encode_attributes(resource.attributes)) -def _encode_value(value: Any) -> PB2AnyValue: +def _encode_value(value: Any) -> bytes: if isinstance(value, bool): - return PB2AnyValue(bool_value=value) + return MarshalAnyValue(bool_value=value) if isinstance(value, str): - return PB2AnyValue(string_value=value) + return MarshalAnyValue(string_value=value) if isinstance(value, int): - return PB2AnyValue(int_value=value) + return MarshalAnyValue(int_value=value) if isinstance(value, float): - return PB2AnyValue(double_value=value) + return MarshalAnyValue(double_value=value) if isinstance(value, Sequence): - return PB2AnyValue( - array_value=PB2ArrayValue(values=[_encode_value(v) for v in value]) + return MarshalAnyValue( + array_value=MarshalArrayValue(values=[_encode_value(v) for v in value]) ) elif isinstance(value, Mapping): - return PB2AnyValue( - kvlist_value=PB2KeyValueList( + return MarshalAnyValue( + kvlist_value=MarshalKeyValueList( values=[_encode_key_value(str(k), v) for k, v in value.items()] ) ) raise Exception(f"Invalid type {type(value)} of value {value}") -def _encode_key_value(key: str, value: Any) -> PB2KeyValue: - return PB2KeyValue(key=key, value=_encode_value(value)) +def _encode_key_value(key: str, value: Any) -> bytes: + return MarshalKeyValue(key=key, value=_encode_value(value)) def _encode_span_id(span_id: int) -> bytes: @@ -102,7 +96,7 @@ def _encode_trace_id(trace_id: int) -> bytes: def _encode_attributes( attributes: Attributes, -) -> Optional[List[PB2KeyValue]]: +) -> Optional[List[bytes]]: if attributes: pb2_attributes = [] for key, value in attributes.items(): diff --git a/src/snowflake/telemetry/_internal/opentelemetry/exporter/otlp/proto/common/_internal/_log_encoder/__init__.py b/src/snowflake/telemetry/_internal/opentelemetry/exporter/otlp/proto/common/_internal/_log_encoder/__init__.py index 2fc3fd8..0700332 100644 --- a/src/snowflake/telemetry/_internal/opentelemetry/exporter/otlp/proto/common/_internal/_log_encoder/__init__.py +++ b/src/snowflake/telemetry/_internal/opentelemetry/exporter/otlp/proto/common/_internal/_log_encoder/__init__.py @@ -23,20 +23,20 @@ _encode_attributes, ) from snowflake.telemetry._internal.opentelemetry.proto.logs.v1.logs import ( - ScopeLogs, - ResourceLogs, - LogsData, + ScopeLogs as MarshalScopeLogs, + ResourceLogs as MarshalResourceLogs, + LogsData as MarshalLogsData, + LogRecord as MarshalLogRecord, ) -from snowflake.telemetry._internal.opentelemetry.proto.logs.v1.logs import LogRecord as PB2LogRecord from opentelemetry.sdk._logs import LogData def encode_logs(batch: Sequence[LogData]) -> bytes: - return bytes(LogsData(resource_logs=_encode_resource_logs(batch)) + return bytes(MarshalLogsData(resource_logs=_encode_resource_logs(batch)) ) -def _encode_log(log_data: LogData) -> PB2LogRecord: +def _encode_log(log_data: LogData) -> bytes: span_id = ( None if log_data.log_record.span_id == 0 @@ -47,7 +47,7 @@ def _encode_log(log_data: LogData) -> PB2LogRecord: if log_data.log_record.trace_id == 0 else _encode_trace_id(log_data.log_record.trace_id) ) - return PB2LogRecord( + return MarshalLogRecord( time_unix_nano=log_data.log_record.timestamp, observed_time_unix_nano=log_data.log_record.observed_timestamp, span_id=span_id, @@ -61,7 +61,7 @@ def _encode_log(log_data: LogData) -> PB2LogRecord: ) -def _encode_resource_logs(batch: Sequence[LogData]) -> List[ResourceLogs]: +def _encode_resource_logs(batch: Sequence[LogData]) -> List[bytes]: sdk_resource_logs = defaultdict(lambda: defaultdict(list)) for sdk_log in batch: @@ -77,13 +77,13 @@ def _encode_resource_logs(batch: Sequence[LogData]) -> List[ResourceLogs]: scope_logs = [] for sdk_instrumentation, pb2_logs in sdk_instrumentations.items(): scope_logs.append( - ScopeLogs( + MarshalScopeLogs( scope=(_encode_instrumentation_scope(sdk_instrumentation)), log_records=pb2_logs, ) ) pb2_resource_logs.append( - ResourceLogs( + MarshalResourceLogs( resource=_encode_resource(sdk_resource), scope_logs=scope_logs, schema_url=sdk_resource.schema_url, diff --git a/src/snowflake/telemetry/_internal/opentelemetry/exporter/otlp/proto/common/_internal/metrics_encoder/__init__.py b/src/snowflake/telemetry/_internal/opentelemetry/exporter/otlp/proto/common/_internal/metrics_encoder/__init__.py index 223b2fb..e4e92cb 100644 --- a/src/snowflake/telemetry/_internal/opentelemetry/exporter/otlp/proto/common/_internal/metrics_encoder/__init__.py +++ b/src/snowflake/telemetry/_internal/opentelemetry/exporter/otlp/proto/common/_internal/metrics_encoder/__init__.py @@ -13,30 +13,24 @@ # limitations under the License. import logging -from opentelemetry.sdk.metrics.export import ( - MetricExporter, -) -from opentelemetry.sdk.metrics.view import Aggregation -from os import environ -from opentelemetry.sdk.metrics import ( - Counter, - Histogram, - ObservableCounter, - ObservableGauge, - ObservableUpDownCounter, - UpDownCounter, -) from snowflake.telemetry._internal.opentelemetry.exporter.otlp.proto.common._internal import ( _encode_attributes, ) -from opentelemetry.sdk.environment_variables import ( - OTEL_EXPORTER_OTLP_METRICS_TEMPORALITY_PREFERENCE, -) -from opentelemetry.sdk.metrics.export import ( - AggregationTemporality, +from snowflake.telemetry._internal.opentelemetry.proto.common.v1.common import InstrumentationScope as MarshalInstrumentationScope +from snowflake.telemetry._internal.opentelemetry.proto.metrics.v1.metrics import ( + NumberDataPoint as MarshalNumberDataPoint, + HistogramDataPoint as MarshalHistogramDataPoint, + ExponentialHistogramDataPoint as MarshalExponentialHistogramDataPoint, + ExponentialHistogramDataPoint_Buckets as MarshalBuckets, + Metric as MarshalMetric, + Gauge as MarshalGauge, + Histogram as MarshalHistogram, + Sum as MarshalSum, + ExponentialHistogram as MarshalExponentialHistogram, + ResourceMetrics as MarshalResourceMetrics, + MetricsData as MarshalMetricsData, + ScopeMetrics as MarshalScopeMetrics, ) -from snowflake.telemetry._internal.opentelemetry.proto.common.v1.common import InstrumentationScope -from snowflake.telemetry._internal.opentelemetry.proto.metrics.v1 import metrics as pb2 from opentelemetry.sdk.metrics.export import ( MetricsData, Gauge, @@ -44,132 +38,13 @@ Sum, ExponentialHistogram as ExponentialHistogramType, ) -from typing import Dict from snowflake.telemetry._internal.opentelemetry.proto.resource.v1.resource import ( - Resource as PB2Resource, -) -from opentelemetry.sdk.environment_variables import ( - OTEL_EXPORTER_OTLP_METRICS_DEFAULT_HISTOGRAM_AGGREGATION, -) -from opentelemetry.sdk.metrics.view import ( - ExponentialBucketHistogramAggregation, - ExplicitBucketHistogramAggregation, + Resource as MarshalResource, ) _logger = logging.getLogger(__name__) -class OTLPMetricExporterMixin: - def _common_configuration( - self, - preferred_temporality: Dict[type, AggregationTemporality] = None, - preferred_aggregation: Dict[type, Aggregation] = None, - ) -> None: - - MetricExporter.__init__( - self, - preferred_temporality=self._get_temporality(preferred_temporality), - preferred_aggregation=self._get_aggregation(preferred_aggregation), - ) - - def _get_temporality( - self, preferred_temporality: Dict[type, AggregationTemporality] - ) -> Dict[type, AggregationTemporality]: - - otel_exporter_otlp_metrics_temporality_preference = ( - environ.get( - OTEL_EXPORTER_OTLP_METRICS_TEMPORALITY_PREFERENCE, - "CUMULATIVE", - ) - .upper() - .strip() - ) - - if otel_exporter_otlp_metrics_temporality_preference == "DELTA": - instrument_class_temporality = { - Counter: AggregationTemporality.DELTA, - UpDownCounter: AggregationTemporality.CUMULATIVE, - Histogram: AggregationTemporality.DELTA, - ObservableCounter: AggregationTemporality.DELTA, - ObservableUpDownCounter: AggregationTemporality.CUMULATIVE, - ObservableGauge: AggregationTemporality.CUMULATIVE, - } - - elif otel_exporter_otlp_metrics_temporality_preference == "LOWMEMORY": - instrument_class_temporality = { - Counter: AggregationTemporality.DELTA, - UpDownCounter: AggregationTemporality.CUMULATIVE, - Histogram: AggregationTemporality.DELTA, - ObservableCounter: AggregationTemporality.CUMULATIVE, - ObservableUpDownCounter: AggregationTemporality.CUMULATIVE, - ObservableGauge: AggregationTemporality.CUMULATIVE, - } - - else: - if otel_exporter_otlp_metrics_temporality_preference != ( - "CUMULATIVE" - ): - _logger.warning( - "Unrecognized OTEL_EXPORTER_METRICS_TEMPORALITY_PREFERENCE" - " value found: " - f"{otel_exporter_otlp_metrics_temporality_preference}, " - "using CUMULATIVE" - ) - instrument_class_temporality = { - Counter: AggregationTemporality.CUMULATIVE, - UpDownCounter: AggregationTemporality.CUMULATIVE, - Histogram: AggregationTemporality.CUMULATIVE, - ObservableCounter: AggregationTemporality.CUMULATIVE, - ObservableUpDownCounter: AggregationTemporality.CUMULATIVE, - ObservableGauge: AggregationTemporality.CUMULATIVE, - } - - instrument_class_temporality.update(preferred_temporality or {}) - - return instrument_class_temporality - - def _get_aggregation( - self, - preferred_aggregation: Dict[type, Aggregation], - ) -> Dict[type, Aggregation]: - - otel_exporter_otlp_metrics_default_histogram_aggregation = environ.get( - OTEL_EXPORTER_OTLP_METRICS_DEFAULT_HISTOGRAM_AGGREGATION, - "explicit_bucket_histogram", - ) - - if otel_exporter_otlp_metrics_default_histogram_aggregation == ( - "base2_exponential_bucket_histogram" - ): - - instrument_class_aggregation = { - Histogram: ExponentialBucketHistogramAggregation(), - } - - else: - - if otel_exporter_otlp_metrics_default_histogram_aggregation != ( - "explicit_bucket_histogram" - ): - - _logger.warning( - ( - "Invalid value for %s: %s, using explicit bucket " - "histogram aggregation" - ), - OTEL_EXPORTER_OTLP_METRICS_DEFAULT_HISTOGRAM_AGGREGATION, - otel_exporter_otlp_metrics_default_histogram_aggregation, - ) - - instrument_class_aggregation = { - Histogram: ExplicitBucketHistogramAggregation(), - } - - instrument_class_aggregation.update(preferred_aggregation or {}) - - return instrument_class_aggregation - - def encode_metrics(data: MetricsData) -> bytes: resource_metrics_dict = {} @@ -201,7 +76,7 @@ def encode_metrics(data: MetricsData) -> bytes: else: as_double = data_point.value - pt = pb2.NumberDataPoint( + pt = MarshalNumberDataPoint( attributes=_encode_attributes( data_point.attributes ), @@ -211,13 +86,13 @@ def encode_metrics(data: MetricsData) -> bytes: ) pb2_data_points.append(pt) - pb2_metric_gauge = pb2.Gauge(data_points=pb2_data_points) + pb2_metric_gauge = MarshalGauge(data_points=pb2_data_points) elif isinstance(metric.data, HistogramType): pb2_data_points = [] pb2_aggregation_temporality = None for data_point in metric.data.data_points: - pt = pb2.HistogramDataPoint( + pt = MarshalHistogramDataPoint( attributes=_encode_attributes( data_point.attributes ), @@ -236,7 +111,7 @@ def encode_metrics(data: MetricsData) -> bytes: metric.data.aggregation_temporality ) pb2_data_points.append(pt) - pb2_metric_histogram = pb2.Histogram( + pb2_metric_histogram = MarshalHistogram( data_points=pb2_data_points, aggregation_temporality=pb2_aggregation_temporality ) @@ -252,7 +127,7 @@ def encode_metrics(data: MetricsData) -> bytes: as_int = data_point.value else: as_double = data_point.value - pt = pb2.NumberDataPoint( + pt = MarshalNumberDataPoint( attributes=_encode_attributes( data_point.attributes ), @@ -265,13 +140,13 @@ def encode_metrics(data: MetricsData) -> bytes: ) # note that because sum is a message type, the # fields must be set individually rather than - # instantiating a pb2.Sum and setting it once + # instantiating a MarshalSum and setting it once pb2_aggregation_temporality = ( metric.data.aggregation_temporality ) pb2_is_monotonic = metric.data.is_monotonic pb2_data_points.append(pt) - pb2_metric_sum = pb2.Sum( + pb2_metric_sum = MarshalSum( data_points=pb2_data_points, aggregation_temporality=pb2_aggregation_temporality, is_monotonic=pb2_is_monotonic, @@ -283,7 +158,7 @@ def encode_metrics(data: MetricsData) -> bytes: for data_point in metric.data.data_points: if data_point.positive.bucket_counts: - positive = pb2.ExponentialHistogramDataPoint_Buckets( + positive = MarshalBuckets( offset=data_point.positive.offset, bucket_counts=data_point.positive.bucket_counts, ) @@ -291,14 +166,14 @@ def encode_metrics(data: MetricsData) -> bytes: positive = None if data_point.negative.bucket_counts: - negative = pb2.ExponentialHistogramDataPoint_Buckets( + negative = MarshalBuckets( offset=data_point.negative.offset, bucket_counts=data_point.negative.bucket_counts, ) else: negative = None - pt = pb2.ExponentialHistogramDataPoint( + pt = MarshalExponentialHistogramDataPoint( attributes=_encode_attributes( data_point.attributes ), @@ -321,7 +196,7 @@ def encode_metrics(data: MetricsData) -> bytes: ) pb2_data_points.append(pt) - pb2_metric_exponential_histogram = pb2.ExponentialHistogram( + pb2_metric_exponential_histogram = MarshalExponentialHistogram( data_points=pb2_data_points, aggregation_temporality=pb2_aggregation_temporality, ) @@ -334,7 +209,7 @@ def encode_metrics(data: MetricsData) -> bytes: continue - pb2_metric = pb2.Metric( + pb2_metric = MarshalMetric( name=metric.name, description=metric.description, unit=metric.unit, @@ -352,8 +227,8 @@ def encode_metrics(data: MetricsData) -> bytes: # The SDK groups metrics in instrumentation scopes already so # there is no need to check for existing instrumentation scopes # here. - pb2_scope_metrics = pb2.ScopeMetrics( - scope=InstrumentationScope( + pb2_scope_metrics = MarshalScopeMetrics( + scope=MarshalInstrumentationScope( name=instrumentation_scope.name, version=instrumentation_scope.version, ), @@ -368,8 +243,8 @@ def encode_metrics(data: MetricsData) -> bytes: scope_data, ) in resource_metrics_dict.items(): resource_data.append( - pb2.ResourceMetrics( - resource=PB2Resource( + MarshalResourceMetrics( + resource=MarshalResource( attributes=_encode_attributes(sdk_resource.attributes) ), scope_metrics=scope_data.values(), @@ -377,4 +252,4 @@ def encode_metrics(data: MetricsData) -> bytes: ) ) resource_metrics = resource_data - return bytes(pb2.MetricsData(resource_metrics=resource_metrics)) \ No newline at end of file + return bytes(MarshalMetricsData(resource_metrics=resource_metrics)) \ No newline at end of file diff --git a/src/snowflake/telemetry/_internal/opentelemetry/exporter/otlp/proto/common/_internal/trace_encoder/__init__.py b/src/snowflake/telemetry/_internal/opentelemetry/exporter/otlp/proto/common/_internal/trace_encoder/__init__.py index 416ed4f..a3b5632 100644 --- a/src/snowflake/telemetry/_internal/opentelemetry/exporter/otlp/proto/common/_internal/trace_encoder/__init__.py +++ b/src/snowflake/telemetry/_internal/opentelemetry/exporter/otlp/proto/common/_internal/trace_encoder/__init__.py @@ -24,15 +24,15 @@ _encode_trace_id, ) from snowflake.telemetry._internal.opentelemetry.proto.trace.v1.trace import ( - ResourceSpans as PB2ResourceSpans, - ScopeSpans as PB2ScopeSpans, - Span as PB2Span, - SpanFlags as PB2SpanFlags, - Status as PB2Status, - Span_SpanKind as PB2SpanKind, - Span_Event as PB2SpanEvent, - Span_Link as PB2SpanLink, - TracesData as PB2TracesData, + ResourceSpans as MarshalResourceSpans, + ScopeSpans as MarshalScopeSpans, + Span as MarshalSpan, + SpanFlags as EnumSpanFlags, + Status as MarshalStatus, + Span_SpanKind as EnumSpanKind, + Span_Event as MarshalSpanEvent, + Span_Link as MarshalSpanLink, + TracesData as MarshalTracesData, ) from opentelemetry.sdk.trace import Event, ReadableSpan from opentelemetry.trace import Link, SpanKind @@ -40,11 +40,11 @@ # pylint: disable=E1101 _SPAN_KIND_MAP = { - SpanKind.INTERNAL: PB2SpanKind.SPAN_KIND_INTERNAL, - SpanKind.SERVER: PB2SpanKind.SPAN_KIND_SERVER, - SpanKind.CLIENT: PB2SpanKind.SPAN_KIND_CLIENT, - SpanKind.PRODUCER: PB2SpanKind.SPAN_KIND_PRODUCER, - SpanKind.CONSUMER: PB2SpanKind.SPAN_KIND_CONSUMER, + SpanKind.INTERNAL: EnumSpanKind.SPAN_KIND_INTERNAL, + SpanKind.SERVER: EnumSpanKind.SPAN_KIND_SERVER, + SpanKind.CLIENT: EnumSpanKind.SPAN_KIND_CLIENT, + SpanKind.PRODUCER: EnumSpanKind.SPAN_KIND_PRODUCER, + SpanKind.CONSUMER: EnumSpanKind.SPAN_KIND_CONSUMER, } _logger = logging.getLogger(__name__) @@ -53,14 +53,14 @@ def encode_spans( sdk_spans: Sequence[ReadableSpan], ) -> bytes: - return bytes(PB2TracesData( + return bytes(MarshalTracesData( resource_spans=_encode_resource_spans(sdk_spans) )) def _encode_resource_spans( sdk_spans: Sequence[ReadableSpan], -) -> List[PB2ResourceSpans]: +) -> List[bytes]: # We need to inspect the spans and group + structure them as: # # Resource @@ -87,13 +87,13 @@ def _encode_resource_spans( scope_spans = [] for sdk_instrumentation, pb2_spans in sdk_instrumentations.items(): scope_spans.append( - PB2ScopeSpans( + MarshalScopeSpans( scope=(_encode_instrumentation_scope(sdk_instrumentation)), spans=pb2_spans, ) ) pb2_resource_spans.append( - PB2ResourceSpans( + MarshalResourceSpans( resource=_encode_resource(sdk_resource), scope_spans=scope_spans, schema_url=sdk_resource.schema_url, @@ -104,15 +104,15 @@ def _encode_resource_spans( def _span_flags(parent_span_context: Optional[SpanContext]) -> int: - flags = PB2SpanFlags.SPAN_FLAGS_CONTEXT_HAS_IS_REMOTE_MASK + flags = EnumSpanFlags.SPAN_FLAGS_CONTEXT_HAS_IS_REMOTE_MASK if parent_span_context and parent_span_context.is_remote: - flags |= PB2SpanFlags.SPAN_FLAGS_CONTEXT_IS_REMOTE_MASK + flags |= EnumSpanFlags.SPAN_FLAGS_CONTEXT_IS_REMOTE_MASK return flags -def _encode_span(sdk_span: ReadableSpan) -> PB2Span: +def _encode_span(sdk_span: ReadableSpan) -> bytes: span_context = sdk_span.get_span_context() - return PB2Span( + return MarshalSpan( trace_id=_encode_trace_id(span_context.trace_id), span_id=_encode_span_id(span_context.span_id), trace_state=_encode_trace_state(span_context.trace_state), @@ -134,12 +134,12 @@ def _encode_span(sdk_span: ReadableSpan) -> PB2Span: def _encode_events( events: Sequence[Event], -) -> Optional[List[PB2SpanEvent]]: +) -> Optional[List[bytes]]: pb2_events = None if events: pb2_events = [] for event in events: - encoded_event = PB2SpanEvent( + encoded_event = MarshalSpanEvent( name=event.name, time_unix_nano=event.timestamp, attributes=_encode_attributes(event.attributes), @@ -149,12 +149,12 @@ def _encode_events( return pb2_events -def _encode_links(links: Sequence[Link]) -> Sequence[PB2SpanLink]: +def _encode_links(links: Sequence[Link]) -> Sequence[bytes]: pb2_links = None if links: pb2_links = [] for link in links: - encoded_link = PB2SpanLink( + encoded_link = MarshalSpanLink( trace_id=_encode_trace_id(link.context.trace_id), span_id=_encode_span_id(link.context.span_id), attributes=_encode_attributes(link.attributes), @@ -165,10 +165,10 @@ def _encode_links(links: Sequence[Link]) -> Sequence[PB2SpanLink]: return pb2_links -def _encode_status(status: Status) -> Optional[PB2Status]: +def _encode_status(status: Status) -> Optional[bytes]: pb2_status = None if status is not None: - pb2_status = PB2Status( + pb2_status = MarshalStatus( code=status.status_code.value, message=status.description, )