Skip to content

Commit

Permalink
Merge branch 'main' into feature/add_pika_instrumentation
Browse files Browse the repository at this point in the history
  • Loading branch information
ocelotl authored Sep 29, 2021
2 parents da90f11 + fbb677a commit a0e4049
Show file tree
Hide file tree
Showing 65 changed files with 735 additions and 249 deletions.
1 change: 0 additions & 1 deletion .flake8
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,5 @@ exclude =
exporter/opentelemetry-exporter-jaeger/build/*
docs/examples/opentelemetry-example-app/src/opentelemetry_example_app/grpc/gen/
docs/examples/opentelemetry-example-app/build/*
opentelemetry-python-core/
opentelemetry-proto/build/*
opentelemetry-proto/src/opentelemetry/proto/
17 changes: 1 addition & 16 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ on:
- 'release/*'
pull_request:
env:
CORE_REPO_SHA: c49ad57bfe35cfc69bfa863d74058ca9bec55fc3
CORE_REPO_SHA: 10208c1be1e720925a80a66f711b8afbe67537f4

jobs:
build:
Expand All @@ -28,12 +28,6 @@ jobs:
steps:
- name: Checkout Contrib Repo @ SHA - ${{ github.sha }}
uses: actions/checkout@v2
- name: Checkout Core Repo @ SHA - ${{ env.CORE_REPO_SHA }}
uses: actions/checkout@v2
with:
repository: open-telemetry/opentelemetry-python
ref: ${{ env.CORE_REPO_SHA }}
path: opentelemetry-python-core
- name: Set up Python ${{ env[matrix.python-version] }}
uses: actions/setup-python@v2
with:
Expand Down Expand Up @@ -84,12 +78,6 @@ jobs:
steps:
- name: Checkout Contrib Repo @ SHA - ${{ github.sha }}
uses: actions/checkout@v2
- name: Checkout Core Repo @ SHA ${{ env.CORE_REPO_SHA }}
uses: actions/checkout@v2
with:
repository: open-telemetry/opentelemetry-python
ref: ${{ env.CORE_REPO_SHA }}
path: opentelemetry-python-core
- name: Set up Python 3.9
uses: actions/setup-python@v2
with:
Expand All @@ -109,6 +97,3 @@ jobs:
key: v4-misc-tox-cache-${{ matrix.tox-environment }}-${{ hashFiles('tox.ini', 'dev-requirements.txt', 'gen-requirements.txt', 'docs-requirements.txt') }}
- name: run tox
run: tox -e ${{ matrix.tox-environment }}
- name: Ensure generated code is up to date
if: matrix.tox-environment == 'generate'
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)
2 changes: 0 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@ lib64
__pycache__
venv*/
.venv*/
opentelemetry-python-core*/
/opentelemetry-python-core

