mirror of
https://github.com/open-telemetry/opentelemetry-python-contrib.git
synced 2025-08-02 11:31:52 +08:00
Update span interface usage (#324)
This commit is contained in:
@ -259,10 +259,14 @@ def _get_origin(span):
|
|||||||
|
|
||||||
def _get_sampling_rate(span):
|
def _get_sampling_rate(span):
|
||||||
ctx = span.get_span_context()
|
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 (
|
return (
|
||||||
span.sampler.rate
|
sampler.rate
|
||||||
if ctx.trace_flags.sampled
|
if ctx.trace_flags.sampled
|
||||||
and isinstance(span.sampler, sampling.TraceIdRatioBased)
|
and isinstance(sampler, sampling.TraceIdRatioBased)
|
||||||
else None
|
else None
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -580,11 +580,11 @@ class TestDatadogSpanExporter(unittest.TestCase):
|
|||||||
is_remote=False,
|
is_remote=False,
|
||||||
trace_flags=trace_api.TraceFlags(trace_api.TraceFlags.SAMPLED),
|
trace_flags=trace_api.TraceFlags(trace_api.TraceFlags.SAMPLED),
|
||||||
)
|
)
|
||||||
sampler = sampling.TraceIdRatioBased(0.5)
|
trace_api.get_tracer_provider().sampler = sampling.TraceIdRatioBased(
|
||||||
|
0.5
|
||||||
span = trace._Span(
|
|
||||||
name="sampled", context=context, parent=None, sampler=sampler
|
|
||||||
)
|
)
|
||||||
|
|
||||||
|
span = trace._Span(name="sampled", context=context, parent=None)
|
||||||
span.start()
|
span.start()
|
||||||
span.end()
|
span.end()
|
||||||
|
|
||||||
|
@ -201,12 +201,12 @@ class TestBotocoreInstrumentor(TestBase):
|
|||||||
self.assertEqual(len(spans), 1)
|
self.assertEqual(len(spans), 1)
|
||||||
actual = span.attributes
|
actual = span.attributes
|
||||||
self.assertRegex(actual["aws.request_id"], r"[A-Z0-9]{52}")
|
self.assertRegex(actual["aws.request_id"], r"[A-Z0-9]{52}")
|
||||||
del actual["aws.request_id"]
|
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
actual,
|
actual,
|
||||||
{
|
{
|
||||||
"aws.operation": "ListQueues",
|
"aws.operation": "ListQueues",
|
||||||
"aws.region": "us-east-1",
|
"aws.region": "us-east-1",
|
||||||
|
"aws.request_id": actual["aws.request_id"],
|
||||||
"aws.service": "sqs",
|
"aws.service": "sqs",
|
||||||
"retry_attempts": 0,
|
"retry_attempts": 0,
|
||||||
"http.status_code": 200,
|
"http.status_code": 200,
|
||||||
@ -232,12 +232,12 @@ class TestBotocoreInstrumentor(TestBase):
|
|||||||
self.assertRegex(
|
self.assertRegex(
|
||||||
create_queue_attributes["aws.request_id"], r"[A-Z0-9]{52}"
|
create_queue_attributes["aws.request_id"], r"[A-Z0-9]{52}"
|
||||||
)
|
)
|
||||||
del create_queue_attributes["aws.request_id"]
|
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
create_queue_attributes,
|
create_queue_attributes,
|
||||||
{
|
{
|
||||||
"aws.operation": "CreateQueue",
|
"aws.operation": "CreateQueue",
|
||||||
"aws.region": "us-east-1",
|
"aws.region": "us-east-1",
|
||||||
|
"aws.request_id": create_queue_attributes["aws.request_id"],
|
||||||
"aws.service": "sqs",
|
"aws.service": "sqs",
|
||||||
"retry_attempts": 0,
|
"retry_attempts": 0,
|
||||||
"http.status_code": 200,
|
"http.status_code": 200,
|
||||||
@ -247,13 +247,13 @@ class TestBotocoreInstrumentor(TestBase):
|
|||||||
self.assertRegex(
|
self.assertRegex(
|
||||||
send_msg_attributes["aws.request_id"], r"[A-Z0-9]{52}"
|
send_msg_attributes["aws.request_id"], r"[A-Z0-9]{52}"
|
||||||
)
|
)
|
||||||
del send_msg_attributes["aws.request_id"]
|
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
send_msg_attributes,
|
send_msg_attributes,
|
||||||
{
|
{
|
||||||
"aws.operation": "SendMessage",
|
"aws.operation": "SendMessage",
|
||||||
"aws.queue_url": response["QueueUrl"],
|
"aws.queue_url": response["QueueUrl"],
|
||||||
"aws.region": "us-east-1",
|
"aws.region": "us-east-1",
|
||||||
|
"aws.request_id": send_msg_attributes["aws.request_id"],
|
||||||
"aws.service": "sqs",
|
"aws.service": "sqs",
|
||||||
"retry_attempts": 0,
|
"retry_attempts": 0,
|
||||||
"http.status_code": 200,
|
"http.status_code": 200,
|
||||||
@ -468,13 +468,13 @@ class TestBotocoreInstrumentor(TestBase):
|
|||||||
self.assertRegex(
|
self.assertRegex(
|
||||||
create_table_attributes["aws.request_id"], r"[A-Z0-9]{52}"
|
create_table_attributes["aws.request_id"], r"[A-Z0-9]{52}"
|
||||||
)
|
)
|
||||||
del create_table_attributes["aws.request_id"]
|
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
create_table_attributes,
|
create_table_attributes,
|
||||||
{
|
{
|
||||||
"aws.operation": "CreateTable",
|
"aws.operation": "CreateTable",
|
||||||
"aws.region": "us-west-2",
|
"aws.region": "us-west-2",
|
||||||
"aws.service": "dynamodb",
|
"aws.service": "dynamodb",
|
||||||
|
"aws.request_id": create_table_attributes["aws.request_id"],
|
||||||
"aws.table_name": "test_table_name",
|
"aws.table_name": "test_table_name",
|
||||||
"retry_attempts": 0,
|
"retry_attempts": 0,
|
||||||
"http.status_code": 200,
|
"http.status_code": 200,
|
||||||
@ -484,12 +484,12 @@ class TestBotocoreInstrumentor(TestBase):
|
|||||||
self.assertRegex(
|
self.assertRegex(
|
||||||
put_item_attributes["aws.request_id"], r"[A-Z0-9]{52}"
|
put_item_attributes["aws.request_id"], r"[A-Z0-9]{52}"
|
||||||
)
|
)
|
||||||
del put_item_attributes["aws.request_id"]
|
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
put_item_attributes,
|
put_item_attributes,
|
||||||
{
|
{
|
||||||
"aws.operation": "PutItem",
|
"aws.operation": "PutItem",
|
||||||
"aws.region": "us-west-2",
|
"aws.region": "us-west-2",
|
||||||
|
"aws.request_id": put_item_attributes["aws.request_id"],
|
||||||
"aws.service": "dynamodb",
|
"aws.service": "dynamodb",
|
||||||
"aws.table_name": "test_table_name",
|
"aws.table_name": "test_table_name",
|
||||||
"retry_attempts": 0,
|
"retry_attempts": 0,
|
||||||
@ -500,12 +500,12 @@ class TestBotocoreInstrumentor(TestBase):
|
|||||||
self.assertRegex(
|
self.assertRegex(
|
||||||
get_item_attributes["aws.request_id"], r"[A-Z0-9]{52}"
|
get_item_attributes["aws.request_id"], r"[A-Z0-9]{52}"
|
||||||
)
|
)
|
||||||
del get_item_attributes["aws.request_id"]
|
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
get_item_attributes,
|
get_item_attributes,
|
||||||
{
|
{
|
||||||
"aws.operation": "GetItem",
|
"aws.operation": "GetItem",
|
||||||
"aws.region": "us-west-2",
|
"aws.region": "us-west-2",
|
||||||
|
"aws.request_id": get_item_attributes["aws.request_id"],
|
||||||
"aws.service": "dynamodb",
|
"aws.service": "dynamodb",
|
||||||
"aws.table_name": "test_table_name",
|
"aws.table_name": "test_table_name",
|
||||||
"retry_attempts": 0,
|
"retry_attempts": 0,
|
||||||
|
Reference in New Issue
Block a user