-
Notifications
You must be signed in to change notification settings - Fork 45
/
Copy pathtest_cloud_trace_exporter.py
782 lines (733 loc) · 27.1 KB
/
test_cloud_trace_exporter.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
# Copyright 2021 The OpenTelemetry Authors
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import re
import unittest
from unittest import mock
import pkg_resources
from google.cloud.trace_v2.services.trace_service.transports import (
TraceServiceGrpcTransport,
)
from google.cloud.trace_v2.types import AttributeValue, BatchWriteSpansRequest
from google.cloud.trace_v2.types import Span as ProtoSpan
from google.cloud.trace_v2.types import TruncatableString
from google.rpc import code_pb2
from google.rpc.status_pb2 import Status
from opentelemetry.exporter.cloud_trace import (
MAX_EVENT_ATTRS,
MAX_LINK_ATTRS,
MAX_NUM_EVENTS,
MAX_NUM_LINKS,
CloudTraceSpanExporter,
_extract_attributes,
_extract_events,
_extract_links,
_extract_resources,
_extract_span_kind,
_extract_status,
_format_attribute_value,
_get_time_from_ns,
_strip_characters,
_truncate_str,
)
from opentelemetry.exporter.cloud_trace.version import __version__
from opentelemetry.sdk.resources import Resource
from opentelemetry.sdk.trace import Event
from opentelemetry.sdk.trace import _Span as Span
from opentelemetry.trace import Link, SpanContext, SpanKind
from opentelemetry.trace.status import Status as SpanStatus
from opentelemetry.trace.status import StatusCode
# pylint: disable=too-many-public-methods
class TestCloudTraceSpanExporter(unittest.TestCase):
def setUp(self):
self.patchers = [
mock.patch(
"opentelemetry.exporter.cloud_trace.TraceServiceClient"
),
mock.patch.object(TraceServiceGrpcTransport, "create_channel"),
]
for patcher in self.patchers:
patcher.start()
def tearDown(self):
for patcher in self.patchers:
patcher.stop()
@classmethod
def setUpClass(cls):
cls.project_id = "PROJECT"
cls.attributes_variety_pack = {
"str_key": "str_value",
"bool_key": False,
"double_key": 1.421,
"int_key": 123,
}
cls.extracted_attributes_variety_pack = ProtoSpan.Attributes(
attribute_map={
"str_key": AttributeValue(
string_value=TruncatableString(
value="str_value", truncated_byte_count=0
)
),
"bool_key": AttributeValue(bool_value=False),
"double_key": AttributeValue(
string_value=TruncatableString(
value="1.4210", truncated_byte_count=0
)
),
"int_key": AttributeValue(int_value=123),
}
)
cls.agent_code = _format_attribute_value(
"opentelemetry-python {}; google-cloud-trace-exporter {}".format(
_strip_characters(
pkg_resources.get_distribution("opentelemetry-sdk").version
),
_strip_characters(__version__),
)
)
cls.example_trace_id = "6e0c63257de34c92bf9efcd03927272e"
cls.example_span_id = "95bb5edabd45950f"
cls.example_time_in_ns = 1589919268850900051
cls.example_time_stamp = _get_time_from_ns(cls.example_time_in_ns)
cls.str_20kb = "a" * 20 * 1024
cls.str_16kb = "a" * 16 * 1024
cls.str_300 = "a" * 300
cls.str_256 = "a" * 256
cls.str_128 = "a" * 128
def test_constructor_default(self):
exporter = CloudTraceSpanExporter(self.project_id)
self.assertEqual(exporter.project_id, self.project_id)
def test_constructor_explicit(self):
client = mock.Mock()
exporter = CloudTraceSpanExporter(self.project_id, client=client)
self.assertIs(exporter.client, client)
self.assertEqual(exporter.project_id, self.project_id)
def test_export(self):
resource_info = Resource(
{
"cloud.account.id": "123",
"cloud.platform": "gcp_compute_engine",
"cloud.provider": "gcp",
"cloud.region": "us-east4",
"cloud.availability_zone": "us-east4-b",
"host.id": "host",
"host.name": "fakeName",
"host.type": "fakeMachineType",
}
)
span_datas = [
Span(
name="span_name",
context=SpanContext(
trace_id=int(self.example_trace_id, 16),
span_id=int(self.example_span_id, 16),
is_remote=False,
),
parent=None,
kind=SpanKind.INTERNAL,
resource=resource_info,
attributes={"attr_key": "attr_value"},
)
]
cloud_trace_spans = {
"name": "projects/{}/traces/{}/spans/{}".format(
self.project_id, self.example_trace_id, self.example_span_id
),
"span_id": self.example_span_id,
"parent_span_id": None,
"display_name": TruncatableString(
value="span_name", truncated_byte_count=0
),
"attributes": ProtoSpan.Attributes(
attribute_map={
"g.co/r/gce_instance/zone": _format_attribute_value(
"us-east4-b"
),
"g.co/r/gce_instance/instance_id": _format_attribute_value(
"host"
),
"g.co/agent": self.agent_code,
"attr_key": _format_attribute_value("attr_value"),
}
),
"links": None,
"status": None,
"time_events": None,
"start_time": None,
"end_time": None,
# pylint: disable=no-member
"span_kind": ProtoSpan.SpanKind.INTERNAL,
}
client = mock.Mock()
exporter = CloudTraceSpanExporter(self.project_id, client=client)
exporter.export(span_datas)
self.assertTrue(client.batch_write_spans.called)
client.batch_write_spans.assert_called_with(
request=BatchWriteSpansRequest(
name="projects/{}".format(self.project_id),
spans=[cloud_trace_spans],
)
)
def test_extract_status_code_unset(self):
self.assertIsNone(
_extract_status(SpanStatus(status_code=StatusCode.UNSET))
)
def test_extract_status_code_ok(self):
self.assertEqual(
_extract_status(SpanStatus(status_code=StatusCode.OK)),
Status(code=code_pb2.OK),
)
def test_extract_status_code_error(self):
self.assertEqual(
_extract_status(
SpanStatus(
status_code=StatusCode.ERROR,
description="error_desc",
)
),
Status(code=code_pb2.UNKNOWN, message="error_desc"),
)
def test_extract_status_code_future_added(self):
self.assertEqual(
_extract_status(
SpanStatus(
status_code=mock.Mock(),
)
),
Status(code=code_pb2.UNKNOWN),
)
def test_extract_empty_attributes(self):
self.assertEqual(
_extract_attributes({}, num_attrs_limit=4),
ProtoSpan.Attributes(attribute_map={}),
)
def test_extract_variety_of_attributes(self):
self.assertEqual(
_extract_attributes(
self.attributes_variety_pack, num_attrs_limit=4
),
self.extracted_attributes_variety_pack,
)
def test_extract_label_mapping_attributes(self):
attributes_labels_mapping = {
"http.scheme": "http",
"http.host": "172.19.0.4:8000",
"http.method": "POST",
"http.request_content_length": 321,
"http.response_content_length": 123,
"http.route": "/fuzzy/search",
"http.status_code": 200,
"http.url": "http://172.19.0.4:8000/fuzzy/search",
"http.user_agent": "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.116 Safari/537.36",
}
extracted_attributes_labels_mapping = ProtoSpan.Attributes(
attribute_map={
"/http/client_protocol": AttributeValue(
string_value=TruncatableString(
value="http", truncated_byte_count=0
)
),
"/http/host": AttributeValue(
string_value=TruncatableString(
value="172.19.0.4:8000", truncated_byte_count=0
)
),
"/http/method": AttributeValue(
string_value=TruncatableString(
value="POST", truncated_byte_count=0
)
),
"/http/request/size": AttributeValue(int_value=321),
"/http/response/size": AttributeValue(int_value=123),
"/http/route": AttributeValue(
string_value=TruncatableString(
value="/fuzzy/search", truncated_byte_count=0
)
),
"/http/status_code": AttributeValue(int_value=200),
"/http/url": AttributeValue(
string_value=TruncatableString(
value="http://172.19.0.4:8000/fuzzy/search",
truncated_byte_count=0,
)
),
"/http/user_agent": AttributeValue(
string_value=TruncatableString(
value="Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.116 Safari/537.36",
truncated_byte_count=0,
)
),
}
)
self.assertEqual(
_extract_attributes(attributes_labels_mapping, num_attrs_limit=9),
extracted_attributes_labels_mapping,
)
def test_ignore_invalid_attributes(self):
self.assertEqual(
_extract_attributes(
{"illegal_attribute_value": {}, "legal_attribute": 3},
num_attrs_limit=4,
),
ProtoSpan.Attributes(
attribute_map={"legal_attribute": AttributeValue(int_value=3)},
dropped_attributes_count=1,
),
)
def test_too_many_attributes(self):
too_many_attrs = {}
for attr_key in range(5):
too_many_attrs[str(attr_key)] = 0
proto_attrs = _extract_attributes(too_many_attrs, num_attrs_limit=4)
self.assertEqual(proto_attrs.dropped_attributes_count, 1)
def test_add_agent_attribute(self):
self.assertEqual(
_extract_attributes({}, num_attrs_limit=4, add_agent_attr=True),
ProtoSpan.Attributes(
attribute_map={"g.co/agent": self.agent_code},
dropped_attributes_count=0,
),
)
def test_agent_attribute_priority(self):
# Drop existing attributes in favor of the agent attribute
self.assertEqual(
_extract_attributes(
{"attribute_key": "attr_value"},
num_attrs_limit=1,
add_agent_attr=True,
),
ProtoSpan.Attributes(
attribute_map={"g.co/agent": self.agent_code},
dropped_attributes_count=1,
),
)
def test_attribute_value_truncation(self):
# shouldn't truncate
self.assertEqual(
_format_attribute_value(self.str_300),
AttributeValue(
string_value=TruncatableString(
value=self.str_300,
truncated_byte_count=0,
)
),
)
# huge string should truncate
self.assertEqual(
_format_attribute_value(self.str_20kb),
AttributeValue(
string_value=TruncatableString(
value=self.str_16kb,
truncated_byte_count=(20 - 16) * 1024,
)
),
)
def test_list_attribute_value(self):
self.assertEqual(
_format_attribute_value(("one", "two")),
AttributeValue(
string_value=TruncatableString(
value="one,two", truncated_byte_count=0
)
),
)
self.assertEqual(
_format_attribute_value([True]),
AttributeValue(
string_value=TruncatableString(
value="True", truncated_byte_count=0
)
),
)
self.assertEqual(
_format_attribute_value((2, 5)),
AttributeValue(
string_value=TruncatableString(
value="2,5", truncated_byte_count=0
)
),
)
self.assertEqual(
_format_attribute_value([2.0, 0.5, 4.55]),
AttributeValue(
string_value=TruncatableString(
value="2.0,0.5,4.55", truncated_byte_count=0
)
),
)
def test_attribute_key_truncation(self):
self.assertEqual(
_extract_attributes(
{self.str_300: "attr_value"}, num_attrs_limit=4
),
ProtoSpan.Attributes(
attribute_map={
self.str_128: AttributeValue(
string_value=TruncatableString(
value="attr_value", truncated_byte_count=0
)
)
}
),
)
def test_extract_empty_events(self):
self.assertIsNone(_extract_events([]))
def test_too_many_events(self):
event = Event(
name="event", timestamp=self.example_time_in_ns, attributes={}
)
too_many_events = [event] * (MAX_NUM_EVENTS + 5)
self.assertEqual(
_extract_events(too_many_events),
ProtoSpan.TimeEvents(
time_event=[
{
"time": self.example_time_stamp,
"annotation": {
"description": TruncatableString(
value="event",
),
"attributes": {},
},
},
]
* MAX_NUM_EVENTS,
dropped_annotations_count=len(too_many_events)
- MAX_NUM_EVENTS,
),
)
def test_too_many_event_attributes(self):
event_attrs = {}
for attr_key in range(MAX_EVENT_ATTRS + 5):
event_attrs[str(attr_key)] = 0
proto_events = _extract_events(
[
Event(
name="a",
attributes=event_attrs,
timestamp=self.example_time_in_ns,
)
]
)
self.assertEqual(
len(
proto_events.time_event[0].annotation.attributes.attribute_map
),
MAX_EVENT_ATTRS,
)
self.assertEqual(
proto_events.time_event[
0
].annotation.attributes.dropped_attributes_count,
len(event_attrs) - MAX_EVENT_ATTRS,
)
def test_extract_multiple_events(self):
event1 = Event(
name="event1",
attributes=self.attributes_variety_pack,
timestamp=self.example_time_in_ns,
)
event2_nanos = 1589919438550020326
event2 = Event(
name="event2",
attributes={"illegal_attr_value": dict()},
timestamp=event2_nanos,
)
self.assertEqual(
_extract_events([event1, event2]),
ProtoSpan.TimeEvents(
time_event=[
{
"time": self.example_time_stamp,
"annotation": {
"description": TruncatableString(
value="event1", truncated_byte_count=0
),
"attributes": self.extracted_attributes_variety_pack,
},
},
{
"time": _get_time_from_ns(event2_nanos),
"annotation": {
"description": TruncatableString(
value="event2", truncated_byte_count=0
),
"attributes": ProtoSpan.Attributes(
attribute_map={}, dropped_attributes_count=1
),
},
},
]
),
)
def test_event_name_truncation(self):
event1 = Event(
name=self.str_300, attributes={}, timestamp=self.example_time_in_ns
)
self.assertEqual(
_extract_events([event1]),
ProtoSpan.TimeEvents(
time_event=[
{
"time": self.example_time_stamp,
"annotation": {
"description": TruncatableString(
value=self.str_256,
truncated_byte_count=300 - 256,
),
"attributes": {},
},
},
]
),
)
def test_extract_empty_links(self):
self.assertIsNone(_extract_links([]))
def test_extract_multiple_links(self):
span_id1 = "95bb5edabd45950f"
span_id2 = "b6b86ad2915c9ddc"
link1 = Link(
context=SpanContext(
trace_id=int(self.example_trace_id, 16),
span_id=int(span_id1, 16),
is_remote=False,
),
attributes={},
)
link2 = Link(
context=SpanContext(
trace_id=int(self.example_trace_id, 16),
span_id=int(span_id1, 16),
is_remote=False,
),
attributes=self.attributes_variety_pack,
)
link3 = Link(
context=SpanContext(
trace_id=int(self.example_trace_id, 16),
span_id=int(span_id2, 16),
is_remote=False,
),
attributes={"illegal_attr_value": dict(), "int_attr_value": 123},
)
self.assertEqual(
_extract_links([link1, link2, link3]),
ProtoSpan.Links(
link=[
{
"trace_id": self.example_trace_id,
"span_id": span_id1,
"type": "TYPE_UNSPECIFIED",
"attributes": ProtoSpan.Attributes(attribute_map={}),
},
{
"trace_id": self.example_trace_id,
"span_id": span_id1,
"type": "TYPE_UNSPECIFIED",
"attributes": self.extracted_attributes_variety_pack,
},
{
"trace_id": self.example_trace_id,
"span_id": span_id2,
"type": "TYPE_UNSPECIFIED",
"attributes": {
"attribute_map": {
"int_attr_value": AttributeValue(int_value=123)
},
},
},
]
),
)
def test_extract_link_with_none_attribute(self):
link = Link(
context=SpanContext(
trace_id=int(self.example_trace_id, 16),
span_id=int(self.example_span_id, 16),
is_remote=False,
),
attributes=None,
)
self.assertEqual(
_extract_links([link]),
ProtoSpan.Links(
link=[
{
"trace_id": self.example_trace_id,
"span_id": self.example_span_id,
"type": "TYPE_UNSPECIFIED",
"attributes": ProtoSpan.Attributes(attribute_map={}),
},
]
),
)
def test_too_many_links(self):
link = Link(
context=SpanContext(
trace_id=int(self.example_trace_id, 16),
span_id=int(self.example_span_id, 16),
is_remote=False,
),
attributes={},
)
too_many_links = [link] * (MAX_NUM_LINKS + 5)
self.assertEqual(
_extract_links(too_many_links),
ProtoSpan.Links(
link=[
{
"trace_id": self.example_trace_id,
"span_id": self.example_span_id,
"type": "TYPE_UNSPECIFIED",
"attributes": {},
}
]
* MAX_NUM_LINKS,
dropped_links_count=len(too_many_links) - MAX_NUM_LINKS,
),
)
def test_too_many_link_attributes(self):
link_attrs = {}
for attr_key in range(MAX_LINK_ATTRS + 1):
link_attrs[str(attr_key)] = 0
attr_link = Link(
context=SpanContext(
trace_id=int(self.example_trace_id, 16),
span_id=int(self.example_span_id, 16),
is_remote=False,
),
attributes=link_attrs,
)
proto_link = _extract_links([attr_link])
self.assertEqual(
len(proto_link.link[0].attributes.attribute_map), MAX_LINK_ATTRS
)
def test_extract_empty_resources(self):
self.assertEqual(
_extract_resources(Resource.get_empty()),
{},
)
def test_extract_resource_attributes_with_regex(self):
resource_regex = re.compile(r"service\..*")
resource = Resource(
attributes={
"cloud.account.id": "123",
"cloud.availability_zone": "us-east4-b",
"cloud.platform": "gcp_compute_engine",
"cloud.provider": "gcp",
"cloud.region": "us-east4",
"host.id": "host",
"host.name": "fakeName",
"host.type": "fakeMachineType",
"service.name": "my-app",
"service.version": "1",
}
)
expected_extract = {
"g.co/r/gce_instance/instance_id": "host",
"g.co/r/gce_instance/zone": "us-east4-b",
"service.name": "my-app",
"service.version": "1",
}
self.assertEqual(
_extract_resources(resource, resource_regex), expected_extract
)
def test_non_matching_regex(self):
resource_regex = re.compile(r"this-regex-matches-nothing")
resource = Resource(
attributes={
"cloud.account.id": "123",
"cloud.availability_zone": "us-east4-b",
"cloud.platform": "gcp_compute_engine",
"cloud.provider": "gcp",
"cloud.region": "us-east4",
"host.id": "host",
"host.name": "fakeName",
"host.type": "fakeMachineType",
}
)
expected_extract = {
"g.co/r/gce_instance/instance_id": "host",
"g.co/r/gce_instance/zone": "us-east4-b",
}
self.assertEqual(
_extract_resources(resource, resource_regex), expected_extract
)
def test_extract_well_formed_resources(self):
resource = Resource(
attributes={
"cloud.account.id": "123",
"cloud.availability_zone": "us-east4-b",
"cloud.platform": "gcp_compute_engine",
"cloud.provider": "gcp",
"cloud.region": "us-east4",
"host.id": "host",
"host.name": "fakeName",
"host.type": "fakeMachineType",
}
)
expected_extract = {
"g.co/r/gce_instance/instance_id": "host",
"g.co/r/gce_instance/zone": "us-east4-b",
}
self.assertEqual(_extract_resources(resource), expected_extract)
def test_extract_unsupported_gcp_resources(self):
# Unsupported gcp resources will be ignored
resource = Resource(
attributes={
"cloud.account.id": "123",
"host.id": "host",
"extra_info": "extra",
"not_gcp_resource": "value",
"cloud.platform": "gcp_some_unsupported_thing",
"cloud.provider": "gcp",
}
)
self.assertEqual(
_extract_resources(resource),
{},
)
def test_truncate_string(self):
"""Cloud Trace API imposes limits on the length of many things,
e.g. strings, number of events, number of attributes. We truncate
these things before sending it to the API as an optimization.
"""
self.assertEqual(_truncate_str("aaaa", limit=1), ("a", 3))
self.assertEqual(_truncate_str("aaaa", limit=5), ("aaaa", 0))
self.assertEqual(_truncate_str("aaaa", limit=4), ("aaaa", 0))
self.assertEqual(_truncate_str("中文翻译", limit=4), ("中", 9))
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"))
# pylint: disable=no-member
def test_extract_span_kind(self):
self.assertEqual(
_extract_span_kind(SpanKind.INTERNAL), ProtoSpan.SpanKind.INTERNAL
)
self.assertEqual(
_extract_span_kind(SpanKind.CLIENT), ProtoSpan.SpanKind.CLIENT
)
self.assertEqual(
_extract_span_kind(SpanKind.SERVER), ProtoSpan.SpanKind.SERVER
)
self.assertEqual(
_extract_span_kind(SpanKind.CONSUMER), ProtoSpan.SpanKind.CONSUMER
)
self.assertEqual(
_extract_span_kind(SpanKind.PRODUCER), ProtoSpan.SpanKind.PRODUCER
)
self.assertEqual(
_extract_span_kind(-1), ProtoSpan.SpanKind.SPAN_KIND_UNSPECIFIED
)