# Installer logs
pip-log.txt
Expand Down
2 changes: 1 addition & 1 deletion .isort.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@ profile=black
; docs: https://github.com/timothycrosley/isort#multi-line-output-modes
multi_line_output=3
skip=target
skip_glob=**/gen/*,.venv*/*,venv*/*,opentelemetry-python-core/*,.tox/*
skip_glob=**/gen/*,.venv*/*,venv*/*,.tox/*
known_first_party=opentelemetry
known_third_party=psutil,pytest,redis,redis_opentracing
11 changes: 11 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,17 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- `opentelemetry-instrumentation-urllib3` Updated `_RequestHookT` with two additional fields - the request body and the request headers
([#660](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/660))

### Changed
- Tests for Falcon 3 support
([#644](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/644))

### Added

- `opentelemetry-instrumentation-urllib3`, `opentelemetry-instrumentation-requests`
The `net.peer.ip` attribute is set to the IP of the connected HTTP server or proxy
using a new instrumentor in `opententelemetry-util-http`
([#661](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/661))

## [1.5.0-0.24b0](https://github.com/open-telemetry/opentelemetry-python/releases/tag/v1.5.0-0.24b0) - 2021-08-26

### Added
Expand Down
14 changes: 7 additions & 7 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -156,16 +156,16 @@ For a deeper discussion, see: https://github.com/open-telemetry/opentelemetry-sp
## Running Tests Locally

1. Go to your Contrib repo directory. `git clone [email protected]:open-telemetry/opentelemetry-python-contrib.git && cd opentelemetry-python-contrib`.
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`.
3. Make sure you have `tox` installed. `pip install tox`.
4. Run `tox` without any arguments to run tests for all the packages. Read more about [tox](https://tox.readthedocs.io/en/latest/).
2. Make sure you have `tox` installed. `pip install tox`.
3. Run `tox` without any arguments to run tests for all the packages. Read more about [tox](https://tox.readthedocs.io/en/latest/).

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

1. Change directory to the repo that was cloned above. `cd opentelemetry-python-core`.
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>`.
3. Go back to the root directory. `cd ../`.
4. With `tox` installed, run tests for a package. (e.g. `tox -e test-instrumentation-flask`.)
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:

CORE_REPO_SHA=c49ad57bfe35cfc69bfa863d74058ca9bec55fc3 tox

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).


## Style Guide
Expand Down
8 changes: 2 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -116,12 +116,8 @@ Maintainers ([@open-telemetry/python-maintainers](https://github.com/orgs/open-t
1. Go to your Contrib repo directory. `cd ~/git/opentelemetry-python-contrib`.
2. Create a virtual env in your Contrib repo directory. `python3 -m venv my_test_venv`.
3. Activate your virtual env. `source my_test_venv/bin/activate`.
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`.
5. Change directory to the repo that was just cloned. `cd opentelemetry-python-core`.
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`.
7. Go back to the root directory. `cd ../`.
8. Make sure you have `tox` installed. `pip install tox`.
9. Run tests for a package. (e.g. `tox -e test-instrumentation-flask`.)
4. Make sure you have `tox` installed. `pip install tox`.
5. Run tests for a package. (e.g. `tox -e test-instrumentation-flask`.)

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

Expand Down
1 change: 1 addition & 0 deletions _template/setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ classifiers =
Programming Language :: Python :: 3.6
Programming Language :: Python :: 3.7
Programming Language :: Python :: 3.8
Programming Language :: Python :: 3.9

[options]
python_requires = >=3.6
Expand Down
8 changes: 2 additions & 6 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,7 @@

settings.configure()

source_dirs = [
os.path.abspath(
"../opentelemetry-python-core/opentelemetry-instrumentation/src/"
),
]
source_dirs = []

exp = "../exporter"
exp_dirs = [
Expand All @@ -51,7 +47,7 @@
if isdir(join(sdk_ext, f))
]

sys.path[:0] = source_dirs + exp_dirs + instr_dirs + sdk_ext_dirs
sys.path[:0] = exp_dirs + instr_dirs + sdk_ext_dirs

# -- Project information -----------------------------------------------------

Expand Down
2 changes: 0 additions & 2 deletions eachdist.ini
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
[DEFAULT]
ignore=
_template
reference
opentelemetry-python-core

sortfirst=
util/opentelemetry-util-http
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ def agent_writer(self):
self._agent_writer = AgentWriter(uds_path=url_parsed.path)
else:
raise ValueError(
"Unknown scheme `%s` for agent URL" % url_parsed.scheme
f"Unknown scheme `{url_parsed.scheme}` for agent URL"
)
return self._agent_writer

Expand Down Expand Up @@ -225,7 +225,7 @@ def _get_span_name(span):
)
span_kind_name = span.kind.name if span.kind else None
name = (
"{}.{}".format(instrumentation_name, span_kind_name)
f"{instrumentation_name}.{span_kind_name}"
if instrumentation_name and span_kind_name
else span.name
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -550,18 +550,28 @@ def test_span_processor_accepts_parent_context(self):
)

def test_origin(self):
context = trace_api.SpanContext(
trace_id=0x000000000000000000000000DEADBEEF,
span_id=trace_api.INVALID_SPAN,
is_remote=True,
trace_state=trace_api.TraceState(
[(datadog.constants.DD_ORIGIN, "origin-service")]
),
trace_id = 0x000000000000000000000000DEADBEEF
trace_state = trace_api.TraceState(
[(datadog.constants.DD_ORIGIN, "origin-service")]
)
parent_span_ctx = trace_api.SpanContext(
trace_id=trace_id,
span_id=0x1,
is_remote=False,
trace_state=trace_state,
)
child_span_ctx = trace_api.SpanContext(
trace_id=trace_id,
span_id=0x2,
is_remote=False,
trace_state=trace_state,
)

root_span = trace._Span(name="root", context=context, parent=None)
root_span = trace._Span(
name="root", context=parent_span_ctx, parent=None
)
child_span = trace._Span(
name="child", context=context, parent=root_span
name="child", context=child_span_ctx, parent=parent_span_ctx
)
root_span.start()
child_span.start()
Expand Down
2 changes: 1 addition & 1 deletion gen-requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ astor==0.8.1
jinja2~=2.7
isort
black

requests
2 changes: 1 addition & 1 deletion instrumentation/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
| [opentelemetry-instrumentation-dbapi](./opentelemetry-instrumentation-dbapi) | dbapi |
| [opentelemetry-instrumentation-django](./opentelemetry-instrumentation-django) | django >= 1.10 |
| [opentelemetry-instrumentation-elasticsearch](./opentelemetry-instrumentation-elasticsearch) | elasticsearch >= 2.0 |
| [opentelemetry-instrumentation-falcon](./opentelemetry-instrumentation-falcon) | falcon ~= 2.0 |
| [opentelemetry-instrumentation-falcon](./opentelemetry-instrumentation-falcon) | falcon >= 2.0.0, < 4.0.0 |
| [opentelemetry-instrumentation-fastapi](./opentelemetry-instrumentation-fastapi) | fastapi ~= 0.58 |
| [opentelemetry-instrumentation-flask](./opentelemetry-instrumentation-flask) | flask >= 1.0, < 3.0 |
| [opentelemetry-instrumentation-grpc](./opentelemetry-instrumentation-grpc) | grpcio ~= 1.27 |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ async def on_request_start(
return

http_method = params.method.upper()
request_span_name = "HTTP {}".format(http_method)
request_span_name = f"HTTP {http_method}"

trace_config_ctx.span = trace_config_ctx.tracer.start_span(
request_span_name, kind=SpanKind.CLIENT,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ def _http_request(
method: str = "GET",
status_code: int = HTTPStatus.OK,
request_handler: typing.Callable = None,
**kwargs
**kwargs,
) -> typing.Tuple[str, int]:
"""Helper to start an aiohttp test server and send an actual HTTP request to it."""

Expand Down Expand Up @@ -132,9 +132,7 @@ def test_status_codes(self):
(span_status, None),
{
SpanAttributes.HTTP_METHOD: "GET",
SpanAttributes.HTTP_URL: "http://{}:{}/test-path?query=param#foobar".format(
host, port
),
SpanAttributes.HTTP_URL: f"http://{host}:{port}/test-path?query=param#foobar",
SpanAttributes.HTTP_STATUS_CODE: int(
status_code
),
Expand Down Expand Up @@ -167,7 +165,7 @@ def test_hooks(self):
expected = "PATCH - /some/path"

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

def response_hook(
span: Span,
Expand Down Expand Up @@ -198,7 +196,7 @@ def response_hook(
)
self.assertEqual(
span.attributes[SpanAttributes.HTTP_URL],
"http://{}:{}{}".format(host, port, path),
f"http://{host}:{port}{path}",
)
self.assertEqual(
span.attributes[SpanAttributes.HTTP_STATUS_CODE], HTTPStatus.OK
Expand Down Expand Up @@ -227,9 +225,7 @@ def strip_query_params(url: yarl.URL) -> str:
(StatusCode.UNSET, None),
{
SpanAttributes.HTTP_METHOD: "GET",
SpanAttributes.HTTP_URL: "http://{}:{}/some/path".format(
host, port
),
SpanAttributes.HTTP_URL: f"http://{host}:{port}/some/path",
SpanAttributes.HTTP_STATUS_CODE: int(HTTPStatus.OK),
},
)
Expand Down Expand Up @@ -290,9 +286,7 @@ async def request_handler(request):
(StatusCode.ERROR, None),
{
SpanAttributes.HTTP_METHOD: "GET",
SpanAttributes.HTTP_URL: "http://{}:{}/test_timeout".format(
host, port
),
SpanAttributes.HTTP_URL: f"http://{host}:{port}/test_timeout",
},
)
]
Expand All @@ -319,9 +313,7 @@ async def request_handler(request):
(StatusCode.ERROR, None),
{
SpanAttributes.HTTP_METHOD: "GET",
SpanAttributes.HTTP_URL: "http://{}:{}/test_too_many_redirects".format(
host, port
),
SpanAttributes.HTTP_URL: f"http://{host}:{port}/test_too_many_redirects",
},
)
]
Expand Down Expand Up @@ -399,7 +391,7 @@ def test_instrument(self):
span = self.assert_spans(1)
self.assertEqual("GET", span.attributes[SpanAttributes.HTTP_METHOD])
self.assertEqual(
"http://{}:{}/test-path".format(host, port),
f"http://{host}:{port}/test-path",
span.attributes[SpanAttributes.HTTP_URL],
)
self.assertEqual(200, span.attributes[SpanAttributes.HTTP_STATUS_CODE])
Expand Down Expand Up @@ -502,13 +494,13 @@ def strip_query_params(url: yarl.URL) -> str:
)
span = self.assert_spans(1)
self.assertEqual(
"http://{}:{}/test-path".format(host, port),
f"http://{host}:{port}/test-path",
span.attributes[SpanAttributes.HTTP_URL],
)

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

def response_hook(
span: Span,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -152,8 +152,9 @@ def get_default_span_details(scope: dict) -> Tuple[str, dict]:
Returns:
a tuple of the span name, and any attributes to attach to the span.
"""
span_name = scope.get("path", "").strip() or "HTTP {}".format(
scope.get("method", "").strip()
span_name = (
scope.get("path", "").strip()
or f"HTTP {scope.get('method', '').strip()}"
)

return span_name, {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ def _common_request( # pylint: disable=too-many-locals
endpoint_name = getattr(instance, "host").split(".")[0]

with self._tracer.start_as_current_span(
"{}.command".format(endpoint_name), kind=SpanKind.CONSUMER,
f"{endpoint_name}.command", kind=SpanKind.CONSUMER,
) as span:
span.set_attribute("endpoint", endpoint_name)
if args:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
def assert_span_http_status_code(span, code):
"""Assert on the span's 'http.status_code' tag"""
tag = span.attributes[SpanAttributes.HTTP_STATUS_CODE]
assert tag == code, "%r != %r" % (tag, code)
assert tag == code, f"{tag} != {code}"


class TestBotoInstrumentor(TestBase):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ def _patched_api_call(self, original_func, instance, args, kwargs):
result = None

with self._tracer.start_as_current_span(
"{}".format(service_name), kind=SpanKind.CLIENT,
f"{service_name}", kind=SpanKind.CLIENT,
) as span:
# inject trace context into payload headers for lambda Invoke
if BotocoreInstrumentor._is_lambda_invoke(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ def _trace_prerun(self, *args, **kwargs):

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

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

operation_name = "{0}/{1}".format(_TASK_APPLY_ASYNC, task.name)
operation_name = f"{_TASK_APPLY_ASYNC}/{task.name}"
span = self._tracer.start_span(
operation_name, kind=trace.SpanKind.PRODUCER
)
Expand Down
Loading

0 comments on commit a0e4049

Please sign in to comment.