Skip to content

Commit a0e4049

Browse files
authored
Merge branch 'main' into feature/add_pika_instrumentation
2 parents da90f11 + fbb677a commit a0e4049

File tree

65 files changed

+735
-249
lines changed

Some content is hidden

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

65 files changed

+735
-249
lines changed

.flake8

-1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,5 @@ exclude =
1919
exporter/opentelemetry-exporter-jaeger/build/*
2020
docs/examples/opentelemetry-example-app/src/opentelemetry_example_app/grpc/gen/
2121
docs/examples/opentelemetry-example-app/build/*
22-
opentelemetry-python-core/
2322
opentelemetry-proto/build/*
2423
opentelemetry-proto/src/opentelemetry/proto/

.github/workflows/test.yml

+1-16
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ on:
66
- 'release/*'
77
pull_request:
88
env:
9-
CORE_REPO_SHA: c49ad57bfe35cfc69bfa863d74058ca9bec55fc3
9+
CORE_REPO_SHA: 10208c1be1e720925a80a66f711b8afbe67537f4
1010

1111
jobs:
1212
build:
@@ -28,12 +28,6 @@ jobs:
2828
steps:
2929
- name: Checkout Contrib Repo @ SHA - ${{ github.sha }}
3030
uses: actions/checkout@v2
31-
- name: Checkout Core Repo @ SHA - ${{ env.CORE_REPO_SHA }}
32-
uses: actions/checkout@v2
33-
with:
34-
repository: open-telemetry/opentelemetry-python
35-
ref: ${{ env.CORE_REPO_SHA }}
36-
path: opentelemetry-python-core
3731
- name: Set up Python ${{ env[matrix.python-version] }}
3832
uses: actions/setup-python@v2
3933
with:
@@ -84,12 +78,6 @@ jobs:
8478
steps:
8579
- name: Checkout Contrib Repo @ SHA - ${{ github.sha }}
8680
uses: actions/checkout@v2
87-
- name: Checkout Core Repo @ SHA ${{ env.CORE_REPO_SHA }}
88-
uses: actions/checkout@v2
89-
with:
90-
repository: open-telemetry/opentelemetry-python
91-
ref: ${{ env.CORE_REPO_SHA }}
92-
path: opentelemetry-python-core
9381
- name: Set up Python 3.9
9482
uses: actions/setup-python@v2
9583
with:
@@ -109,6 +97,3 @@ jobs:
10997
key: v4-misc-tox-cache-${{ matrix.tox-environment }}-${{ hashFiles('tox.ini', 'dev-requirements.txt', 'gen-requirements.txt', 'docs-requirements.txt') }}
11098
- name: run tox
11199
run: tox -e ${{ matrix.tox-environment }}
112-
- name: Ensure generated code is up to date
113-
if: matrix.tox-environment == 'generate'
114-
run: git diff --exit-code || (echo 'Generated code is out of date, please run "tox -e generate" and commit the changes in this PR.' && exit 1)

.gitignore

-2
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,6 @@ lib64
2323
__pycache__
2424
venv*/
2525
.venv*/
26-
opentelemetry-python-core*/
27-
/opentelemetry-python-core
2826

2927
# Installer logs
3028
pip-log.txt

