Skip to content

Commit

Permalink
Update span interface usage (#324)
Browse files Browse the repository at this point in the history
  • Loading branch information
alrex authored Feb 9, 2021
1 parent 499899a commit 0fe9096
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -259,10 +259,14 @@ def _get_origin(span):

def _get_sampling_rate(span):
ctx = span.get_span_context()
tracer_provider = trace_api.get_tracer_provider()
if not hasattr(tracer_provider, "sampler"):
return None
sampler = tracer_provider.sampler
return (
span.sampler.rate
sampler.rate
if ctx.trace_flags.sampled
and isinstance(span.sampler, sampling.TraceIdRatioBased)
and isinstance(sampler, sampling.TraceIdRatioBased)
else None
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -580,11 +580,11 @@ def test_sampling_rate(self):
is_remote=False,
trace_flags=trace_api.TraceFlags(trace_api.TraceFlags.SAMPLED),
)
sampler = sampling.TraceIdRatioBased(0.5)

span = trace._Span(
name="sampled", context=context, parent=None, sampler=sampler
trace_api.get_tracer_provider().sampler = sampling.TraceIdRatioBased(
0.5
)

span = trace._Span(name="sampled", context=context, parent=None)
span.start()
span.end()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -201,12 +201,12 @@ def test_sqs_client(self):
self.assertEqual(len(spans), 1)
actual = span.attributes
self.assertRegex(actual["aws.request_id"], r"[A-Z0-9]{52}")
del actual["aws.request_id"]
self.assertEqual(
actual,
{
"aws.operation": "ListQueues",
"aws.region": "us-east-1",
"aws.request_id": actual["aws.request_id"],
"aws.service": "sqs",
"retry_attempts": 0,
"http.status_code": 200,
Expand All @@ -232,12 +232,12 @@ def test_sqs_send_message(self):
self.assertRegex(
create_queue_attributes["aws.request_id"], r"[A-Z0-9]{52}"
)
del create_queue_attributes["aws.request_id"]
self.assertEqual(
create_queue_attributes,
{
"aws.operation": "CreateQueue",
"aws.region": "us-east-1",
"aws.request_id": create_queue_attributes["aws.request_id"],
"aws.service": "sqs",
"retry_attempts": 0,
"http.status_code": 200,
Expand All @@ -247,13 +247,13 @@ def test_sqs_send_message(self):
self.assertRegex(
send_msg_attributes["aws.request_id"], r"[A-Z0-9]{52}"
)
del send_msg_attributes["aws.request_id"]
self.assertEqual(
send_msg_attributes,
{
"aws.operation": "SendMessage",
"aws.queue_url": response["QueueUrl"],
"aws.region": "us-east-1",
"aws.request_id": send_msg_attributes["aws.request_id"],
"aws.service": "sqs",
"retry_attempts": 0,
"http.status_code": 200,
Expand Down Expand Up @@ -468,13 +468,13 @@ def test_dynamodb_client(self):
self.assertRegex(
create_table_attributes["aws.request_id"], r"[A-Z0-9]{52}"
)
del create_table_attributes["aws.request_id"]
self.assertEqual(
create_table_attributes,
{
"aws.operation": "CreateTable",
"aws.region": "us-west-2",
"aws.service": "dynamodb",
"aws.request_id": create_table_attributes["aws.request_id"],
"aws.table_name": "test_table_name",
"retry_attempts": 0,
"http.status_code": 200,
Expand All @@ -484,12 +484,12 @@ def test_dynamodb_client(self):
self.assertRegex(
put_item_attributes["aws.request_id"], r"[A-Z0-9]{52}"
)
del put_item_attributes["aws.request_id"]
self.assertEqual(
put_item_attributes,
{
"aws.operation": "PutItem",
"aws.region": "us-west-2",
"aws.request_id": put_item_attributes["aws.request_id"],
"aws.service": "dynamodb",
"aws.table_name": "test_table_name",
"retry_attempts": 0,
Expand All @@ -500,12 +500,12 @@ def test_dynamodb_client(self):
self.assertRegex(
get_item_attributes["aws.request_id"], r"[A-Z0-9]{52}"
)
del get_item_attributes["aws.request_id"]
self.assertEqual(
get_item_attributes,
{
"aws.operation": "GetItem",
"aws.region": "us-west-2",
"aws.request_id": get_item_attributes["aws.request_id"],
"aws.service": "dynamodb",
"aws.table_name": "test_table_name",
"retry_attempts": 0,
Expand Down

0 comments on commit 0fe9096

Please sign in to comment.