pinpoint-apm/pinpoint · warning

TraceBlock already begin. trace=

Error message

TraceBlock already begin. trace={}

What it means

DefaultTraceBlock.begin() logs 'TraceBlock already begin. trace={}' when begin() is called on a block that was already marked as begun. The method guards its `begin` flag and returns without calling trace.traceBlockBegin() again, so the second begin is silently skipped. This is a usage-order problem with DefaultTraceBlock helper objects.

Solutions

  1. Create a new DefaultTraceBlock instance for each instrumentation section instead of reusing one
  2. Call end() before calling begin() again on the same block
  3. Restructure re-entrant/instrumented code so each begin/end pair is balanced per invocation
  4. If this appears with recursion, use a separate block per stack frame

Example fix

// before
DefaultTraceBlock block = new DefaultTraceBlock(trace);
block.begin();
a();
block.begin(); // warns already begin
b();
block.end();
// after
DefaultTraceBlock b1 = new DefaultTraceBlock(trace);
b1.begin(); a(); b1.end();
DefaultTraceBlock b2 = new DefaultTraceBlock(trace);
b2.begin(); b(); b2.end();
Defensive patterns

Strategy: type-guard

Validate before calling

if (!block.isBegin()) { block.begin(); }

Type guard

boolean canBegin(DefaultTraceBlock b) { return b != null && !b.isBegin(); }

Try / catch

if (block.isBegin()) { logger.warn("block already begun, skipping"); } else { block.begin(); }

Prevention

When it happens

Trigger: Reusing a DefaultTraceBlock instance and calling begin() twice without an intervening end(); wrapping overlapping code regions with the same block object; a begin() call retried after a previous begin already succeeded.

Common situations: Application or plugin code using DefaultTraceBlock helpers around nested/re-entrant methods; copy-pasted instrumentation where one block object wraps two sequential sections but begin() was called for both; re-entrant method interception.

Understand the failure class

Background: "Invalid state transition" errors: "status must be X, actually Y", "already rejected/charging/uninstalled", "cannot ... while running" — what they mean when a library rejects your call — this error's family across 31 libraries.

Related errors


AI-assisted analysis of pinpoint-apm/pinpoint@744c3d3075 (2026-09-07). Data as JSON: /api/errors/ac5be318c31dc934. Report an issue: GitHub.

Appendix: source

Thrown at agent-module/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/DefaultTraceBlock.java:60

    private boolean begin;

    public DefaultTraceBlock(Trace trace) {
        this.trace = Objects.requireNonNull(trace, "trace");
    }

    @Override
    public void close() {
        // AutoCloseable
        if (begin) {
            trace.traceBlockEnd();
        }
    }

    @Override
    public void begin() {
        if (begin) {
            if (logger.isWarnEnabled()) {
                logger.warn("TraceBlock already begin. trace={}", trace);
            }
            return;
        }
        trace.traceBlockBegin();
        begin = true;
    }

    public boolean isBegin() {
        return begin;
    }

    @Override
    public Trace getTrace() {
        return trace;
    }

    @Override
    public ParsingResult recordSqlInfo(String sql) {

View on GitHub (pinned to 744c3d3075)