Skip to content

Commit 06e4755

Browse files
cursoragenthassiebp
andcommitted
fix(otel): type SDK attribute mappings for opentelemetry 1.45.1
Co-authored-by: hassieb.pakzad <hassieb.pakzad@clickhouse.com>
1 parent cd37863 commit 06e4755

1 file changed

Lines changed: 13 additions & 2 deletions

File tree

‎langfuse/_client/span_exporter.py‎

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ def export(self, spans: Sequence[ReadableSpan]) -> SpanExportResult:
112112
span,
113113
self._process_media_attributes(
114114
span=span,
115-
attributes=dict(span.attributes or {}),
115+
attributes=_attributes_dict(span.attributes),
116116
),
117117
)
118118
for span in spans
@@ -574,10 +574,21 @@ def _create_otel_span_data(
574574
if instrumentation_scope
575575
else None,
576576
attributes=MappingProxyType(dict(attributes)),
577-
resource_attributes=MappingProxyType(dict(span.resource.attributes or {})),
577+
resource_attributes=MappingProxyType(
578+
_attributes_dict(span.resource.attributes)
579+
),
578580
)
579581

580582

583+
def _attributes_dict(
584+
attributes: Optional[MappingCollection[str, Any]],
585+
) -> Dict[str, AttributeValue]:
586+
# The SDK types attribute values as the recursive ``AnyValue``, which also
587+
# allows bytes, mappings and None. The exporter passes such values through
588+
# unchanged, so they are treated as opaque ``AttributeValue``s here.
589+
return cast(Dict[str, AttributeValue], dict(attributes or {}))
590+
591+
581592
def _clean_attribute_value(*, key: str, value: Any) -> Optional[AttributeValue]:
582593
cleaned_attributes = BoundedAttributes(maxlen=1, immutable=False)
583594

0 commit comments

Comments
 (0)