In the documentation on how to use opencensus-python
to submit traces to Azure Application Insights, it's spelled out how to add additional information to the customDimensions
field. That is,
import logging
from opencensus.ext.azure.log_exporter import AzureLogHandler
logger = logging.getLogger(__name__)
logger.addHandler(AzureLogHandler(
connection_string='InstrumentationKey=00000000-0000-0000-0000-000000000000')
)
logger.error('blooh')
logger.error('blooh2', extra={'custom_dimensions': {'woot': 42}})
becomes
in the Application Insights UI.
That's all well and good, but what is the intended way to remove the items from customDimensions
that are included by default; i.e. things like fileName
and process
?
By inspection of the source code, the properties do seem rather hard to avoid to create, but it is possible to remove them by post-processing the envelope
:
import logging
from opencensus.ext.azure.log_exporter import AzureLogHandler
custom_dimensions = {'foo': 'bar'}
def remove_items(envelope):
envelope.data.baseData.properties = custom_dimensions
return True
logger = logging.getLogger(__name__)
handler = AzureLogHandler(connection_string='InstrumentationKey=00000000-0000-0000-0000-000000000000')
handler.add_telemetry_processor(remove_items)
logger.addHandler(handler)
logger.error('blooh')
This is tested and works in opencensus-ext-azure
version 1.0.5.
Notice also that with this approarch, it is no longer necessary to specify the extra
when logging.