From f6dc521e19386fe6076e1ba425286b312019b604 Mon Sep 17 00:00:00 2001 From: Peter Giacomo Lombardo Date: Wed, 28 Nov 2018 13:03:35 +0100 Subject: [PATCH] Add recording of basic rpc span type --- instana/json_span.py | 15 +++++++++++++++ instana/recorder.py | 20 +++++++++++++++----- 2 files changed, 30 insertions(+), 5 deletions(-) diff --git a/instana/json_span.py b/instana/json_span.py index b927a349..83c57d46 100644 --- a/instana/json_span.py +++ b/instana/json_span.py @@ -31,6 +31,7 @@ class Data(object): http = None rabbitmq = None redis = None + rpc = None sdk = None service = None sqlalchemy = None @@ -86,6 +87,20 @@ def __init__(self, **kwds): self.__dict__.update(kwds) +class RPCData(object): + flavor = None + host = None + port = None + call = None + call_type = None + params = None + baggage = None + error = None + + def __init__(self, **kwds): + self.__dict__.update(kwds) + + class SQLAlchemyData(object): sql = None url = None diff --git a/instana/recorder.py b/instana/recorder.py index de9b941f..f73cd1fb 100644 --- a/instana/recorder.py +++ b/instana/recorder.py @@ -12,7 +12,7 @@ import instana.singletons from .json_span import (CustomData, Data, HttpData, JsonSpan, MySQLData, - RabbitmqData, RedisData, SDKData, SoapData, + RabbitmqData, RedisData, RPCData, SDKData, SoapData, SQLAlchemyData) from .log import logger @@ -124,6 +124,16 @@ def build_registered_span(self, span): error=span.tags.pop('redis.error', None), subCommands=span.tags.pop('subCommands', None)) + if span.operation_name == "rpc-client" or span.operation_name == "rpc-server": + data.rpc = RPCData(flavor=span.tags.pop('rpc.flavor', None), + host=span.tags.pop('rpc.host', None), + port=span.tags.pop('rpc.port', None), + call=span.tags.pop('rpc.call', None), + call_type=span.tags.pop('rpc.call_type', None), + params=span.tags.pop('rpc.params', None), + baggage=span.tags.pop('rpc.baggage', None), + error=span.tags.pop('rpc.error', None)) + if span.operation_name == "sqlalchemy": data.sqlalchemy = SQLAlchemyData(sql=span.tags.pop('sqlalchemy.sql', None), eng=span.tags.pop('sqlalchemy.eng', None), @@ -142,7 +152,7 @@ def build_registered_span(self, span): tskey = list(data.custom.logs.keys())[0] data.mysql.error = data.custom.logs[tskey]['message'] - entityFrom = {'e': instana.singletons.agent.from_.pid, + entity_from = {'e': instana.singletons.agent.from_.pid, 'h': instana.singletons.agent.from_.agentUuid} json_span = JsonSpan(n=span.operation_name, @@ -151,7 +161,7 @@ def build_registered_span(self, span): s=span.context.span_id, ts=int(round(span.start_time * 1000)), d=int(round(span.duration * 1000)), - f=entityFrom, + f=entity_from, data=data) if span.stack: @@ -182,7 +192,7 @@ def build_sdk_span(self, span): sdk_data.Type = self.get_span_kind(span) data = Data(service=self.get_service_name(span), sdk=sdk_data) - entityFrom = {'e': instana.singletons.agent.from_.pid, + entity_from = {'e': instana.singletons.agent.from_.pid, 'h': instana.singletons.agent.from_.agentUuid} json_span = JsonSpan( @@ -192,7 +202,7 @@ def build_sdk_span(self, span): ts=int(round(span.start_time * 1000)), d=int(round(span.duration * 1000)), n="sdk", - f=entityFrom, + f=entity_from, data=data) error = span.tags.pop("error", False)