Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit ea77e77

Browse files
author
alrex
authored
Merge branch 'master' into span-processor-reset-timeout
2 parents e79ff4a + ddf7eeb commit ea77e77

File tree

207 files changed

+2386
-992
lines changed

Some content is hidden

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

207 files changed

+2386
-992
lines changed

.github/workflows/docs.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ on:
77
paths:
88
- 'docs/**'
99
- 'exporter/**'
10-
- 'ext/**'
10+
- 'instrumentation/**'
1111
- 'opentelemetry-python/opentelemetry-api/src/opentelemetry/**'
1212
- 'opentelemetry-python/opentelemetry-sdk/src/opentelemetry/sdk/**'
1313

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
Basic Context
2+
=============
3+
4+
These examples show how context is propagated through Spans in OpenTelemetry.
5+
6+
There are three different examples:
7+
8+
* implicit_context: Shows how starting a span implicitly creates context.
9+
10+
* child_context: Shows how context is propagated through child spans.
11+
12+
* async_context: Shows how context can be shared in another coroutine.
13+
14+
The source files of these examples are available :scm_web:`here <docs/examples/basic_context/>`.
15+
16+
Installation
17+
------------
18+
19+
.. code-block:: sh
20+
21+
pip install opentelemetry-api
22+
pip install opentelemetry-sdk
23+
24+
Run the Example
25+
---------------
26+
27+
.. code-block:: sh
28+
29+
python <example_name>.py
30+
31+
The output will be shown in the console.
32+
33+
Useful links
34+
------------
35+
36+
- OpenTelemetry_
37+
- :doc:`../../api/trace`
38+
39+
.. _OpenTelemetry: https://github.com/open-telemetry/opentelemetry-python/

opentelemetry-sdk/tests/correlationcontext/__init__.py renamed to docs/examples/basic_context/async_context.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,28 @@
1111
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
14+
15+
import asyncio
16+
17+
from opentelemetry import baggage, trace
18+
from opentelemetry.sdk.trace import TracerProvider
19+
20+
trace.set_tracer_provider(TracerProvider())
21+
tracer = trace.get_tracer(__name__)
22+
23+
loop = asyncio.get_event_loop()
24+
25+
26+
async def async_span(span):
27+
with tracer.use_span(span):
28+
ctx = baggage.set_baggage("foo", "bar")
29+
return ctx
30+
31+
32+
async def main():
33+
span = tracer.start_span(name="span")
34+
ctx = await async_span(span)
35+
print(baggage.get_all(context=ctx))
36+
37+
38+
loop.run_until_complete(main())
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# Copyright The OpenTelemetry 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+
from opentelemetry import baggage, trace
16+
17+
tracer = trace.get_tracer(__name__)
18+
19+
global_ctx = baggage.set_baggage("context", "global")
20+
with tracer.start_as_current_span(name="root span") as root_span:
21+
parent_ctx = baggage.set_baggage("context", "parent")
22+
with tracer.start_as_current_span(
23+
name="child span", context=parent_ctx
24+
) as child_span:
25+
child_ctx = baggage.set_baggage("context", "child")
26+
27+
print(baggage.get_baggage("context", global_ctx))
28+
print(baggage.get_baggage("context", parent_ctx))
29+
print(baggage.get_baggage("context", child_ctx))

instrumentation/opentelemetry-instrumentation-django/tests/conftest.py renamed to docs/examples/basic_context/implicit_context.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,14 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15-
from os import environ
15+
from opentelemetry import baggage, trace
16+
from opentelemetry.sdk.trace import TracerProvider
1617

18+
trace.set_tracer_provider(TracerProvider())
19+
tracer = trace.get_tracer(__name__)
1720

18-
def pytest_sessionstart(session): # pylint: disable=unused-argument
19-
environ.setdefault("OTEL_PYTHON_DJANGO_INSTRUMENT", "True")
21+
with tracer.start_span(name="root span") as root_span:
22+
ctx = baggage.set_baggage("foo", "bar")
23+
24+
print("Global context baggage: {}".format(baggage.get_all()))
25+
print("Span context baggage: {}".format(baggage.get_all(context=ctx)))

docs/examples/django/README.rst

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ Execution of the Django app
3636

3737
Set these environment variables first:
3838

