Skip to content
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
1 change: 1 addition & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ jobs:
OTEL_SERVICE_NAME: test-service
OTEL_EXPORTER_OTLP_ENDPOINT: http://localhost:4317
GCP_PROJECT_ID: test-project
TELEMETRY_ENABLED: false
run: |
poetry run pytest --cov=app --cov-report=xml

Expand Down
3 changes: 2 additions & 1 deletion app/core/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ class Settings(BaseSettings):
DATABASE_URL: str

# OpenTelemetry
TELEMETRY_ENABLED: bool = True # Set to False in tests to avoid connection errors
OTEL_SERVICE_NAME: str = "clestiq-shield-api"
OTEL_EXPORTER_OTLP_ENDPOINT: str = "http://otel-collector:4317"

Expand All @@ -28,7 +29,7 @@ class Settings(BaseSettings):
SECURITY_XSS_PROTECTION_ENABLED: bool = True
SECURITY_SQL_INJECTION_DETECTION_ENABLED: bool = True
SECURITY_COMMAND_INJECTION_DETECTION_ENABLED: bool = True
SECURITY_LLM_CHECK_THRESHOLD: float = 0.85 # Block if security_score > this value
SECURITY_LLM_CHECK_THRESHOLD: float = 0.85


class Config:
Expand Down
18 changes: 18 additions & 0 deletions app/core/telemetry.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,24 @@ def add_open_telemetry_spans(_, __, event_dict):
return event_dict

def setup_telemetry(app):
# Skip telemetry setup if disabled (e.g., in test environments)
if not settings.TELEMETRY_ENABLED:
log = structlog.get_logger()
log.info("Telemetry disabled, skipping OpenTelemetry initialization")

# Still configure basic structlog for tests
structlog.configure(
processors=[
structlog.contextvars.merge_contextvars,
structlog.processors.add_log_level,
structlog.processors.TimeStamper(fmt="iso"),
structlog.processors.JSONRenderer()
],
logger_factory=structlog.stdlib.LoggerFactory(),
cache_logger_on_first_use=True,
)
return

resource = Resource.create({
ResourceAttributes.SERVICE_NAME: settings.OTEL_SERVICE_NAME,
})
Expand Down
1 change: 1 addition & 0 deletions docker-compose.test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ services:
- GCP_LOCATION=us-east1
- SECURITY_SANITIZATION_ENABLED=true
- SECURITY_PII_REDACTION_ENABLED=true
- TELEMETRY_ENABLED=false
- SECURITY_XSS_PROTECTION_ENABLED=true
- SECURITY_SQL_INJECTION_DETECTION_ENABLED=true
- SECURITY_COMMAND_INJECTION_DETECTION_ENABLED=true
Expand Down