Skip to content

Commit

Permalink
Merge pull request #1385 from garberg/nipapd_otel_proxy
Browse files Browse the repository at this point in the history
Fix trace proxy, improve logs
  • Loading branch information
garberg authored May 26, 2024
2 parents 893f0bc + 5612026 commit 7037dcb
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 7 deletions.
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

0 comments on commit 7037dcb

Please sign in to comment.