1
- # Copyright 2019- 2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
1
+ # Copyright 2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
2
2
#
3
3
# Redistribution and use in source and binary forms, with or without
4
4
# modification, are permitted provided that the following conditions
28
28
29
29
sys .path .append ("../common" )
30
30
31
- import test_util as tu
32
- import unittest
33
31
import json
32
+ import unittest
33
+
34
+ import test_util as tu
35
+
34
36
35
37
class OpenTelemetryTest (tu .TestResultCollector ):
36
38
@@ -113,7 +115,10 @@ def _check_parent(self, child_span, parent_span):
113
115
# Check that child and parent span have the same trace_id
114
116
# and child's `parent_span_id` is the same as parent's `span_id`
115
117
self .assertEqual (child_span ['trace_id' ], parent_span ['trace_id' ])
116
- self .assertTrue ('parent_span_id' in child_span )
118
+ self .assertIn (
119
+ 'parent_span_id' ,
120
+ child_span ,
121
+ "child span does not have parent span id specified" )
117
122
self .assertEqual (child_span ['parent_span_id' ], parent_span ['span_id' ])
118
123
119
124
def test_spans (self ):
@@ -127,13 +132,13 @@ def test_spans(self):
127
132
128
133
# There should be 6 spans in total:
129
134
# 3 for http request and 3 for grpc request.
130
- self .assertTrue (len (self .spans ) == 6 )
135
+ self .assertEqual (len (self .spans ), 6 )
131
136
# We should have 2 compute spans
132
- self .assertTrue (parsed_spans .count ("compute" ), 2 )
137
+ self .assertEqual (parsed_spans .count ("compute" ), 2 )
133
138
# 2 request spans (named simple - same as our model name)
134
- self .assertTrue (parsed_spans .count (self .model_name ), 2 )
139
+ self .assertEqual (parsed_spans .count (self .model_name ), 2 )
135
140
# 2 root spans
136
- self .assertTrue (parsed_spans .count (self .root_span ), 2 )
141
+ self .assertEqual (parsed_spans .count (self .root_span ), 2 )
137
142
138
143
def test_nested_spans (self ):
139
144
@@ -146,15 +151,21 @@ def test_nested_spans(self):
146
151
self ._check_parent (child , parent )
147
152
148
153
# root_span should not have `parent_span_id` field
149
- self .assertFalse ('parent_span_id' in self .spans [2 ])
154
+ self .assertNotIn (
155
+ 'parent_span_id' ,
156
+ self .spans [2 ],
157
+ "root span has a parent_span_id specified" )
150
158
151
159
# Last 3 spans in `self.spans` belong to GRPC request
152
160
# Order of spans and their relationship described earlier
153
161
for child , parent in zip (self .spans [3 :], self .spans [4 :]):
154
162
self ._check_parent (child , parent )
155
163
156
164
# root_span should not have `parent_span_id` field
157
- self .assertFalse ('parent_span_id' in self .spans [5 ])
165
+ self .assertNotIn (
166
+ 'parent_span_id' ,
167
+ self .spans [5 ],
168
+ "root span has a parent_span_id specified" )
158
169
159
170
160
171
if __name__ == '__main__' :
0 commit comments