Skip to content

Commit 1e7f6b1

Browse files
Remove duplicates of encoding of attributes
1 parent 3fae967 commit 1e7f6b1

File tree

1 file changed

+3
-24
lines changed
  • exporter/opentelemetry-exporter-otlp-proto-common/src/opentelemetry/exporter/otlp/proto/common/trace_encoder

1 file changed

+3
-24
lines changed

exporter/opentelemetry-exporter-otlp-proto-common/src/opentelemetry/exporter/otlp/proto/common/trace_encoder/__init__.py

+3-24
Original file line numberDiff line numberDiff line change
@@ -139,16 +139,9 @@ def _encode_events(
139139
encoded_event = PB2SPan.Event(
140140
name=event.name,
141141
time_unix_nano=event.timestamp,
142+
attributes=_encode_attributes(event.attributes),
142143
dropped_attributes_count=event.attributes.dropped,
143144
)
144-
for key, value in event.attributes.items():
145-
try:
146-
encoded_event.attributes.append(
147-
_encode_key_value(key, value)
148-
)
149-
# pylint: disable=broad-except
150-
except Exception as error:
151-
_logger.exception(error)
152145
pb2_events.append(encoded_event)
153146
return pb2_events
154147

@@ -161,16 +154,9 @@ def _encode_links(links: Sequence[Link]) -> Sequence[PB2SPan.Link]:
161154
encoded_link = PB2SPan.Link(
162155
trace_id=_encode_trace_id(link.context.trace_id),
163156
span_id=_encode_span_id(link.context.span_id),
157+
attributes=_encode_attributes(link.attributes),
164158
dropped_attributes_count=link.attributes.dropped,
165159
)
166-
for key, value in link.attributes.items():
167-
try:
168-
encoded_link.attributes.append(
169-
_encode_key_value(key, value)
170-
)
171-
# pylint: disable=broad-except
172-
except Exception as error:
173-
_logger.exception(error)
174160
pb2_links.append(encoded_link)
175161
return pb2_links
176162

@@ -216,11 +202,4 @@ def _encode_attributes(
216202

217203

218204
def _encode_resource(resource: Resource) -> PB2Resource:
219-
pb2_resource = PB2Resource()
220-
for key, value in resource.attributes.items():
221-
try:
222-
# pylint: disable=no-member
223-
pb2_resource.attributes.append(_encode_key_value(key, value))
224-
except Exception as error: # pylint: disable=broad-except
225-
_logger.exception(error)
226-
return pb2_resource
205+
return PB2Resource(attributes=_encode_attributes(resource.attributes))

0 commit comments

Comments
 (0)