opencensus-python
opencensus-python copied to clipboard
Azure exporter with Django integration using Gunicorn not working
Using Python 3.5 Django 2.2.16 opencensus-ext-django 0.7.2 opencensus-ext-azure 1.0.4 gunicorn 20.0.4
on Ubuntu 16.04 using Postgresql 9.6
I have in Django settings:
from opencensus.ext.azure.trace_exporter import AzureExporter
OPENCENSUS = {
'TRACE': {
'SAMPLER': 'opencensus.trace.samplers.AlwaysOnSampler()',
'EXPORTER': AzureExporter(connection_string="InstrumentationKey=<key value here>"),
}
}
With the middleware "opencensus.ext.django.middleware.OpencensusMiddleware"
When running via manage runserver
I get data in Azure, only request data no database query tracing.
However, when I run via gunicorn I get no data in Azure.
I have tried replacing the Exporter to the PrintExporter, and this does indeed print data to the console, both Request and Database. If I set the number of threads for gunicorn (uses gthread worker) via --threads 4
then Database traces don't work, but requests still do.
I tried extending the Azure exporter to write data to disk, and that gets Request and Database data into Azure while not having threads for gunicorn (uses sync worker)
class AzureAbuseExporter(AzureExporter):
def export(self, items):
envelopes = [self.span_data_to_envelope(sd) for sd in items]
envelopes = self.apply_telemetry_processors(envelopes)
self.storage.put(envelopes)
I do not believe this to really be a solution for production, as it creates thousands of files.
When running via manage runserver I get data in Azure, only request data no database query tracing.
To trace requests to the postgresql
database, you must instrument with the postgresql instrumentation.
If I set the number of threads for gunicorn (uses gthread worker) via --threads 4 then Database traces don't work, but requests still do.
When you say "requests still do", does that mean you are seeing request telemetry in Azure monitor? Or are you seeing requests working for the print exporter?
To trace requests to the
postgresql
database, you must instrument with the postgresql instrumentation.
I believe what I am referring to is the "dependency", opencensus-ext-django adds tracing to outgoing database calls. I may not have the terminology correct here.
When you say "requests still do", does that mean you are seeing request telemetry in Azure monitor? Or are you seeing requests working for the print exporter?
I was not able to get telemetry in Azure at all using AzureExporter, this was with PrintExporter.
I get data in Azure, only request data no database query tracing.
So you are NOT getting database query tracing with just manage runserver
?
If I set the number of threads for gunicorn (uses gthread worker) via --threads 4 then Database traces don't work, but requests still do.
You are still able to see requests telemetry? Do you have some sample code so we can see where the requests are being called and where the database calls are?