Skip to content

Commit

Permalink
feat: log opentelemetry trace and span ids (#57)
Browse files Browse the repository at this point in the history
* Log opentelemetry trace and span ids.
  • Loading branch information
Oleksii-Klimov authored Jan 17, 2024
1 parent 7f3fa06 commit c725a33
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
8 changes: 6 additions & 2 deletions aidial_assistant/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,15 @@
tools_supporting_deployments: set[str] = set(
os.getenv("TOOLS_SUPPORTING_DEPLOYMENTS", "").split(",")
)
otel_logging_enabled: bool = True

logging.config.dictConfig(get_log_config(log_level))

logging.config.dictConfig(get_log_config(log_level, otel_logging_enabled))

telemetry_config = TelemetryConfig(
tracing=TracingConfig(otlp_export=otlp_export_enabled, logging=True),
tracing=TracingConfig(
otlp_export=otlp_export_enabled, logging=otel_logging_enabled
),
)
app = DIALApp(telemetry_config=telemetry_config)

Expand Down
9 changes: 7 additions & 2 deletions aidial_assistant/utils/log_config.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
def get_log_config(log_level: str) -> dict:
def get_log_config(log_level: str, otel_logging: bool) -> dict:
otel_prefix_fmt = (
"[trace_id=%(otelTraceID)s span_id=%(otelSpanID)s] - "
if otel_logging
else ""
)
return {
"version": 1,
"disable_existing_loggers": False,
"formatters": {
"default": {
"()": "uvicorn.logging.DefaultFormatter",
"fmt": "%(levelprefix)s | %(asctime)s | %(name)s | %(process)d | %(message)s",
"fmt": f"%(levelprefix)s | %(asctime)s | %(name)s | %(process)d | {otel_prefix_fmt}%(message)s",
"datefmt": "%Y-%m-%d %H:%M:%S",
"use_colors": True,
},
Expand Down

0 comments on commit c725a33

Please sign in to comment.