mirror of
https://github.com/inventree/InvenTree.git
synced 2026-04-12 06:18:48 +00:00
feat(frontend): Add better frontend tracing (#11244)
* add better tracing through the frontend * extend allowed headers * add endpoint to end the trace * end traces correctly in backend * end trace * early cop-out if not tracing is enabled * Update API version link for v447
This commit is contained in:
@@ -1,11 +1,14 @@
|
||||
"""InvenTree API version information."""
|
||||
|
||||
# InvenTree API version
|
||||
INVENTREE_API_VERSION = 452
|
||||
INVENTREE_API_VERSION = 453
|
||||
"""Increment this API version number whenever there is a significant change to the API that any clients need to know about."""
|
||||
|
||||
INVENTREE_API_TEXT = """
|
||||
|
||||
v453 -> 2026-02-11 : https://github.com/inventree/InvenTree/pull/11244
|
||||
- Adds (internal) endpoint to end a observability tooling session
|
||||
|
||||
v452 -> 2026-02-10 : https://github.com/inventree/InvenTree/pull/11276
|
||||
- Adds "install_into_detail" field to the BuildItem API endpoint
|
||||
|
||||
|
||||
@@ -1289,10 +1289,12 @@ CORS_ALLOWED_ORIGIN_REGEXES = get_setting(
|
||||
typecast=list,
|
||||
)
|
||||
|
||||
_allowed_headers = (*default_cors_headers, 'traceparent')
|
||||
# Allow extra CORS headers in DEBUG mode
|
||||
# Required for serving /static/ and /media/ files
|
||||
if DEBUG:
|
||||
CORS_ALLOW_HEADERS = (*default_cors_headers, 'cache-control', 'pragma', 'expires')
|
||||
_allowed_headers = (*_allowed_headers, 'cache-control', 'pragma', 'expires')
|
||||
CORS_ALLOW_HEADERS = _allowed_headers
|
||||
|
||||
# In debug mode allow CORS requests from localhost
|
||||
# This allows connection from the frontend development server
|
||||
|
||||
@@ -22,6 +22,7 @@ from django_q.tasks import async_task
|
||||
from djmoney.contrib.exchange.models import ExchangeBackend, Rate
|
||||
from drf_spectacular.utils import OpenApiResponse, extend_schema
|
||||
from error_report.models import Error
|
||||
from opentelemetry import trace
|
||||
from pint._typing import UnitLike
|
||||
from rest_framework import generics, serializers
|
||||
from rest_framework.exceptions import NotAcceptable, NotFound, PermissionDenied
|
||||
@@ -1115,6 +1116,50 @@ class HealthCheckView(APIView):
|
||||
)
|
||||
|
||||
|
||||
class ObservabilityEndSerializer(serializers.Serializer):
|
||||
"""Serializer for observability end endpoint."""
|
||||
|
||||
traceid = serializers.CharField(
|
||||
help_text='Trace ID to end', max_length=128, required=True
|
||||
)
|
||||
service = serializers.CharField(
|
||||
help_text='Service name', max_length=128, required=True
|
||||
)
|
||||
|
||||
|
||||
class ObservabilityEnd(CreateAPI):
|
||||
"""Endpoint for observability tools."""
|
||||
|
||||
permission_classes = [AllowAnyOrReadScope]
|
||||
serializer_class = ObservabilityEndSerializer
|
||||
|
||||
def create(self, request, *args, **kwargs):
|
||||
"""End a trace in the observability system."""
|
||||
if not settings.TRACING_ENABLED:
|
||||
return Response({'status': 'ok'})
|
||||
|
||||
data = self.get_serializer(data=request.data)
|
||||
data.is_valid(raise_exception=True)
|
||||
|
||||
traceid = data.validated_data['traceid']
|
||||
# service = data.validated_data['service'] # This will become interesting with frontend observability
|
||||
|
||||
# End the foreign trend via the low level otel API
|
||||
tracer = trace.get_tracer(__name__)
|
||||
span_context = trace.SpanContext(
|
||||
trace_id=int(traceid, 16),
|
||||
span_id=0,
|
||||
is_remote=True,
|
||||
trace_flags=trace.TraceFlags(0x01),
|
||||
trace_state=trace.TraceState(),
|
||||
)
|
||||
with tracer.start_span('Ending session') as span:
|
||||
span.add_event('Ending external trace')
|
||||
span.add_link(span_context)
|
||||
|
||||
return Response({'status': 'ok'})
|
||||
|
||||
|
||||
selection_urls = [
|
||||
path(
|
||||
'<int:pk>/',
|
||||
@@ -1393,7 +1438,22 @@ common_api_urls = [
|
||||
# System APIs (related to basic system functions)
|
||||
path(
|
||||
'system/',
|
||||
include([path('health/', HealthCheckView.as_view(), name='api-system-health')]),
|
||||
include([
|
||||
# Health check
|
||||
path('health/', HealthCheckView.as_view(), name='api-system-health')
|
||||
]),
|
||||
),
|
||||
# Internal System APIs - DO NOT USE
|
||||
path(
|
||||
'system-internal/',
|
||||
include([
|
||||
# Observability
|
||||
path(
|
||||
'observability/end',
|
||||
ObservabilityEnd.as_view(),
|
||||
name='api-system-observability',
|
||||
)
|
||||
]),
|
||||
),
|
||||
]
|
||||
|
||||
|
||||
Reference in New Issue
Block a user