Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Aleksei.lesieur/opentelemetry #818

Closed
wants to merge 61 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
61 commits
Select commit Hold shift + click to select a range
a3310f3
Initial thrift otel
trevorriles Sep 18, 2023
983f4a4
Add thrift client support
trevorriles Sep 18, 2023
88864dd
remove unused function
trevorriles Sep 18, 2023
669461b
instrument http
trevorriles Sep 18, 2023
d959822
Restore old functionality
trevorriles Sep 20, 2023
6e2617b
Remove duplicate start_time
trevorriles Sep 20, 2023
b0c6795
refactor status import
trevorriles Sep 20, 2023
632181a
additional fixes for the tests and libraries
trevorriles Sep 20, 2023
a6d6fa8
black linting applied
trevorriles Sep 20, 2023
d3d1498
Initialize opentelemetry exporter
trevorriles Sep 21, 2023
69c3436
Fix tests, support dropping headers from untrusted sources
trevorriles Sep 21, 2023
f09b4e0
require service_name in trace config
trevorriles Sep 21, 2023
19a196b
Add deps to setup.py
trevorriles Sep 21, 2023
bd9d51e
Fix trace service.name config
trevorriles Sep 21, 2023
a4d571f
fix sampling
trevorriles Sep 21, 2023
b0e0e9d
sampling fixes
trevorriles Sep 21, 2023
0ed5261
Set a fake version for testing
trevorriles Sep 21, 2023
86b2d18
Remove trust header logic for now
trevorriles Sep 21, 2023
b236aaf
add debug logging
trevorriles Sep 21, 2023
52d1425
Tweak how we access headers
trevorriles Sep 22, 2023
9a32983
reformat thrift logic
trevorriles Sep 22, 2023
3e5b378
fixup header errors
trevorriles Sep 22, 2023
08a6558
Correctly initiate dict
trevorriles Sep 22, 2023
10b974c
Change thrift server header extraction
trevorriles Sep 22, 2023
892fd91
Add log lines
trevorriles Sep 22, 2023
cfb006d
typo
trevorriles Sep 22, 2023
273f862
Revert "Change thrift server header extraction"
trevorriles Sep 22, 2023
46ad0f3
Better handling of non utf-8 header
trevorriles Sep 23, 2023
1591025
Fix header handling
trevorriles Sep 23, 2023
4453e1c
Add debugging line
trevorriles Sep 24, 2023
b3e216a
Remove bad logging line
trevorriles Sep 25, 2023
7e11282
Push breakpoint for debugging
trevorriles Sep 25, 2023
f0f81a7
move breakpoint
trevorriles Sep 25, 2023
c0fc1ae
remvoe breakpoint
trevorriles Sep 25, 2023
d182382
feat: Add rpc specific attributes to thrift client
Xaelias Oct 25, 2023
324097f
feat: First implementation of thrift server otel
Xaelias Nov 3, 2023
d9d3791
fix: Use typing for Dict type annotation
trevorriles Nov 16, 2023
d7fbe1d
fix: adhoc: Thrift otel implementation
Xaelias Nov 21, 2023
a7e2f7c
fix: adhoc: Use `socket` package to get client IP/fqdn and use NET_*_…
Xaelias Nov 22, 2023
0f5c3cc
remove otel trust headers
Xaelias Dec 4, 2023
96856d2
Migrate handling of headers to use otel propagators
trevorriles Nov 29, 2023
1ddcfa2
refactor _extract_first_element
trevorriles Nov 30, 2023
3234c00
Fixes for PR
trevorriles Nov 30, 2023
fc7c55d
Fix optional type to include module
trevorriles Dec 1, 2023
b58a37c
use default in _extract_first_element
Xaelias Dec 5, 2023
08db6c3
add tests for b3 vs. otel headers acceptance in pyramid/thrift server
Xaelias Dec 5, 2023
0e2a1b0
some light test rewritting
Xaelias Dec 6, 2023
20da8e2
feat: adhoc: Log trace IDs for recording spans
Xaelias Dec 6, 2023
f8bba3e
lint + trying to fix requirements error in 3.7
Xaelias Dec 13, 2023
c51d232
trying to fix requirements for 3.7
Xaelias Dec 13, 2023
be2856e
remove all f"{...=}" from logs
Xaelias Dec 13, 2023
c3803cd
more fixes
Xaelias Dec 18, 2023
d03871b
back to scm verison
Xaelias Dec 18, 2023
90d03b9
Remove support for python 3.7, addn python 3.10 and 3.11
Xaelias Dec 18, 2023
c1133bd
3.10 vs 3.1
Xaelias Dec 18, 2023
abc48f9
fix deps
Xaelias Dec 18, 2023
dac9893
no 3.11
Xaelias Dec 18, 2023
c5dcaae
no 3.10
Xaelias Dec 18, 2023
42e6183
typing
Xaelias Dec 18, 2023
79f7ab8
typing
Xaelias Dec 18, 2023
af5f243
hardcode trace_id in log_formatter test to make sure we have the full…
Xaelias Dec 19, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/python-package.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: [3.7, 3.8, 3.9]
python-version: [3.8, 3.9]

