Skip to content
This repository was archived by the owner on Sep 17, 2025. It is now read-only.

Commit f0064d8

Browse files
authored
Refactor Django/Pyramid configuration (#624)
refactor Pyramid config decouple exporter logic from Django extension use tracecontext as the default propagator
1 parent d67b206 commit f0064d8

File tree

20 files changed

+188
-758
lines changed

20 files changed

+188
-758
lines changed

README.rst

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -143,8 +143,9 @@ Propagators
143143
~~~~~~~~~~~
144144

145145
You can specify the propagator type for serializing and deserializing the
146-
``SpanContext`` and its headers. There are currently three built in propagators:
147-
``GoogleCloudFormatPropagator``, ``TextFormatPropagator`` and ``TraceContextPropagator``.
146+
``SpanContext`` and its headers. The default propagator is
147+
``TraceContextPropagator``, the rest options are ``BinaryFormatPropagator``,
148+
``GoogleCloudFormatPropagator`` and ``TextFormatPropagator``.
148149

149150
This example shows how to use the ``GoogleCloudFormatPropagator``:
150151

@@ -195,13 +196,15 @@ for a Flask application:
195196
blacklist_paths = ['_ah/health']
196197
middleware = FlaskMiddleware(app, blacklist_paths=blacklist_paths)
197198
198-
For Django, you can configure the blacklist in the ``OPENCENSUS_TRACE_PARAMS`` in ``settings.py``:
199+
For Django, you can configure the blacklist in the ``OPENCENSUS`` in ``settings.py``:
199200

200201
.. code:: python
201202
202-
OPENCENSUS_TRACE_PARAMS: {
203-
...
204-
'BLACKLIST_PATHS': ['_ah/health',],
203+
OPENCENSUS: {
204+
'TRACE': {
205+
...
206+
'BLACKLIST_PATHS': ['_ah/health',],
207+
}
205208
}
206209
207210

contrib/opencensus-ext-azure/examples/client.py

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,16 +16,11 @@
1616

1717
from opencensus.ext.azure.trace_exporter import AzureExporter
1818
from opencensus.trace import config_integration
19-
from opencensus.trace.propagation.trace_context_http_header_format \
20-
import TraceContextPropagator
2119
from opencensus.trace.tracer import Tracer
2220

2321
if __name__ == '__main__':
2422
config_integration.trace_integrations(['requests'])
25-
tracer = Tracer(
26-
propagator=TraceContextPropagator(),
27-
exporter=AzureExporter(),
28-
)
23+
tracer = Tracer(exporter=AzureExporter())
2924
with tracer.span(name='parent'):
3025
with tracer.span(name='child'):
3126
response = requests.get(url='http://localhost:8080/')

contrib/opencensus-ext-django/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# Changelog
22

33
## Unreleased
4+
- Decoupled exporter specific logic from configuration
45

56
## 0.2.0
67
Released 2019-04-08

contrib/opencensus-ext-django/README.rst

Lines changed: 10 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -35,29 +35,17 @@ And add this line to the ``INSTALLED_APPS`` section:
3535
'opencensus.ext.django',
3636
]
3737
38-
You can configure the sampler, exporter, propagator using the ``OPENCENSUS_TRACE`` setting in
39-
``settings.py``:
38+
Additional configuration can be provided, please read
39+
`Customization <https://github.com/census-instrumentation/opencensus-python#customization>`_
40+
for a complete reference.
4041

4142
.. code:: python
4243
43-
OPENCENSUS_TRACE = {
44-
'SAMPLER': 'opencensus.trace.samplers.probability.ProbabilitySampler',
45-
'REPORTER': 'opencensus.trace.print_exporter.PrintExporter',
46-
'PROPAGATOR': 'opencensus.trace.propagation.google_cloud_format.'
47-
'GoogleCloudFormatPropagator',
48-
}
49-
50-
You can configure the sampling rate and other parameters using the ``OPENCENSUS_TRACE_PARAMS``
51-
setting in ``settings.py``:
52-
53-
.. code:: python
54-
55-
OPENCENSUS_TRACE_PARAMS = {
56-
'BLACKLIST_PATHS': ['/_ah/health'],
57-
'GCP_EXPORTER_PROJECT': None,
58-
'SAMPLING_RATE': 0.5,
59-
'SERVICE_NAME': 'my_service',
60-
'ZIPKIN_EXPORTER_HOST_NAME': 'localhost',
61-
'ZIPKIN_EXPORTER_PORT': 9411,
62-
'ZIPKIN_EXPORTER_PROTOCOL': 'http',
44+
OPENCENSUS = {
45+
'TRACE': {
46+
'SAMPLER': 'opencensus.trace.samplers.ProbabilitySampler(rate=1)',
47+
'EXPORTER': '''opencensus.ext.ocagent.trace_exporter.TraceExporter(
48+
service_name='foobar',
49+
)''',
50+
}
6351
}

contrib/opencensus-ext-django/examples/app/settings.py

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -64,18 +64,13 @@
6464
},
6565
]
6666

67-
OPENCENSUS_TRACE = {
68-
'SAMPLER':
69-
'opencensus.trace.samplers.always_on.AlwaysOnSampler',
70-
'EXPORTER':
71-
'opencensus.ext.stackdriver.trace_exporter.StackdriverExporter',
72-
'PROPAGATOR':
73-
'opencensus.trace.propagation.google_cloud_format.'
74-
'GoogleCloudFormatPropagator',
75-
}
76-
77-
OPENCENSUS_TRACE_PARAMS = {
78-
'SAMPLING_RATE': 0.5,
67+
OPENCENSUS = {
68+
'TRACE': {
69+
'SAMPLER': 'opencensus.trace.samplers.ProbabilitySampler(rate=0.5)',
70+
'EXPORTER': '''opencensus.ext.ocagent.trace_exporter.TraceExporter(
71+
service_name='foobar',
72+
)''',
73+
}
7974
}
8075

8176
# Internationalization

contrib/opencensus-ext-django/opencensus/ext/django/config.py

Lines changed: 0 additions & 115 deletions
This file was deleted.

0 commit comments

Comments
 (0)