Skip to content

Commit

Permalink
Strip letters (#877)
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrew Xue authored Jul 3, 2020
1 parent 2a9c3ac commit 112bade
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,10 @@ def _extract_events(events: Sequence[Event]) -> ProtoSpan.TimeEvents:
)


def _strip_characters(ot_version):
return "".join(filter(lambda x: x.isdigit() or x == ".", ot_version))


def _extract_attributes(
attrs: types.Attributes,
num_attrs_limit: int,
Expand All @@ -310,8 +314,10 @@ def _extract_attributes(
if add_agent_attr:
attributes_dict["g.co/agent"] = _format_attribute_value(
"opentelemetry-python {}; google-cloud-trace-exporter {}".format(
pkg_resources.get_distribution("opentelemetry-sdk").version,
cloud_trace_version,
_strip_characters(
pkg_resources.get_distribution("opentelemetry-sdk").version
),
_strip_characters(cloud_trace_version),
)
)
return ProtoSpan.Attributes(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
_extract_links,
_extract_status,
_format_attribute_value,
_strip_characters,
_truncate_str,
)
from opentelemetry.exporter.cloud_trace.version import (
Expand Down Expand Up @@ -117,10 +118,12 @@ def test_export(self):
attribute_map={
"g.co/agent": _format_attribute_value(
"opentelemetry-python {}; google-cloud-trace-exporter {}".format(
pkg_resources.get_distribution(
"opentelemetry-sdk"
).version,
cloud_trace_version,
_strip_characters(
pkg_resources.get_distribution(
"opentelemetry-sdk"
).version
),
_strip_characters(cloud_trace_version),
)
)
}
Expand Down Expand Up @@ -415,3 +418,10 @@ def test_truncate(self):
),
MAX_EVENT_ATTRS,
)

def test_strip_characters(self):
self.assertEqual("0.10.0", _strip_characters("0.10.0b"))
self.assertEqual("1.20.5", _strip_characters("1.20.5"))
self.assertEqual("3.1.0", _strip_characters("3.1.0beta"))
self.assertEqual("4.2.0", _strip_characters("4b.2rc.0a"))
self.assertEqual("6.20.15", _strip_characters("b6.20.15"))

0 comments on commit 112bade

Please sign in to comment.