Spaces:
Runtime error
Runtime error
Upload folder using huggingface_hub
Browse files- src/chatbot/app.py +13 -2
src/chatbot/app.py
CHANGED
|
@@ -33,7 +33,7 @@ if otel_endpoint:
|
|
| 33 |
enable_otel = True
|
| 34 |
else:
|
| 35 |
# Local development default
|
| 36 |
-
otel_endpoint = "https://
|
| 37 |
enable_otel = True
|
| 38 |
|
| 39 |
if enable_otel:
|
|
@@ -48,8 +48,19 @@ if enable_otel:
|
|
| 48 |
tracer_provider.add_span_processor(span_processor)
|
| 49 |
trace_api.set_tracer_provider(tracer_provider)
|
| 50 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 51 |
# Instrument the OpenAI Python library
|
| 52 |
-
OpenAIInstrumentor().instrument()
|
| 53 |
print(f"OpenTelemetry enabled with endpoint: {otel_endpoint}")
|
| 54 |
except Exception as e:
|
| 55 |
print(f"Failed to initialize OpenTelemetry: {e}")
|
|
|
|
| 33 |
enable_otel = True
|
| 34 |
else:
|
| 35 |
# Local development default
|
| 36 |
+
otel_endpoint = "https://myotel.azurewebsites.net/v1/traces"
|
| 37 |
enable_otel = True
|
| 38 |
|
| 39 |
if enable_otel:
|
|
|
|
| 48 |
tracer_provider.add_span_processor(span_processor)
|
| 49 |
trace_api.set_tracer_provider(tracer_provider)
|
| 50 |
|
| 51 |
+
# Custom hook to filter out Omit/NotGiven types from attributes
|
| 52 |
+
def request_hook(span, kwargs):
|
| 53 |
+
if span and span.is_recording():
|
| 54 |
+
for key, value in kwargs.items():
|
| 55 |
+
# Check for "Omit" or "NotGiven" types which OTEL can't serialize
|
| 56 |
+
type_name = type(value).__name__
|
| 57 |
+
if type_name in ["Omit", "NotGiven"]:
|
| 58 |
+
# Setup correct attribute name expected by semantic conventions or just use key
|
| 59 |
+
# The instrumentation might use gen_ai.request.{key}
|
| 60 |
+
span.set_attribute(f"gen_ai.request.{key}", str(value))
|
| 61 |
+
|
| 62 |
# Instrument the OpenAI Python library
|
| 63 |
+
OpenAIInstrumentor().instrument(request_hook=request_hook)
|
| 64 |
print(f"OpenTelemetry enabled with endpoint: {otel_endpoint}")
|
| 65 |
except Exception as e:
|
| 66 |
print(f"Failed to initialize OpenTelemetry: {e}")
|