{"record":{"id":"c4880b3007ebcace","repo":"langgenius/dify","slug":"tracing-provider-is-required-when-enabled-is-true","errorCode":null,"errorMessage":"tracing_provider is required when enabled is True","messagePattern":"tracing_provider is required when enabled is True","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"api/controllers/console/app/app.py","lineNumber":213,"sourceCode":"\n\nclass AppSiteStatusPayload(BaseModel):\n    enable_site: bool = Field(..., description=\"Enable or disable site\")\n\n\nclass AppApiStatusPayload(BaseModel):\n    enable_api: bool = Field(..., description=\"Enable or disable API\")\n\n\nclass AppTracePayload(BaseModel):\n    enabled: bool = Field(..., description=\"Enable or disable tracing\")\n    tracing_provider: str | None = Field(default=None, description=\"Tracing provider\")\n\n    @field_validator(\"tracing_provider\")\n    @classmethod\n    def validate_tracing_provider(cls, value: str | None, info) -> str | None:\n        if info.data.get(\"enabled\") and not value:\n            raise ValueError(\"tracing_provider is required when enabled is True\")\n        return value\n\n\nclass AppTraceResponse(ResponseModel):\n    enabled: bool = False\n    tracing_provider: str | None = None\n\n\nclass Tag(ResponseModel):\n    id: str\n    name: str\n    type: str\n\n\nclass WorkflowPartial(ResponseModel):\n    id: str\n    created_by: str | None = None\n    created_at: int | None = None","sourceCodeStart":195,"sourceCodeEnd":231,"githubUrl":"https://github.com/langgenius/dify/blob/ef8544b173fd6cd7a8e71df2cab576e52bebbfbc/api/controllers/console/app/app.py#L195-L231","documentation":"Raised by AppTracePayload.validate_tracing_provider (Pydantic field_validator) when enabled is True but tracing_provider is None or empty. AppTracePayload backs the endpoint that toggles app-level tracing integration. Surfaces as a Pydantic ValidationError on the tracing config PUT/POST.","triggerScenarios":"Sending {enabled: true} (or with tracing_provider omitted/null/empty string) to enable tracing without naming a provider. The validator runs after the 'enabled' field is parsed, so it can read info.data.get('enabled').","commonSituations":"Frontend toggles the 'enable tracing' switch without selecting a provider from the dropdown; default provider state not initialized; malformed payload from a script that only sets the flag.","solutions":["Include a valid tracing_provider value (e.g., 'langfuse', 'langsmith', 'opik') whenever enabled is true.","If disabling, send {enabled: false} and tracing_provider can be omitted.","Make the UI require a provider selection before the enable toggle can be flipped on.","Validate the payload shape before submitting."],"exampleFix":"// before\naxios.put(`/apps/${id}/trace`, { enabled: true })\n\n// after\naxios.put(`/apps/${id}/trace`, { enabled: true, tracing_provider: 'langfuse' })","handlingStrategy":"validation","validationCode":"function buildTracePayload(enabled, provider) {\n  if (enabled && !provider) throw new Error('tracing_provider is required when enabled is true');\n  return { enabled, tracing_provider: enabled ? provider : provider ?? null };\n}","typeGuard":"const isProviderSetWhenEnabled = (p) => !p.enabled || (typeof p.tracing_provider === 'string' && p.tracing_provider.length > 0);","tryCatchPattern":"try { await axios.put(`/apps/${id}/trace`, payload); }\ncatch (e) { if (/tracing_provider is required/.test(e.message)) { /* prompt user to pick a provider */ } }","preventionTips":["Force the user to choose a provider before the enable toggle flips on.","Default the provider field to a known value in the UI.","Validate the payload client-side before submitting."],"tags":["apps","tracing","pydantic","validation","console-api"],"backgroundTag":null,"analyzedSha":"ef8544b173fd6cd7a8e71df2cab576e52bebbfbc","analyzedAt":"2026-08-12T05:15:17.394Z","schemaVersion":2},"datasetVersion":"2026-08-12T13:17:24.610Z"}