container:
image: python:${{ matrix.python-version }}
Expand Down
6 changes: 3 additions & 3 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,19 @@ repos:
name: make-fmt
stages: [commit]
language: system
entry: docker-compose run baseplate make fmt
entry: docker compose run --no-TTY baseplate make fmt
always_run: true
- id: make-lint
name: make-lint
stages: [push]
language: system
entry: docker-compose run baseplate make lint
entry: docker compose run --no-TTY baseplate make lint
always_run: true
fail_fast: true
- id: pytest
name: pytest
stages: [push]
language: system
entry: docker-compose run baseplate pytest
entry: docker compose run --no-TTY baseplate pytest
always_run: true
fail_fast: true
1 change: 1 addition & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ WORKDIR /src
ENV CASS_DRIVER_NO_EXTENSIONS theytaketoolongtobuild

COPY requirements*.txt ./
RUN apt-get -y update && apt-get -y install librdkafka-dev && rm -rf /var/lib/apt/lists/*
RUN pip install -r requirements.txt

RUN touch /baseplate-py-dev-docker-image
Expand Down
4 changes: 4 additions & 0 deletions baseplate/clients/requests.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

from advocate import AddrValidator
from advocate import ValidatingHTTPAdapter
from opentelemetry.instrumentation.requests import RequestsInstrumentor
from prometheus_client import Counter
from prometheus_client import Gauge
from prometheus_client import Histogram
Expand All @@ -26,6 +27,9 @@
from baseplate.lib.prometheus_metrics import getHTTPSuccessLabel


RequestsInstrumentor().instrument()


def http_adapter_from_config(
app_config: config.RawConfig, prefix: str, **kwargs: Any
) -> HTTPAdapter:
Expand Down
288 changes: 178 additions & 110 deletions baseplate/clients/thrift.py

Large diffs are not rendered by default.

31 changes: 23 additions & 8 deletions baseplate/frameworks/pyramid/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
import pyramid.tweens
import webob.request

from opentelemetry import trace
from opentelemetry.instrumentation.pyramid import PyramidInstrumentor
from prometheus_client import Counter
from prometheus_client import Gauge
from prometheus_client import Histogram
Expand All @@ -35,10 +37,12 @@
from baseplate.thrift.ttypes import IsHealthyProbe


PyramidInstrumentor().instrument()

logger = logging.getLogger(__name__)


class SpanFinishingAppIterWrapper:
class SpanFinishingAppIterWrapper(Iterable):
"""Wrapper for Response.app_iter that finishes the span when the iterator is done.

The WSGI spec expects applications to return an iterable object. In the
Expand All @@ -53,7 +57,7 @@ class SpanFinishingAppIterWrapper:

"""

def __init__(self, span: Span, app_iter: Iterable[bytes]) -> None:
def __init__(self, app_iter: Iterator[bytes], span: Optional[Span] = None) -> None:
self.span = span
self.app_iter = iter(app_iter)

Expand All @@ -64,10 +68,15 @@ def __next__(self) -> bytes:
try:
return next(self.app_iter)
except StopIteration:
self.span.finish()
trace.get_current_span().set_status(trace.status.StatusCode.OK)
if self.span:
self.span.finish()
raise
except: # noqa: E722
self.span.finish(exc_info=sys.exc_info())
except Exception as e: # noqa: E722
trace.get_current_span().set_status(trace.status.StatusCode.ERROR)
trace.get_current_span().record_exception(e)
if self.span:
self.span.finish(exc_info=sys.exc_info())
raise

def close(self) -> None:
Expand Down Expand Up @@ -129,15 +138,21 @@ def baseplate_tween(request: Request) -> Response:
response = handler(request)
if request.span:
request.span.set_tag("http.response_length", response.content_length)
except: # noqa: E722
except Exception as e: # noqa: E722
trace.get_current_span().set_status(trace.status.StatusCode.ERROR)
trace.get_current_span().record_exception(e)
if hasattr(request, "span") and request.span:
request.span.finish(exc_info=sys.exc_info())
raise
else:
trace.get_current_span().set_status(trace.status.StatusCode.OK)
content_length = response.content_length
if request.span:
request.span.set_tag("http.status_code", response.status_code)
content_length = response.content_length
response.app_iter = SpanFinishingAppIterWrapper(request.span, response.app_iter)
response.app_iter = SpanFinishingAppIterWrapper(response.app_iter, request.span)
response.content_length = content_length
else:
response.app_iter = SpanFinishingAppIterWrapper(response.app_iter)
response.content_length = content_length
finally:
manually_close_request_metrics(request, response)
Expand Down
Loading
Loading