39-
#. ``export OTEL_PYTHON_DJANGO_INSTRUMENT=True``
4039
#. ``export DJANGO_SETTINGS_MODULE=instrumentation_example.settings``
4140

4241
The way to achieve OpenTelemetry instrumentation for your Django app is to use
@@ -100,6 +99,13 @@ output similar to this one:
10099
The last output shows spans automatically generated by the OpenTelemetry Django
101100
Instrumentation package.
102101

102+
Disabling Django Instrumentation
103+
--------------------------------
104+
105+
Django's instrumentation can be disabled by setting the following environment variable.
106+
107+
#. ``export OTEL_PYTHON_DJANGO_INSTRUMENT=False``
108+
103109
References
104110
----------
105111

docs/examples/django/manage.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,13 @@
2121

2222

2323
def main():
24+
os.environ.setdefault(
25+
"DJANGO_SETTINGS_MODULE", "instrumentation_example.settings"
26+
)
2427

2528
# This call is what makes the Django application be instrumented
2629
DjangoInstrumentor().instrument()
2730

28-
os.environ.setdefault(
29-
"DJANGO_SETTINGS_MODULE", "instrumentation_example.settings"
30-
)
3131
try:
3232
from django.core.management import execute_from_command_line
3333
except ImportError as exc:

docs/examples/error_hander/error_handler_0/setup.cfg

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ package_dir=
3636
=src
3737
packages=find_namespace:
3838
install_requires =
39-
opentelemetry-sdk == 0.14.dev0
39+
opentelemetry-sdk == 0.15.dev0
4040

4141
[options.packages.find]
4242
where = src

docs/examples/error_hander/error_handler_0/src/error_handler_0/version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,4 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15-
__version__ = "0.14.dev0"
15+
__version__ = "0.15.dev0"

docs/examples/error_hander/error_handler_1/setup.cfg

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ package_dir=
3636
=src
3737
packages=find_namespace:
3838
install_requires =
39-
opentelemetry-sdk == 0.14.dev0
39+
opentelemetry-sdk == 0.15.dev0
4040

4141
[options.packages.find]
4242
where = src

docs/examples/error_hander/error_handler_1/src/error_handler_1/version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,4 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15-
__version__ = "0.14.dev0"
15+
__version__ = "0.15.dev0"

docs/examples/opentelemetry-example-app/setup.cfg

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,10 @@ zip_safe = False
4242
include_package_data = True
4343
install_requires =
4444
typing; python_version<'3.5'
45-
opentelemetry-api == 0.14.dev0
46-
opentelemetry-sdk == 0.14.dev0
47-
opentelemetry-instrumentation-requests == 0.14.dev0
48-
opentelemetry-instrumentation-flask == 0.14.dev0
45+
opentelemetry-api == 0.15.dev0
46+
opentelemetry-sdk == 0.15.dev0
47+
opentelemetry-instrumentation-requests == 0.15.dev0
48+
opentelemetry-instrumentation-flask == 0.15.dev0
4949
flask
5050
requests
5151
protobuf~=3.11

docs/examples/opentelemetry-example-app/src/opentelemetry_example_app/version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,4 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15-
__version__ = "0.14.dev0"
15+
__version__ = "0.15.dev0"

docs/faq-and-cookbook.rst

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,3 +25,21 @@ Getting and modifying a span
2525
2626
current_span = trace.get_current_span()
2727
current_span.set_attribute("hometown", "seattle")
28+
29+
Capturing baggage at different contexts
30+
---------------------------------------
31+
32+
.. code-block:: python
33+
34+
from opentelemetry import trace
35+
36+
tracer = trace.get_tracer(__name__)
37+
with tracer.start_as_current_span(name="root span") as root_span:
38+
parent_ctx = baggage.set_baggage("context", "parent")
39+
with tracer.start_as_current_span(
40+
name="child span", context=parent_ctx
41+
) as child_span:
42+
child_ctx = baggage.set_baggage("context", "child")
43+
44+
print(baggage.get_baggage("context", parent_ctx))
45+
print(baggage.get_baggage("context", child_ctx))

docs/getting_started/tests/test_flask.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,4 +45,4 @@ def test_flask(self):
4545
output = str(server.stdout.read())
4646
self.assertIn('"name": "HTTP GET"', output)
4747
self.assertIn('"name": "example-request"', output)
48-
self.assertIn('"name": "hello"', output)
48+
self.assertIn('"name": "/"', output)

