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

Fix trace proxy, improve logs #1385

Merged
merged 1 commit into from
May 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
20 changes: 17 additions & 3 deletions nipap/nipap/tracing.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import inspect
from functools import wraps

from flask import request
from flask import request, abort

from opentelemetry import trace, context
from opentelemetry.trace import SpanKind, StatusCode
Expand Down Expand Up @@ -34,9 +34,23 @@ def init_tracing(service_name, endpoint, sampler, use_grpc=True):


def setup(app, endpoint):
""" Set up an endpoint which proxies traces to the OpenTelemetry receiver.

This can be used by for example the NIPAP CLI.
"""
@app.route('/v1/traces/', defaults={'path': ''}, methods=["POST"])
def proxy(path):
return post(f'{endpoint}{path}', data=request.data, headers=request.headers).content

# Remove Host-header as it's set to the host running nipapd.
headers = {k: v for k, v in request.headers}
headers.pop("Host", None)
res = post(f'{endpoint}{path}', data=request.data, headers=headers)

# Check result and abort with error if not successful
if res.status_code >= 400:
abort(res.status_code, description=res.text)

return res.content


def create_span(f):
Expand Down Expand Up @@ -159,4 +173,4 @@ def create_span_authenticate(f):
@wraps(f)
def decorated(*args, **kwargs):
return f(*args, **kwargs)
return decorated
return decorated
9 changes: 5 additions & 4 deletions nipap/nipapd
Original file line number Diff line number Diff line change
Expand Up @@ -257,13 +257,14 @@ if __name__ == '__main__':
try:
setup(app, cfg.get("tracing", "otlp_http_endpoint"))
except configparser.NoOptionError:
logger.info('Found no OTLP HTTP endpoint, OTLP proxy disabled')
pass
logger.debug('Tracing is enabled')
logger.debug('Tracing is enabled and successfully set up')
except KeyError:
logger.error('Error in tracing configuration. No tracing enabled')
logger.error('Error in tracing configuration, tracing not enabled')
pass
except ImportError:
logger.error('Failed to import tracing libraries. Check dependencies. No tracing enabled')
except ImportError as err:
logger.error('Failed to import tracing library %s, tracing not enabled', err.name)
pass
else:
logger.debug('Tracing is disabled')
Expand Down
Loading