{"record":{"id":"ed3cb6c290eefe73","repo":"prestodb/presto","slug":"distributed-tracing-error","errorCode":"DISTRIBUTED_TRACING_ERROR","errorMessage":"Duplicated block inserted: ","messagePattern":"Duplicated block inserted: ","errorType":"error_code","errorClass":"PrestoException","httpStatus":null,"severity":"error","filePath":"presto-main-base/src/main/java/com/facebook/presto/tracing/SimpleTracer.java","lineNumber":52,"sourceCode":"    public final String traceToken;\n\n    public SimpleTracer(String traceToken)\n    {\n        this.traceToken = traceToken;\n        addPoint(\"Start tracing\");\n    }\n\n    @Override\n    public void addPoint(String annotation)\n    {\n        pointList.add(new SimpleTracerPoint(annotation));\n    }\n\n    @Override\n    public void startBlock(String blockName, String annotation)\n    {\n        if (blockMap.containsKey(blockName)) {\n            throw new PrestoException(DISTRIBUTED_TRACING_ERROR, \"Duplicated block inserted: \" + blockName);\n        }\n        SimpleTracerBlock block = new SimpleTracerBlock(annotation);\n        blockMap.put(blockName, block);\n        synchronized (recorderBlockMap) {\n            recorderBlockMap.put(blockName, block);\n        }\n    }\n\n    @Override\n    public void addPointToBlock(String blockName, String annotation)\n    {\n        if (!blockMap.containsKey(blockName)) {\n            throw new PrestoException(DISTRIBUTED_TRACING_ERROR, \"Adding point to non-existing block: \" + blockName);\n        }\n        blockMap.get(blockName).addPoint(new SimpleTracerPoint(annotation));\n    }\n\n    @Override","sourceCodeStart":34,"sourceCodeEnd":70,"githubUrl":"https://github.com/prestodb/presto/blob/55bb57d202de3b926896fa966c2c4a44c779634e/presto-main-base/src/main/java/com/facebook/presto/tracing/SimpleTracer.java#L34-L70","documentation":"SimpleTracer.startBlock registers a new tracing block by name in blockMap and recorderBlockMap. Block names must be unique within the tracer; inserting a name that already exists would silently overwrite live tracing data, so it is rejected with DISTRIBUTED_TRACING_ERROR.","triggerScenarios":"Calling startBlock(blockName, annotation) with a blockName that was already passed to startBlock and not yet removed by endBlock.","commonSituations":"Copy-pasted instrumentation code that reuses a hard-coded block name across iterations or threads; a retry path calling startBlock twice for the same logical block; forgetting endBlock before starting a same-named block.","solutions":["End the existing block with endBlock(blockName, annotation) before calling startBlock again","Use a unique block name (append a counter, iteration index, or UUID) for repeated blocks","Review instrumentation call sites flagged by the tracer to find the duplicate startBlock","Check for leaked blocks from earlier failures that were never ended"],"exampleFix":"// before\ntracer.startBlock(\"query-block\", annotation);\nfor (Stage stage : stages) {\n    tracer.startBlock(\"stage-block\", stageAnnotation); // duplicate\n}\n// after\nfor (Stage stage : stages) {\n    tracer.startBlock(\"stage-block-\" + stage.getId(), stageAnnotation);\n}","handlingStrategy":"try-catch","validationCode":"if (tracer instanceof SimpleTracer) {\n    // only start if not already started\n}\n// prefer tracking names yourself before calling:\nboolean canStart = !startedBlockNames.contains(blockName);","typeGuard":"boolean canStartBlock(SimpleTracer tracer, String blockName) {\n    return blockName != null && !startedBlockNames.contains(blockName);\n}","tryCatchPattern":"try {\n    tracer.startBlock(blockName, annotation);\n} catch (PrestoException e) {\n    if (e.getMessage().startsWith(\"Duplicated block inserted\")) {\n        LOG.warn(\"Block %s already started; skipping duplicate startBlock\", blockName);\n    } else {\n        throw e;\n    }\n}","preventionTips":["Generate unique block names for repeated or looped instrumentation","Always pair startBlock with endBlock, including on exception paths","Keep block names in shared constants to avoid case/typo mismatches","Avoid calling startBlock from both a retry wrapper and the retried code"],"tags":["tracing","distributed-tracing","instrumentation"],"backgroundTag":"duplicate-tracing-block","analyzedSha":"55bb57d202de3b926896fa966c2c4a44c779634e","analyzedAt":"2026-09-04T12:50:26.162Z","contentChangedAt":"2026-09-04T12:50:26.162Z","schemaVersion":2},"datasetVersion":"2026-09-11T21:17:09.523Z"}