.isort.cfg

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,6 @@ profile=black
1414
; docs: https://github.com/timothycrosley/isort#multi-line-output-modes
1515
multi_line_output=3
1616
skip=target
17-
skip_glob=**/gen/*,.venv*/*,venv*/*,opentelemetry-python-core/*,.tox/*
17+
skip_glob=**/gen/*,.venv*/*,venv*/*,.tox/*
1818
known_first_party=opentelemetry
1919
known_third_party=psutil,pytest,redis,redis_opentracing

CHANGELOG.md

+11
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,17 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
2828
- `opentelemetry-instrumentation-urllib3` Updated `_RequestHookT` with two additional fields - the request body and the request headers
2929
([#660](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/660))
3030

31+
### Changed
32+
- Tests for Falcon 3 support
33+
([#644](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/644))
34+
35+
### Added
36+
37+
- `opentelemetry-instrumentation-urllib3`, `opentelemetry-instrumentation-requests`
38+
The `net.peer.ip` attribute is set to the IP of the connected HTTP server or proxy
39+
using a new instrumentor in `opententelemetry-util-http`
40+
([#661](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/661))
41+
3142
## [1.5.0-0.24b0](https://github.com/open-telemetry/opentelemetry-python/releases/tag/v1.5.0-0.24b0) - 2021-08-26
3243

3344
### Added

CONTRIBUTING.md

+7-7
Original file line numberDiff line numberDiff line change
@@ -156,16 +156,16 @@ For a deeper discussion, see: https://github.com/open-telemetry/opentelemetry-sp
156156
## Running Tests Locally
157157

158158
1. Go to your Contrib repo directory. `git clone [email protected]:open-telemetry/opentelemetry-python-contrib.git && cd opentelemetry-python-contrib`.
159-
2. Clone the [OpenTelemetry Python](https://github.com/open-telemetry/opentelemetry-python) Python Core repo to a folder named `opentelemetry-python-core`. `git clone https://github.com/open-telemetry/opentelemetry-python.git opentelemetry-python-core`.
160-
3. Make sure you have `tox` installed. `pip install tox`.
161-
4. Run `tox` without any arguments to run tests for all the packages. Read more about [tox](https://tox.readthedocs.io/en/latest/).
159+
2. Make sure you have `tox` installed. `pip install tox`.
160+
3. Run `tox` without any arguments to run tests for all the packages. Read more about [tox](https://tox.readthedocs.io/en/latest/).
162161

163162
### Testing against a different Core repo branch/commit
164163

165-
1. Change directory to the repo that was cloned above. `cd opentelemetry-python-core`.
166-
2. Move the head of this repo to the SHA hash you want your tests to use. The current SHA hash can be found in `.github/workflows/test.yml` file under the `opentelemetry-python-contrib` directory. For example, currently it is `1a12fa0d681e37c1fda9cb8d46212ff3bbf6b76a`. So use `git fetch && git checkout <current SHA hash>`.
167-
3. Go back to the root directory. `cd ../`.
168-
4. With `tox` installed, run tests for a package. (e.g. `tox -e test-instrumentation-flask`.)
164+
Some of the tox targets install packages from the [OpenTelemetry Python Core Repository](https://github.com/open-telemetry/opentelemetry-python) via pip. The version of the packages installed defaults to the main branch in that repository when tox is run locally. It is possible to install packages tagged with a specific git commit hash by setting an environment variable before running tox as per the following example:
165+
166+
CORE_REPO_SHA=c49ad57bfe35cfc69bfa863d74058ca9bec55fc3 tox
167+
168+
The continuation integration overrides that environment variable with as per the configuration [here](https://github.com/open-telemetry/opentelemetry-python-contrib/blob/main/.github/workflows/test.yml#L9).
169169

170170

171171
## Style Guide

README.md

+2-6
Original file line numberDiff line numberDiff line change
@@ -116,12 +116,8 @@ Maintainers ([@open-telemetry/python-maintainers](https://github.com/orgs/open-t
116116
1. Go to your Contrib repo directory. `cd ~/git/opentelemetry-python-contrib`.
117117
2. Create a virtual env in your Contrib repo directory. `python3 -m venv my_test_venv`.
118118
3. Activate your virtual env. `source my_test_venv/bin/activate`.
119-
4. Clone the [OpenTelemetry Python](https://github.com/open-telemetry/opentelemetry-python) Python Core repo to a folder named `opentelemetry-python-core`. `git clone [email protected]:open-telemetry/opentelemetry-python.git opentelemetry-python-core`.
120-
5. Change directory to the repo that was just cloned. `cd opentelemetry-python-core`.
121-
6. Move the head of this repo to the hash you want your tests to use. This is currently the SHA `47483865854c7adae7455f8441dab7f814f4ce2a` as seen in `.github/workflows/test.yml`. Use `git fetch && git checkout 47483865854c7adae7455f8441dab7f814f4ce2a`.
122-
7. Go back to the root directory. `cd ../`.
123-
8. Make sure you have `tox` installed. `pip install tox`.
124-
9. Run tests for a package. (e.g. `tox -e test-instrumentation-flask`.)
119+
4. Make sure you have `tox` installed. `pip install tox`.
120+
5. Run tests for a package. (e.g. `tox -e test-instrumentation-flask`.)
125121

126122
### Thanks to all the people who already contributed!
127123

_template/setup.cfg

+1
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ classifiers =
3737
Programming Language :: Python :: 3.6
3838
Programming Language :: Python :: 3.7
3939
Programming Language :: Python :: 3.8
40+
Programming Language :: Python :: 3.9
4041

4142
[options]
4243
python_requires = >=3.6

docs/conf.py

+2-6
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,7 @@
2424

2525
settings.configure()
2626

27-
source_dirs = [
28-
os.path.abspath(
29-
"../opentelemetry-python-core/opentelemetry-instrumentation/src/"
30-
),
31-
]
27+
source_dirs = []
3228

3329
exp = "../exporter"
3430
exp_dirs = [
@@ -51,7 +47,7 @@
5147
if isdir(join(sdk_ext, f))
5248
]
5349

54-
sys.path[:0] = source_dirs + exp_dirs + instr_dirs + sdk_ext_dirs
50+
sys.path[:0] = exp_dirs + instr_dirs + sdk_ext_dirs
5551

5652
# -- Project information -----------------------------------------------------
5753

eachdist.ini

-2
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@
33
[DEFAULT]
44
ignore=
55
_template
6-
reference
7-
opentelemetry-python-core
86

97
sortfirst=
108
util/opentelemetry-util-http

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ def agent_writer(self):
102102
self._agent_writer = AgentWriter(uds_path=url_parsed.path)
103103
else:
104104
raise ValueError(
105-
"Unknown scheme `%s` for agent URL" % url_parsed.scheme
105+
f"Unknown scheme `{url_parsed.scheme}` for agent URL"
106106
)
107107
return self._agent_writer
108108

@@ -225,7 +225,7 @@ def _get_span_name(span):
225225
)
226226
span_kind_name = span.kind.name if span.kind else None
227227
name = (
228-
"{}.{}".format(instrumentation_name, span_kind_name)
228+
f"{instrumentation_name}.{span_kind_name}"
229229
if instrumentation_name and span_kind_name
230230
else span.name
231231
)

exporter/opentelemetry-exporter-datadog/tests/test_datadog_exporter.py

+19-9
Original file line numberDiff line numberDiff line change
@@ -550,18 +550,28 @@ def test_span_processor_accepts_parent_context(self):
550550
)
551551

552552
def test_origin(self):
553-
context = trace_api.SpanContext(
554-
trace_id=0x000000000000000000000000DEADBEEF,
555-
span_id=trace_api.INVALID_SPAN,
556-
is_remote=True,
557-
trace_state=trace_api.TraceState(
558-
[(datadog.constants.DD_ORIGIN, "origin-service")]
559-
),
553+
trace_id = 0x000000000000000000000000DEADBEEF
554+
trace_state = trace_api.TraceState(
555+
[(datadog.constants.DD_ORIGIN, "origin-service")]
556+
)
557+
parent_span_ctx = trace_api.SpanContext(
558+
trace_id=trace_id,
559+
span_id=0x1,
560+
is_remote=False,
561+
trace_state=trace_state,
562+
)
563+
child_span_ctx = trace_api.SpanContext(
564+
trace_id=trace_id,
565+
span_id=0x2,
566+
is_remote=False,
567+
trace_state=trace_state,
560568
)
561569

562-
root_span = trace._Span(name="root", context=context, parent=None)
570+
root_span = trace._Span(
571+
name="root", context=parent_span_ctx, parent=None
572+
)
563573
child_span = trace._Span(
564-
name="child", context=context, parent=root_span
574+
name="child", context=child_span_ctx, parent=parent_span_ctx
565575
)
566576
root_span.start()
567577
child_span.start()

gen-requirements.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@ astor==0.8.1
33
jinja2~=2.7
44
isort
55
black
6-
6+
requests

instrumentation/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
| [opentelemetry-instrumentation-dbapi](./opentelemetry-instrumentation-dbapi) | dbapi |
1212
| [opentelemetry-instrumentation-django](./opentelemetry-instrumentation-django) | django >= 1.10 |
1313
| [opentelemetry-instrumentation-elasticsearch](./opentelemetry-instrumentation-elasticsearch) | elasticsearch >= 2.0 |
14-
| [opentelemetry-instrumentation-falcon](./opentelemetry-instrumentation-falcon) | falcon ~= 2.0 |
14+
| [opentelemetry-instrumentation-falcon](./opentelemetry-instrumentation-falcon) | falcon >= 2.0.0, < 4.0.0 |
1515
| [opentelemetry-instrumentation-fastapi](./opentelemetry-instrumentation-fastapi) | fastapi ~= 0.58 |
1616
| [opentelemetry-instrumentation-flask](./opentelemetry-instrumentation-flask) | flask >= 1.0, < 3.0 |
1717
| [opentelemetry-instrumentation-grpc](./opentelemetry-instrumentation-grpc) | grpcio ~= 1.27 |

instrumentation/opentelemetry-instrumentation-aiohttp-client/src/opentelemetry/instrumentation/aiohttp_client/__init__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ async def on_request_start(
175175
return
176176

177177
http_method = params.method.upper()
178-
request_span_name = "HTTP {}".format(http_method)
178+
request_span_name = f"HTTP {http_method}"
179179

180180
trace_config_ctx.span = trace_config_ctx.tracer.start_span(
181181
request_span_name, kind=SpanKind.CLIENT,

instrumentation/opentelemetry-instrumentation-aiohttp-client/tests/test_aiohttp_client_integration.py

+10-18
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ def _http_request(
9292
method: str = "GET",
9393
status_code: int = HTTPStatus.OK,
9494
request_handler: typing.Callable = None,
95-
**kwargs
95+
**kwargs,
9696
) -> typing.Tuple[str, int]:
9797
"""Helper to start an aiohttp test server and send an actual HTTP request to it."""
9898

@@ -132,9 +132,7 @@ def test_status_codes(self):
132132
(span_status, None),
133133
{
134134
SpanAttributes.HTTP_METHOD: "GET",
135-
SpanAttributes.HTTP_URL: "http://{}:{}/test-path?query=param#foobar".format(
136-
host, port
137-
),
135+
SpanAttributes.HTTP_URL: f"http://{host}:{port}/test-path?query=param#foobar",
138136
SpanAttributes.HTTP_STATUS_CODE: int(
139137
status_code
140138
),
@@ -167,7 +165,7 @@ def test_hooks(self):
167165
expected = "PATCH - /some/path"
168166

169167
def request_hook(span: Span, params: aiohttp.TraceRequestStartParams):
170-
span.update_name("{} - {}".format(params.method, params.url.path))
168+
span.update_name(f"{params.method} - {params.url.path}")
171169

172170
def response_hook(
173171
span: Span,
@@ -198,7 +196,7 @@ def response_hook(
198196
)
199197
self.assertEqual(
200198
span.attributes[SpanAttributes.HTTP_URL],
201-
"http://{}:{}{}".format(host, port, path),
199+
f"http://{host}:{port}{path}",
202200
)
203201
self.assertEqual(
204202
span.attributes[SpanAttributes.HTTP_STATUS_CODE], HTTPStatus.OK
@@ -227,9 +225,7 @@ def strip_query_params(url: yarl.URL) -> str:
227225
(StatusCode.UNSET, None),
228226
{
229227
SpanAttributes.HTTP_METHOD: "GET",
230-
SpanAttributes.HTTP_URL: "http://{}:{}/some/path".format(
231-
host, port
232-
),
228+
SpanAttributes.HTTP_URL: f"http://{host}:{port}/some/path",
233229
SpanAttributes.HTTP_STATUS_CODE: int(HTTPStatus.OK),
234230
},
235231
)
@@ -290,9 +286,7 @@ async def request_handler(request):
290286
(StatusCode.ERROR, None),
291287
{
292288
SpanAttributes.HTTP_METHOD: "GET",
293-
SpanAttributes.HTTP_URL: "http://{}:{}/test_timeout".format(
294-
host, port
295-
),
289+
SpanAttributes.HTTP_URL: f"http://{host}:{port}/test_timeout",
296290
},
297291
)
298292
]
@@ -319,9 +313,7 @@ async def request_handler(request):
319313
(StatusCode.ERROR, None),
320314
{
321315
SpanAttributes.HTTP_METHOD: "GET",
322-
SpanAttributes.HTTP_URL: "http://{}:{}/test_too_many_redirects".format(
323-
host, port
324-
),
316+
SpanAttributes.HTTP_URL: f"http://{host}:{port}/test_too_many_redirects",
325317
},
326318
)
327319
]
@@ -399,7 +391,7 @@ def test_instrument(self):
399391
span = self.assert_spans(1)
400392
self.assertEqual("GET", span.attributes[SpanAttributes.HTTP_METHOD])
401393
self.assertEqual(
402-
"http://{}:{}/test-path".format(host, port),
394+
f"http://{host}:{port}/test-path",
403395
span.attributes[SpanAttributes.HTTP_URL],
404396
)
405397
self.assertEqual(200, span.attributes[SpanAttributes.HTTP_STATUS_CODE])
@@ -502,13 +494,13 @@ def strip_query_params(url: yarl.URL) -> str:
502494
)
503495
span = self.assert_spans(1)
504496
self.assertEqual(
505-
"http://{}:{}/test-path".format(host, port),
497+
f"http://{host}:{port}/test-path",
506498
span.attributes[SpanAttributes.HTTP_URL],
507499
)
508500

509501
def test_hooks(self):
510502
def request_hook(span: Span, params: aiohttp.TraceRequestStartParams):
511-
span.update_name("{} - {}".format(params.method, params.url.path))
503+
span.update_name(f"{params.method} - {params.url.path}")
512504

513505
def response_hook(
514506
span: Span,

instrumentation/opentelemetry-instrumentation-asgi/src/opentelemetry/instrumentation/asgi/__init__.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -152,8 +152,9 @@ def get_default_span_details(scope: dict) -> Tuple[str, dict]:
152152
Returns:
153153
a tuple of the span name, and any attributes to attach to the span.
154154
"""
155-
span_name = scope.get("path", "").strip() or "HTTP {}".format(
156-
scope.get("method", "").strip()
155+
span_name = (
156+
scope.get("path", "").strip()
157+
or f"HTTP {scope.get('method', '').strip()}"
157158
)
158159

159160
return span_name, {}

instrumentation/opentelemetry-instrumentation-boto/src/opentelemetry/instrumentation/boto/__init__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ def _common_request( # pylint: disable=too-many-locals
123123
endpoint_name = getattr(instance, "host").split(".")[0]
124124

125125
with self._tracer.start_as_current_span(
126-
"{}.command".format(endpoint_name), kind=SpanKind.CONSUMER,
126+
f"{endpoint_name}.command", kind=SpanKind.CONSUMER,
127127
) as span:
128128
span.set_attribute("endpoint", endpoint_name)
129129
if args:

instrumentation/opentelemetry-instrumentation-boto/tests/test_boto_instrumentation.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
def assert_span_http_status_code(span, code):
3636
"""Assert on the span's 'http.status_code' tag"""
3737
tag = span.attributes[SpanAttributes.HTTP_STATUS_CODE]
38-
assert tag == code, "%r != %r" % (tag, code)
38+
assert tag == code, f"{tag} != {code}"
3939

4040

4141
class TestBotoInstrumentor(TestBase):

instrumentation/opentelemetry-instrumentation-botocore/src/opentelemetry/instrumentation/botocore/__init__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ def _patched_api_call(self, original_func, instance, args, kwargs):
151151
result = None
152152

153153
with self._tracer.start_as_current_span(
154-
"{}".format(service_name), kind=SpanKind.CLIENT,
154+
f"{service_name}", kind=SpanKind.CLIENT,
155155
) as span:
156156
# inject trace context into payload headers for lambda Invoke
157157
if BotocoreInstrumentor._is_lambda_invoke(

instrumentation/opentelemetry-instrumentation-celery/src/opentelemetry/instrumentation/celery/__init__.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ def _trace_prerun(self, *args, **kwargs):
136136

137137
logger.debug("prerun signal start task_id=%s", task_id)
138138

139-
operation_name = "{0}/{1}".format(_TASK_RUN, task.name)
139+
operation_name = f"{_TASK_RUN}/{task.name}"
140140
span = self._tracer.start_span(
141141
operation_name, context=tracectx, kind=trace.SpanKind.CONSUMER
142142
)
@@ -178,7 +178,7 @@ def _trace_before_publish(self, *args, **kwargs):
178178
if task is None or task_id is None:
179179
return
180180

181-
operation_name = "{0}/{1}".format(_TASK_APPLY_ASYNC, task.name)
181+
operation_name = f"{_TASK_APPLY_ASYNC}/{task.name}"
182182
span = self._tracer.start_span(
183183
operation_name, kind=trace.SpanKind.PRODUCER
184184
)

0 commit comments

Comments
 (0)