Skip to content

Commit

Permalink
rpc (#20563)
Browse files Browse the repository at this point in the history
  • Loading branch information
lzchen authored and iscai-msft committed Sep 29, 2021
1 parent ba63b3d commit cf8f6e5
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ def _convert_span_to_envelope(span: Span) -> TelemetryItem:
envelope.tags["ai.operation.id"] = "{:032x}".format(span.context.trace_id)
if "enduser.id" in span.attributes:
envelope.tags["ai.user.id"] = span.attributes["enduser.id"]
if span.parent:
if span.parent and span.parent.span_id:
envelope.tags["ai.operation.parentId"] = "{:016x}".format(
span.parent.span_id
)
Expand Down Expand Up @@ -314,8 +314,7 @@ def _convert_span_to_envelope(span: Span) -> TelemetryItem:
elif "rpc.system" in span.attributes: # Rpc
data.type = "rpc.system"
# TODO: data.data for rpc
# rpc specific logic for target
if "peer.service" not in span.attributes:
if target is None:
target = span.attributes["rpc.system"]
else:
# TODO: Azure specific types
Expand All @@ -325,7 +324,8 @@ def _convert_span_to_envelope(span: Span) -> TelemetryItem:
# TODO: data.data for messaging
# TODO: Special logic for data.target for messaging?
else: # SpanKind.INTERNAL
data.type = "InProc"
if span.parent:
data.type = "InProc"
data.success = True
# Apply truncation
if data.result_code:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -401,6 +401,7 @@ def test_span_to_envelope_client_rpc(self):
is_remote=False,
),
attributes={
"peer.service": "service",
"rpc.system": "rpc",
"rpc.service": "Test service",
},
Expand All @@ -422,7 +423,16 @@ def test_span_to_envelope_client_rpc(self):

self.assertEqual(envelope.data.base_type, "RemoteDependencyData")
self.assertEqual(envelope.data.base_data.type, "rpc.system")
self.assertEqual(envelope.data.base_data.target, "service")

# target
span._attributes = {
"rpc.system": "rpc",
"rpc.service": "Test service",
}
envelope = exporter._span_to_envelope(span)
self.assertEqual(envelope.data.base_data.target, "rpc")

# TODO: data.data
# self.assertEqual(envelope.data.base_data.data, "SELECT")
self.assertEqual(envelope.data.base_data.result_code, "1")
Expand Down Expand Up @@ -475,13 +485,15 @@ def test_span_to_envelope_internal(self):
end_time = start_time + 1001000000

# SpanKind.INTERNAL
span = trace._Span(
name="test",
context=SpanContext(
context = SpanContext(
trace_id=36873507687745823477771305566750195431,
span_id=12030755672171557337,
is_remote=False,
),
)
span = trace._Span(
name="test",
context=context,
parent=context,
attributes={},
kind=SpanKind.INTERNAL,
)
Expand All @@ -503,6 +515,11 @@ def test_span_to_envelope_internal(self):
self.assertEqual(envelope.data.base_data.type, "InProc")
self.assertEqual(envelope.data.base_data.result_code, "1")

# type
span._parent = None
envelope = exporter._span_to_envelope(span)
self.assertIsNone(envelope.data.base_data.type)

def test_span_envelope_server_http(self):
exporter = self._exporter
start_time = 1575494316027613500
Expand Down

0 comments on commit cf8f6e5

Please sign in to comment.