Skip to content

Commit

Permalink
More consistent assertion methods (#641)
Browse files Browse the repository at this point in the history
* More consistent assertion methods

* Updated core SHA
  • Loading branch information
owais authored Aug 30, 2021
1 parent d4668bc commit ffc2a2f
Show file tree
Hide file tree
Showing 17 changed files with 75 additions and 77 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ on:
- 'release/*'
pull_request:
env:
CORE_REPO_SHA: 3e1c89bcae77c34b9750a1f00608a04a97921c51
CORE_REPO_SHA: 9dc17e33bc083e38c1fd55b8ed6787caba8f54fe

jobs:
build:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ def test_instrumentor_connect(self):
span = spans_list[0]

# Check version and name in span's instrumentation info
self.check_span_instrumentation_info(
self.assertEqualSpanInstrumentationInfo(
span, opentelemetry.instrumentation.aiopg
)

Expand Down Expand Up @@ -97,7 +97,7 @@ async def _ctx_manager_connect():
span = spans_list[0]

# Check version and name in span's instrumentation info
self.check_span_instrumentation_info(
self.assertEqualSpanInstrumentationInfo(
span, opentelemetry.instrumentation.aiopg
)

Expand All @@ -118,7 +118,7 @@ def test_instrumentor_create_pool(self):
span = spans_list[0]

# Check version and name in span's instrumentation info
self.check_span_instrumentation_info(
self.assertEqualSpanInstrumentationInfo(
span, opentelemetry.instrumentation.aiopg
)

Expand Down Expand Up @@ -149,7 +149,7 @@ async def _ctx_manager_pool():
span = spans_list[0]

# Check version and name in span's instrumentation info
self.check_span_instrumentation_info(
self.assertEqualSpanInstrumentationInfo(
span, opentelemetry.instrumentation.aiopg
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,8 +132,8 @@ def test_s3_client(self):
assert spans
span = spans[0]
self.assertEqual(len(spans), 2)
self.assertEqual(
span.attributes,
self.assertSpanHasAttributes(
span,
{
"aws.operation": "ListBuckets",
"aws.region": "us-west-2",
Expand All @@ -150,8 +150,8 @@ def test_s3_client(self):
spans = self.memory_exporter.get_finished_spans()
assert spans
span = spans[2]
self.assertEqual(
span.attributes,
self.assertSpanHasAttributes(
span,
{
"aws.operation": "ListObjects",
"aws.region": "us-west-2",
Expand All @@ -175,9 +175,9 @@ def test_s3_put(self):
spans = self.memory_exporter.get_finished_spans()
assert spans
self.assertEqual(len(spans), 3)
create_bucket_attributes = spans[0].attributes
self.assertEqual(
create_bucket_attributes,
create_span = spans[0]
self.assertSpanHasAttributes(
create_span,
{
"aws.operation": "CreateBucket",
"aws.region": "us-west-2",
Expand All @@ -186,9 +186,9 @@ def test_s3_put(self):
SpanAttributes.HTTP_STATUS_CODE: 200,
},
)
put_object_attributes = spans[1].attributes
self.assertEqual(
put_object_attributes,
put_span = spans[1]
self.assertSpanHasAttributes(
put_span,
{
"aws.operation": "PutObject",
"aws.region": "us-west-2",
Expand All @@ -198,9 +198,9 @@ def test_s3_put(self):
},
)
self.assertTrue("params.Body" not in spans[1].attributes.keys())
get_object_attributes = spans[2].attributes
self.assertEqual(
get_object_attributes,
get_span = spans[2]
self.assertSpanHasAttributes(
get_span,
{
"aws.operation": "GetObject",
"aws.region": "us-west-2",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ def test_task(self):

self.assertEqual(consumer.name, "run/tests.celery_test_tasks.task_add")
self.assertEqual(consumer.kind, SpanKind.CONSUMER)
self.assert_span_has_attributes(
self.assertSpanHasAttributes(
consumer,
{
"celery.action": "run",
Expand All @@ -64,7 +64,7 @@ def test_task(self):
producer.name, "apply_async/tests.celery_test_tasks.task_add"
)
self.assertEqual(producer.kind, SpanKind.PRODUCER)
self.assert_span_has_attributes(
self.assertSpanHasAttributes(
producer,
{
"celery.action": "apply_async",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,8 @@ def test_instrumentor(self, request_mock):
span = spans_list[0]

# Check version and name in span's instrumentation info
# self.check_span_instrumentation_info(span, opentelemetry.instrumentation.elasticsearch)
self.check_span_instrumentation_info(
# self.assertEqualSpanInstrumentationInfo(span, opentelemetry.instrumentation.elasticsearch)
self.assertEqualSpanInstrumentationInfo(
span, opentelemetry.instrumentation.elasticsearch
)

Expand Down Expand Up @@ -289,7 +289,7 @@ def test_dsl_create(self, request_mock):
"elasticsearch.url": "/test-index",
"elasticsearch.method": "PUT",
}
self.assert_span_has_attributes(span2, attributes)
self.assertSpanHasAttributes(span2, attributes)
self.assertEqual(
literal_eval(span2.attributes[SpanAttributes.DB_STATEMENT]),
helpers.dsl_create_statement,
Expand All @@ -315,7 +315,7 @@ def test_dsl_index(self, request_mock):
"elasticsearch.url": helpers.dsl_index_url,
"elasticsearch.method": "PUT",
}
self.assert_span_has_attributes(span, attributes)
self.assertSpanHasAttributes(span, attributes)
self.assertEqual(
literal_eval(span.attributes[SpanAttributes.DB_STATEMENT]),
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ def _test_method(self, method):
span.name, "HelloWorldResource.on_{0}".format(method.lower())
)
self.assertEqual(span.status.status_code, StatusCode.UNSET)
self.assert_span_has_attributes(
self.assertSpanHasAttributes(
span,
{
SpanAttributes.HTTP_METHOD: method,
Expand All @@ -128,7 +128,7 @@ def test_404(self):
span = spans[0]
self.assertEqual(span.name, "HTTP GET")
self.assertEqual(span.status.status_code, StatusCode.ERROR)
self.assert_span_has_attributes(
self.assertSpanHasAttributes(
span,
{
SpanAttributes.HTTP_METHOD: "GET",
Expand Down Expand Up @@ -159,7 +159,7 @@ def test_500(self):
span.status.description,
"NameError: name 'non_existent_var' is not defined",
)
self.assert_span_has_attributes(
self.assertSpanHasAttributes(
span,
{
SpanAttributes.HTTP_METHOD: "GET",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ def client_response_hook(send_span, response):
response_spans = spans[:2]
for span in response_spans:
self.assertEqual(span.name, "name from response hook")
self.assert_span_has_attributes(
self.assertSpanHasAttributes(
span, {"attr-from-response-hook": "value"}
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ def test_unary_unary_future(self):
self.assertIs(span.kind, trace.SpanKind.CLIENT)

# Check version and name in span's instrumentation info
self.check_span_instrumentation_info(
self.assertEqualSpanInstrumentationInfo(
span, opentelemetry.instrumentation.grpc
)

Expand All @@ -126,11 +126,11 @@ def test_unary_unary(self):
self.assertIs(span.kind, trace.SpanKind.CLIENT)

# Check version and name in span's instrumentation info
self.check_span_instrumentation_info(
self.assertEqualSpanInstrumentationInfo(
span, opentelemetry.instrumentation.grpc
)

self.assert_span_has_attributes(
self.assertSpanHasAttributes(
span,
{
SpanAttributes.RPC_METHOD: "SimpleMethod",
Expand All @@ -152,11 +152,11 @@ def test_unary_stream(self):
self.assertIs(span.kind, trace.SpanKind.CLIENT)

# Check version and name in span's instrumentation info
self.check_span_instrumentation_info(
self.assertEqualSpanInstrumentationInfo(
span, opentelemetry.instrumentation.grpc
)

self.assert_span_has_attributes(
self.assertSpanHasAttributes(
span,
{
SpanAttributes.RPC_METHOD: "ServerStreamingMethod",
Expand All @@ -178,11 +178,11 @@ def test_stream_unary(self):
self.assertIs(span.kind, trace.SpanKind.CLIENT)

# Check version and name in span's instrumentation info
self.check_span_instrumentation_info(
self.assertEqualSpanInstrumentationInfo(
span, opentelemetry.instrumentation.grpc
)

self.assert_span_has_attributes(
self.assertSpanHasAttributes(
span,
{
SpanAttributes.RPC_METHOD: "ClientStreamingMethod",
Expand All @@ -206,11 +206,11 @@ def test_stream_stream(self):
self.assertIs(span.kind, trace.SpanKind.CLIENT)

# Check version and name in span's instrumentation info
self.check_span_instrumentation_info(
self.assertEqualSpanInstrumentationInfo(
span, opentelemetry.instrumentation.grpc
)

self.assert_span_has_attributes(
self.assertSpanHasAttributes(
span,
{
SpanAttributes.RPC_METHOD: "BidirectionalStreamingMethod",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,12 +106,12 @@ def handler(request, context):
self.assertIs(span.kind, trace.SpanKind.SERVER)

# Check version and name in span's instrumentation info
self.check_span_instrumentation_info(
self.assertEqualSpanInstrumentationInfo(
span, opentelemetry.instrumentation.grpc
)

# Check attributes
self.assert_span_has_attributes(
self.assertSpanHasAttributes(
span,
{
SpanAttributes.NET_PEER_IP: "[::1]",
Expand Down Expand Up @@ -187,12 +187,12 @@ def test_create_span(self):
self.assertIs(span.kind, trace.SpanKind.SERVER)

# Check version and name in span's instrumentation info
self.check_span_instrumentation_info(
self.assertEqualSpanInstrumentationInfo(
span, opentelemetry.instrumentation.grpc
)

# Check attributes
self.assert_span_has_attributes(
self.assertSpanHasAttributes(
span,
{
SpanAttributes.NET_PEER_IP: "[::1]",
Expand Down Expand Up @@ -257,12 +257,12 @@ def SimpleMethod(self, request, context):
self.assertIs(parent_span.kind, trace.SpanKind.SERVER)

# Check version and name in span's instrumentation info
self.check_span_instrumentation_info(
self.assertEqualSpanInstrumentationInfo(
parent_span, opentelemetry.instrumentation.grpc
)

# Check attributes
self.assert_span_has_attributes(
self.assertSpanHasAttributes(
parent_span,
{
SpanAttributes.NET_PEER_IP: "[::1]",
Expand Down Expand Up @@ -317,12 +317,12 @@ def test_create_span_streaming(self):
self.assertIs(span.kind, trace.SpanKind.SERVER)

# Check version and name in span's instrumentation info
self.check_span_instrumentation_info(
self.assertEqualSpanInstrumentationInfo(
span, opentelemetry.instrumentation.grpc
)

# Check attributes
self.assert_span_has_attributes(
self.assertSpanHasAttributes(
span,
{
SpanAttributes.NET_PEER_IP: "[::1]",
Expand Down Expand Up @@ -386,12 +386,12 @@ def ServerStreamingMethod(self, request, context):
self.assertIs(parent_span.kind, trace.SpanKind.SERVER)

# Check version and name in span's instrumentation info
self.check_span_instrumentation_info(
self.assertEqualSpanInstrumentationInfo(
parent_span, opentelemetry.instrumentation.grpc
)

# Check attributes
self.assert_span_has_attributes(
self.assertSpanHasAttributes(
parent_span,
{
SpanAttributes.NET_PEER_IP: "[::1]",
Expand Down Expand Up @@ -490,7 +490,7 @@ def handler(request, context):
self.assertIsNone(span2.parent)

# check attributes
self.assert_span_has_attributes(
self.assertSpanHasAttributes(
span,
{
SpanAttributes.NET_PEER_IP: "[::1]",
Expand Down Expand Up @@ -562,7 +562,7 @@ def handler(request, context):
self.assertIsNone(span2.parent)

# check attributes
self.assert_span_has_attributes(
self.assertSpanHasAttributes(
span,
{
SpanAttributes.NET_PEER_IP: "[::1]",
Expand Down Expand Up @@ -617,7 +617,7 @@ def handler(request, context):
self.assertIs(span.kind, trace.SpanKind.SERVER)

# Check version and name in span's instrumentation info
self.check_span_instrumentation_info(
self.assertEqualSpanInstrumentationInfo(
span, opentelemetry.instrumentation.grpc
)

Expand All @@ -631,7 +631,7 @@ def handler(request, context):
)

# Check attributes
self.assert_span_has_attributes(
self.assertSpanHasAttributes(
span,
{
SpanAttributes.NET_PEER_IP: "[::1]",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ def test_basic(self):

self.assertIs(span.status.status_code, trace.StatusCode.UNSET)

self.check_span_instrumentation_info(
self.assertEqualSpanInstrumentationInfo(
span, opentelemetry.instrumentation.httpx
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ def test_instrumentor(self, mock_connect):
span = spans_list[0]

# Check version and name in span's instrumentation info
self.check_span_instrumentation_info(
self.assertEqualSpanInstrumentationInfo(
span, opentelemetry.instrumentation.mysql
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ def test_instrumentor(self):
span = spans_list[0]

# Check version and name in span's instrumentation info
self.check_span_instrumentation_info(
self.assertEqualSpanInstrumentationInfo(
span, opentelemetry.instrumentation.psycopg2
)

Expand Down
Loading

0 comments on commit ffc2a2f

Please sign in to comment.