exporter/opentelemetry-exporter-datadog/CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,13 @@
22

33
## Unreleased
44

5+
- Make `SpanProcessor.on_start` accept parent Context
6+
([#1251](https://github.com/open-telemetry/opentelemetry-python/pull/1251))
7+
8+
## Version 0.14b0
9+
10+
Released 2020-10-13
11+
512
- Add support for span resource labels and service name
613

714
## Version 0.12b0

exporter/opentelemetry-exporter-datadog/setup.cfg

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,8 @@ package_dir=
4040
packages=find_namespace:
4141
install_requires =
4242
ddtrace>=0.34.0
43-
opentelemetry-api == 0.14.dev0
44-
opentelemetry-sdk == 0.14.dev0
43+
opentelemetry-api == 0.15.dev0
44+
opentelemetry-sdk == 0.15.dev0
4545

4646
[options.packages.find]
4747
where = src

exporter/opentelemetry-exporter-datadog/src/opentelemetry/exporter/datadog/exporter.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -189,12 +189,12 @@ def _translate_to_datadog(self, spans):
189189

190190
def _get_trace_ids(span):
191191
"""Extract tracer ids from span"""
192-
ctx = span.get_context()
192+
ctx = span.get_span_context()
193193
trace_id = ctx.trace_id
194194
span_id = ctx.span_id
195195

196196
if isinstance(span.parent, trace_api.Span):
197-
parent_id = span.parent.get_context().span_id
197+
parent_id = span.parent.get_span_context().span_id
198198
elif isinstance(span.parent, trace_api.SpanContext):
199199
parent_id = span.parent.span_id
200200
else:
@@ -255,13 +255,13 @@ def _get_exc_info(span):
255255

256256

257257
def _get_origin(span):
258-
ctx = span.get_context()
258+
ctx = span.get_span_context()
259259
origin = ctx.trace_state.get(DD_ORIGIN)
260260
return origin
261261

262262

263263
def _get_sampling_rate(span):
264-
ctx = span.get_context()
264+
ctx = span.get_span_context()
265265
return (
266266
span.sampler.rate
267267
if ctx.trace_flags.sampled

exporter/opentelemetry-exporter-datadog/src/opentelemetry/exporter/datadog/propagator.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ def inject(
8686
context: typing.Optional[Context] = None,
8787
) -> None:
8888
span = get_current_span(context)
89-
span_context = span.get_context()
89+
span_context = span.get_span_context()
9090
if span_context == trace.INVALID_SPAN_CONTEXT:
9191
return
9292
sampled = (trace.TraceFlags.SAMPLED & span.context.trace_flags) != 0

exporter/opentelemetry-exporter-datadog/src/opentelemetry/exporter/datadog/spanprocessor.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
import threading
1818
import typing
1919

20-
from opentelemetry.context import attach, detach, set_value
20+
from opentelemetry.context import Context, attach, detach, set_value
2121
from opentelemetry.sdk.trace import Span, SpanProcessor
2222
from opentelemetry.sdk.trace.export import SpanExporter
2323
from opentelemetry.trace import INVALID_TRACE_ID
@@ -81,8 +81,10 @@ def __init__(
8181
self.done = False
8282
self.worker_thread.start()
8383

84-
def on_start(self, span: Span) -> None:
85-
ctx = span.get_context()
84+
def on_start(
85+
self, span: Span, parent_context: typing.Optional[Context] = None
86+
) -> None:
87+
ctx = span.get_span_context()
8688
trace_id = ctx.trace_id
8789

8890
with self.traces_lock:
@@ -102,7 +104,7 @@ def on_end(self, span: Span) -> None:
102104
logger.warning("Already shutdown, dropping span.")
103105
return
104106

105-
ctx = span.get_context()
107+
ctx = span.get_span_context()
106108
trace_id = ctx.trace_id
107109

108110
with self.traces_lock:

exporter/opentelemetry-exporter-datadog/src/opentelemetry/exporter/datadog/version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,4 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15-
__version__ = "0.14.dev0"
15+
__version__ = "0.15.dev0"

0 commit comments

Comments
 (0)