{"record":{"id":"ce9f02df9e18c38a","repo":"langgenius/dify","slug":"trace-config-is-exist","errorCode":"trace_config_is_exist","errorMessage":"Trace config is exist.","messagePattern":"Trace config is exist\\.","errorType":"error_code","errorClass":"TracingConfigIsExist","httpStatus":400,"severity":"warning","filePath":"api/controllers/console/app/ops_trace.py","lineNumber":117,"sourceCode":"    @console_ns.response(403, \"Insufficient permissions\")\n    @setup_required\n    @login_required\n    @account_initialization_required\n    @edit_permission_required\n    @rbac_permission_required(RBACResourceScope.APP, RBACPermission.APP_TRACING_CONFIG)\n    @get_app_model\n    @model_validate(TraceConfigPayload)\n    def post(self, req_data: TraceConfigPayload, app_model: App):\n        \"\"\"Create a new trace app configuration\"\"\"\n        try:\n            result = OpsService.create_tracing_app_config(\n                app_id=app_model.id,\n                tracing_provider=req_data.tracing_provider,\n                tracing_config=req_data.tracing_config,\n                session=db.session(),\n            )\n            if not result:\n                raise TracingConfigIsExist()\n            if result.get(\"error\"):\n                raise TracingConfigCheckError()\n            return result\n        except Exception as e:\n            raise BadRequest(str(e))\n\n    @console_ns.doc(\"update_trace_app_config\")\n    @console_ns.doc(description=\"Update an existing tracing configuration for an application\")\n    @console_ns.doc(params={\"app_id\": \"Application ID\"})\n    @console_ns.expect(console_ns.models[TraceConfigPayload.__name__])\n    @console_ns.response(\n        200,\n        \"Tracing configuration updated successfully\",\n        console_ns.models[TraceAppConfigResponse.__name__],\n    )\n    @console_ns.response(400, \"Invalid request parameters or configuration not found\")\n    @console_ns.response(403, \"Insufficient permissions\")\n    @setup_required","sourceCodeStart":99,"sourceCodeEnd":135,"githubUrl":"https://github.com/langgenius/dify/blob/ef8544b173fd6cd7a8e71df2cab576e52bebbfbc/api/controllers/console/app/ops_trace.py#L99-L135","documentation":"Raised as TracingConfigIsExist in POST /apps/{app_id}/ops-trace when OpsService.create_tracing_app_config returns a falsy result (api/controllers/console/app/ops_trace.py:116-117). The service returns falsy when a tracing config for the same app+provider already exists, so creation is refused to prevent duplicates. Note: the outer `except Exception as e: raise BadRequest(str(e))` ultimately surfaces this as a 400 with the message text.","triggerScenarios":"POSTing a trace config for an app+provider pair that already has a stored tracing config. The endpoint is idempotent-refusing — a second create for the same provider triggers it.","commonSituations":"Front-end re-submitting the create form after a successful save; integration test running twice without cleanup; user switching provider and re-creating instead of PATCHing; double-click on the save button.","solutions":["Use PATCH /apps/{app_id}/ops-trace to update the existing config instead of POSTing a new one.","DELETE the existing trace config first if you genuinely want to recreate it.","Guard the UI submit handler against double-submission (disable button on click).","Query the current trace config before deciding whether to POST or PATCH."],"exampleFix":"// before: always POST\nfetch(`/apps/${appId}/ops-trace`, {method:'POST', body: ...})\n// after: choose method by existence\nconst existing = await fetch(`/apps/${appId}/ops-trace?provider=${provider}`).then(r=>r.json())\nawait fetch(`/apps/${appId}/ops-trace`, {method: existing ? 'PATCH' : 'POST', body: ...})","handlingStrategy":"validation","validationCode":"// Decide POST vs PATCH based on existing config\nconst existing = await fetch(`/apps/${appId}/ops-trace?provider=${provider}`).then(r=>r.ok?r.json():null)\nconst method = existing ? 'PATCH' : 'POST'\nawait fetch(`/apps/${appId}/ops-trace`, {method, body: JSON.stringify(payload)})","typeGuard":null,"tryCatchPattern":"try {\n  await createTraceConfig(appId, payload)\n} catch (e) {\n  if (e.code === 'trace_config_is_exist') return patchTraceConfig(appId, payload)\n  throw e\n}","preventionTips":["Track whether a trace config already exists before offering 'create'.","Disable the submit button after click to prevent double POSTs."],"tags":["ops-trace","duplicate","tracing-config","api"],"backgroundTag":null,"analyzedSha":"ef8544b173fd6cd7a8e71df2cab576e52bebbfbc","analyzedAt":"2026-08-12T05:15:17.394Z","schemaVersion":2},"datasetVersion":"2026-08-12T13:17:24.610Z"}