How to filter out Tracer spans in application insights
I have added few TRACER spans in my code. Currently few of them are INPROC.
with TRACER.span(name='func1'):
retval= func1()
with TRACER.span(name='func2'):
retval= func2()
I can see telemetry being added to dependency logs in application insights. But both of them are of type="INPROC"
I was not able to filter out logs with span name func1 or func2? Is there a way to identity dependency logs with span name?
Dependencies should have the span name in the "target" field in Application Insights, whether they are INPROC or not.
I can see dependencies with target=INPROC. But if we have two dependencies with different span names and both are INPROC, then how those can be differentiated?
@anandchugh
I don't think the "target" field should be INPROC. That should be the name of the span. The "type" field in Application Insights should be INPROC. To answer your question, for a specific telemetry using w3c (which is what OpenCensus uses), the uniqueness is defined by what trace the span belongs to (traceId) and the actual span (spanId). TraceId maps to operationId and spanId maps to id in Application Insights.
@lzchen yes its "type" filed which contains "INPROC" value Created a small test flask app for this
from flask import Flask
import logging
import requests
import sys
from opencensus.ext.azure.log_exporter import AzureLogHandler
from opencensus.ext.azure.trace_exporter import AzureExporter
from opencensus.trace import config_integration
from opencensus.trace.samplers import ProbabilitySampler, AlwaysOnSampler
from opencensus.trace.tracer import Tracer
from opencensus.ext.flask.flask_middleware import FlaskMiddleware
APP_NAME = "TracingApp"
def callback_addRoleName(envelope):
envelope.data.baseData.name = APP_NAME
envelope.tags['ai.cloud.role'] = APP_NAME
return True
aiConnStr= 'InstrumentationKey=xxx'
azureExporter = AzureExporter(
connection_string=aiConnStr
)
azureExporter.add_telemetry_processor(callback_addRoleName)
app = Flask(APP_NAME)
middleware = FlaskMiddleware(
app,
exporter=azureExporter,
sampler=AlwaysOnSampler(),
)
config_integration.trace_integrations(['requests','logging'])
tracer = Tracer(exporter=azureExporter, sampler=AlwaysOnSampler())
logger = logging.getLogger(APP_NAME)
handler = AzureLogHandler(connection_string=aiConnStr)
handler.add_telemetry_processor(callback_addRoleName)
logger.setLevel(logging.INFO)
logger.addHandler(handler)
@app.route('/')
def hello():
logger.info('Before the span -outlook ')
with tracer.span(name='outlook'):
response = requests.get(url='http://outlook.com')
logger.info('After the span -outlook ')
logger.info('Before the span -testfunc_1 ')
with tracer.span(name='testfunc_1'):
testfunc_1()
logger.warning('After the span -testfunc_1')
logger.info('Before the span -testfunc_2 ')
with tracer.span(name='testfunc_2'):
testfunc_2()
logger.warning('After the span -testfunc_2')
return 'Hello'
def testfunc_1():
for x in range(0, 1000):
print(f"Number is {x}")
def testfunc_2():
for x in range(2000, 3000):
print(f"Number is {x}")
if __name__ == "__main__":
app.run(host ='0.0.0.0', port = 5001, debug = True)
In application insights, I can see these in dependency table. I can see target=TracingApp and type=INPROC but not able to see anywhere spanname(testfunc_1 or testfunc_2)

Is it possible to add a feature to log span names as it can be helpful in analyzing performance of each span.
The span names are already logged, they are supposed to be the "name" field.
It looks like you are rewriting all your telemetry sent from AzureExporter names with "TracingApp" in callback_addRoleName
envelope.data.baseData.name = APP_NAME