Skip to content

Commit a31fdbb

Browse files
committed
Merge branch 'master' into better-resource-detection
2 parents 6144ee0 + 16d3ab3 commit a31fdbb

File tree

266 files changed

+4143
-1673
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

266 files changed

+4143
-1673
lines changed

.coveragerc

+4
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ branch = True
33
omit =
44
*gen/jaeger*
55
*gen/opencensus*
6+
opencensus/__init__.py
7+
opencensus/common/__init__.py
68

79
[report]
810
fail_under = 100
@@ -15,3 +17,5 @@ exclude_lines =
1517
omit =
1618
*gen/jaeger*
1719
*gen/opencensus*
20+
opencensus/__init__.py
21+
opencensus/common/__init__.py

AUTHORS

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
Google Inc.
1+
OpenCensus Authors

CHANGELOG.md

+6
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,12 @@
66
Use `UnknownMetricFamily` for `SumData` instead of `UntypedMetricFamily`.
77
Check if label keys and values match before exporting.
88
- Remove min and max from Distribution.
9+
- Replace stackdriver `gke_container` resources, see the [GKE migration
10+
notes](https://cloud.google.com/monitoring/kubernetes-engine/migration#incompatible)
11+
for details
12+
- Componentize the package distribution. All [contrib
13+
packages](https://github.com/census-instrumentation/opencensus-python/tree/master/contrib/)
14+
are now decoupled from the core library, and can be released separately.
915

1016
## 0.2.0
1117
Released 2019-01-18

README.rst

+49-234
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,23 @@
1-
OpenCensus for Python - A stats collection and distributed tracing framework
2-
============================================================================
3-
4-
`Census`_ for Python. Census provides a framework to measure a server's resource
5-
usage and collect performance stats. This repository contains Python related
6-
utilities and supporting software needed by Census.
7-
8-
.. _Census: https://github.com/census-instrumentation
1+
OpenCensus - A stats collection and distributed tracing framework
2+
=================================================================
93

4+
|gitter|
105
|circleci|
6+
|pypi|
117

128
.. |circleci| image:: https://circleci.com/gh/census-instrumentation/opencensus-python.svg?style=shield
139
:target: https://circleci.com/gh/census-instrumentation/opencensus-python
10+
.. |gitter| image:: https://badges.gitter.im/census-instrumentation/lobby.svg
11+
:target: https://gitter.im/census-instrumentation/lobby?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge
12+
.. |pypi| image:: https://badge.fury.io/py/opencensus.svg
13+
:target: https://pypi.org/project/opencensus/
14+
15+
`OpenCensus`_ for Python. OpenCensus provides a framework to measure a
16+
server's resource usage and collect performance stats. This repository
17+
contains Python related utilities and supporting software needed by
18+
OpenCensus.
19+
20+
.. _OpenCensus: https://github.com/census-instrumentation
1421

1522
- `API Documentation`_
1623

@@ -74,7 +81,7 @@ You can collect traces using the ``Tracer`` `context manager`_:
7481
with tracer.span(name='span2') as span2:
7582
do_something_to_trace()
7683
77-
Census will collect everything within the ``with`` statement as a single span.
84+
OpenCensus will collect everything within the ``with`` statement as a single span.
7885

7986
Alternatively, you can explicitly start and end a span:
8087

@@ -120,7 +127,7 @@ the traces are printed to stdout in JSON format. Other options include
120127
writing to a file, sending to Python logging, or reporting to
121128
Stackdriver.
122129

123-
This example shows how to configure Census to save the traces to a
130+
This example shows how to configure OpenCensus to save the traces to a
124131
file:
125132

126133
.. code:: python
@@ -154,7 +161,7 @@ By default, traces are exported synchronously, which introduces latency during
154161
your code's execution. To avoid blocking code execution, you can initialize
155162
your exporter to use a background thread.
156163

157-
This example shows how to configure Census to use a background thread:
164+
This example shows how to configure OpenCensus to use a background thread:
158165

159166
.. code:: python
160167
@@ -235,230 +242,38 @@ For Django, you can configure the blacklist in the ``OPENCENSUS_TRACE_PARAMS`` i
235242
.. note:: By default, the health check path for the App Engine flexible environment is not traced,
236243
but you can turn it on by excluding it from the blacklist setting.
237244

238-
Framework Integration
239-
---------------------
240-
241-
Census supports integration with popular web frameworks including Django,
242-
Flask, and Pyramid. When the application receives a HTTP request, the tracer
243-
will automatically generate a span context using the trace information
244-
extracted from the request headers and propagated to the child spans.
245-
246-
Flask
247-
~~~~~
248-
249-
In your application, use the middleware to wrap your app and the
250-
requests will be automatically traced.
251-
252-
.. code:: python
253-
254-
from opencensus.trace.ext.flask.flask_middleware import FlaskMiddleware
255-
256-
app = flask.Flask(__name__)
257-
258-
# You can also specify the sampler, exporter, propagator in the middleware,
259-
# default is using `AlwaysOnSampler` as sampler, `PrintExporter` as exporter,
260-
# `GoogleCloudFormatPropagator` as propagator.
261-
middleware = FlaskMiddleware(app)
262-
263-
Django
264-
~~~~~~
265-
266-
For tracing Django requests, you will need to add the following line to
267-
the ``MIDDLEWARE_CLASSES`` section in the Django ``settings.py`` file.
268-
269-
.. code:: python
270-
271-
MIDDLEWARE_CLASSES = [
272-
...
273-
'opencensus.trace.ext.django.middleware.OpencensusMiddleware',
274-
]
275-
276-
And add this line to the ``INSTALLED_APPS`` section:
277-
278-
.. code:: python
279-
280-
INSTALLED_APPS = [
281-
...
282-
'opencensus.trace.ext.django',
283-
]
284-
285-
You can configure the sampler, exporter, propagator using the ``OPENCENSUS_TRACE`` setting in
286-
``settings.py``:
287-
288-
.. code:: python
289-
290-
OPENCENSUS_TRACE = {
291-
'SAMPLER': 'opencensus.trace.samplers.probability.ProbabilitySampler',
292-
'EXPORTER': 'opencensus.trace.exporters.print_exporter.PrintExporter',
293-
'PROPAGATOR': 'opencensus.trace.propagation.google_cloud_format.'
294-
'GoogleCloudFormatPropagator',
295-
}
296-
297-
You can configure the sampling rate and other parameters using the ``OPENCENSUS_TRACE_PARAMS``
298-
setting in ``settings.py``:
299-
300-
.. code:: python
301-
302-
OPENCENSUS_TRACE_PARAMS = {
303-
'BLACKLIST_PATHS': ['/_ah/health'],
304-
'GCP_EXPORTER_PROJECT': None,
305-
'SAMPLING_RATE': 0.5,
306-
'SERVICE_NAME': 'my_service',
307-
'ZIPKIN_EXPORTER_HOST_NAME': 'localhost',
308-
'ZIPKIN_EXPORTER_PORT': 9411,
309-
'ZIPKIN_EXPORTER_PROTOCOL': 'http',
310-
'JAEGER_EXPORTER_HOST_NAME': None,
311-
'JAEGER_EXPORTER_PORT': None,
312-
'JAEGER_EXPORTER_AGENT_HOST_NAME': 'localhost',
313-
'JAEGER_EXPORTER_AGENT_PORT': 6831
314-
}
315-
316-
317-
Pyramid
318-
~~~~~~~
319-
320-
In your application, add the pyramid tween and your requests will be
321-
traced.
322-
323-
.. code:: python
324-
325-
def main(global_config, **settings):
326-
config = Configurator(settings=settings)
327-
328-
config.add_tween('opencensus.trace.ext.pyramid'
329-
'.pyramid_middleware.OpenCensusTweenFactory')
330-
331-
To configure the sampler, exporter, and propagator, pass the instances
332-
into the pyramid settings
333-
334-
.. code:: python
335-
336-
from opencensus.trace.exporters import print_exporter
337-
from opencensus.trace.propagation import google_cloud_format
338-
from opencensus.trace.samplers import probability
339-
340-
settings = {}
341-
settings['OPENCENSUS_TRACE'] = {
342-
'EXPORTER': print_exporter.PrintExporter(),
343-
'SAMPLER': probability.ProbabilitySampler(rate=0.5),
344-
'PROPAGATOR': google_cloud_format.GoogleCloudFormatPropagator(),
345-
}
346-
347-
config = Configurator(settings=settings)
348-
349-
gRPC Integration
350-
----------------
351-
352-
OpenCensus provides the implementation of interceptors for both the client side
353-
and server side to instrument the gRPC requests and responses. The client
354-
interceptors are used to create a decorated channel that intercepts client
355-
gRPC calls and server interceptors act as decorators over handlers.
356-
357-
gRPC interceptor is a new feature in the grpcio1.8.0 release, please upgrade
358-
your grpcio to the latest version to use this feature.
359-
360-
For sample usage, please refer to the hello world example in the examples
361-
directory.
362-
363-
More information about the gRPC interceptors please see the `proposal`_.
364-
365-
.. _proposal: https://github.com/mehrdada/proposal/blob/python-interceptors/L13-Python-Interceptors.md
366-
367-
Service Integration
368-
-------------------
369-
370-
Opencensus supports integration with various popular outbound services such as
371-
SQL packages, Requests and Google Cloud client libraries. To enable integration
372-
services to census: you will need to pass the list of services to census:
373-
374-
.. code:: python
375-
376-
from opencensus.trace import config_integration
377-
from opencensus.trace import tracer as tracer_module
378-
379-
import mysql.connector
380-
381-
# Trace both mysql-connection and psycopg2
382-
integration = ['mysql', 'postgresql']
383-
384-
config_integration.trace_integrations(integration)
385-
386-
387-
MySQL
388-
~~~~~
389-
390-
The integration with MySQL supports the `mysql-connector`_ library and is specified
391-
to ``trace_integrations`` using ``'mysql'``.
392-
393-
.. _mysql-connector: https://pypi.org/project/mysql-connector
394-
395-
PostgreSQL
396-
~~~~~~~~~~
397-
398-
The integration with PostgreSQL supports the `psycopg2`_ library and is specified
399-
to ``trace_integrations`` using ``'postgresql'``.
400-
401-
.. _psycopg2: https://pypi.org/project/psycopg2
402-
403-
404-
SQLAlchemy
405-
~~~~~~~~~~
406-
407-
You can trace usage of the `sqlalchemy package`_, regardless of the underlying
408-
database, by specifying ``'sqlalchemy'`` to ``trace_integrations``.
409-
410-
.. _SQLAlchemy package: https://pypi.org/project/SQLAlchemy
411-
412-
.. note:: If you enable tracing of SQLAlchemy as well as the underlying database
413-
driver, you will get duplicate spans. Instead, just trace SQLAlchemy.
414-
415-
Requests
416-
~~~~~~~~
417-
418-
Census can trace HTTP requests made with the `Requests package`_. The request URL,
419-
method, and status will be collected.
420-
421-
You can enable Requests integration by specifying ``'requests'`` to ``trace_integrations``.
422-
423-
It's possible to configure a list of URL you don't want traced. By default the request to exporter
424-
won't be traced. It's configurable by giving an array of hostname/port to the attribute
425-
``blacklist_hostnames`` in OpenCensus context's attributes:
426-
427-
.. code:: python
428-
429-
execution_context.set_opencensus_attr('blacklist_hostnames',['hostname:port'])
430-
431-
Only the hostname must be specified if only the hostname is specified in the URL request.
432-
433-
.. _Requests package: https://pypi.python.org/pypi/requests
434-
435-
Httplib
436-
~~~~~~~~
437-
438-
Census can trace HTTP requests made with the httplib library.
439-
440-
You can enable Requests integration by specifying ``'httplib'`` to ``trace_integrations``.
441-
442-
It's possible to configure a list of URL you don't want traced. See requests integration
443-
for more information. The only difference is that you need to specify hostname and port
444-
every time.
445-
446-
Google Cloud Client Libraries
447-
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
448-
449-
Census can trace HTTP and gRPC requests made with the `Cloud client libraries`_.
450-
The request URL, method, and status will be collected.
451-
452-
You can enable Google Cloud client libraries integration by specifying ``'google_cloud_clientlibs'`` to ``trace_integrations``.
453-
454-
.. _Cloud client libraries: https://github.com/GoogleCloudPlatform/google-cloud-python#google-cloud-python-client
455-
456-
Threading
457-
~~~~~~~~~
458-
459-
Census can propagate trace across threads when using the Threading package.
245+
Integration
246+
-----------
460247

461-
You can enable Threading integration by specifying ``'threading'`` to ``trace_integrations``.
248+
OpenCensus supports integration with popular web frameworks, client libraries and built-in libraries.
249+
250+
- `Django`_
251+
- `Flask`_
252+
- `Google Cloud Client Libraries`_
253+
- `gRPC`_
254+
- `httplib`_
255+
- `MySQL`_
256+
- `PostgreSQL`_
257+
- `pymongo`_
258+
- `PyMySQL`_
259+
- `Pyramid`_
260+
- `requests`_
261+
- `SQLAlchemy`_
262+
- `threading`_
263+
264+
.. _Django: https://github.com/census-instrumentation/opencensus-python/tree/master/contrib/opencensus-ext-django
265+
.. _Flask: https://github.com/census-instrumentation/opencensus-python/tree/master/contrib/opencensus-ext-flask
266+
.. _Google Cloud Client Libraries: https://github.com/census-instrumentation/opencensus-python/tree/master/contrib/opencensus-ext-google-cloud-clientlibs
267+
.. _gRPC: https://github.com/census-instrumentation/opencensus-python/tree/master/contrib/opencensus-ext-grpc
268+
.. _httplib: https://github.com/census-instrumentation/opencensus-python/tree/master/contrib/opencensus-ext-httplib
269+
.. _MySQL: https://github.com/census-instrumentation/opencensus-python/tree/master/contrib/opencensus-ext-mysql
270+
.. _PostgreSQL: https://github.com/census-instrumentation/opencensus-python/tree/master/contrib/opencensus-ext-postgresql
271+
.. _pymongo: https://github.com/census-instrumentation/opencensus-python/tree/master/contrib/opencensus-ext-pymongo
272+
.. _PyMySQL: https://github.com/census-instrumentation/opencensus-python/tree/master/contrib/opencensus-ext-pymysql
273+
.. _Pyramid: https://github.com/census-instrumentation/opencensus-python/tree/master/contrib/opencensus-ext-pyramid
274+
.. _requests: https://github.com/census-instrumentation/opencensus-python/tree/master/contrib/opencensus-ext-requests
275+
.. _SQLAlchemy: https://github.com/census-instrumentation/opencensus-python/tree/master/contrib/opencensus-ext-sqlalchemy
276+
.. _threading: https://github.com/census-instrumentation/opencensus-python/tree/master/contrib/opencensus-ext-threading
462277

463278
------
464279
Stats
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# Changelog
2+
3+
## Unreleased
4+
5+
- Add this changelog.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
W3C Correlation Context
2+
============================================================================
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
__path__ = __import__('pkgutil').extend_path(__path__, __name__)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
__path__ = __import__('pkgutil').extend_path(__path__, __name__)

opencensus/trace/ext/google_cloud_clientlibs/__init__.py renamed to contrib/opencensus-correlation/opencensus/common/correlationcontext/__init__.py

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright 2017, OpenCensus Authors
1+
# Copyright 2019, OpenCensus Authors
22
#
33
# Licensed under the Apache License, Version 2.0 (the "License");
44
# you may not use this file except in compliance with the License.
@@ -12,6 +12,7 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15-
from opencensus.trace.ext.google_cloud_clientlibs import trace
15+
from opencensus.common.correlationcontext.correlationcontext import CorrelationContext
1616

17-
__all__ = ['trace']
17+
18+
__all__ = ['CorrelationContext']
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# Copyright 2019, OpenCensus Authors
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
class CorrelationContext(object):
16+
pass

0 commit comments

Comments
 (0)