{"record":{"id":"550980c45df91f66","repo":"pinpoint-apm/pinpoint","slug":"unexpected-traceid-type-traceid","errorCode":null,"errorMessage":"Unexpected TraceId type: ${traceId}","messagePattern":"Unexpected TraceId type: (.+?)","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"agent-module/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/grpc/mapper/TraceIdMapStructUtils.java","lineNumber":50,"sourceCode":"public class TraceIdMapStructUtils {\n    @Qualifier\n    @Target(ElementType.METHOD)\n    @Retention(RetentionPolicy.CLASS)\n    public @interface ToTransactionId {\n    }\n\n    @ToTransactionId\n    public static PTransactionId newTransactionId(TraceId traceId) {\n        if (traceId instanceof DefaultTraceId) {\n            DefaultTraceId defaultTraceId = (DefaultTraceId) traceId;\n            TransactionId txId = defaultTraceId.getInternalTransactionId();\n            final PTransactionId.Builder builder = PTransactionId.newBuilder();\n            builder.setAgentId(txId.getAgentId());\n            builder.setAgentStartTime(txId.getAgentStartTime());\n            builder.setSequence(txId.getTransactionSequence());\n            return builder.build();\n        }\n        throw new IllegalArgumentException(\"Unexpected TraceId type: \" + traceId);\n    }\n}\n","sourceCodeStart":32,"sourceCodeEnd":53,"githubUrl":"https://github.com/pinpoint-apm/pinpoint/blob/744c3d3075e595656abb1ae331ad2c0e4c9eb996/agent-module/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/grpc/mapper/TraceIdMapStructUtils.java#L32-L53","documentation":"TraceIdMapStructUtils.newTransactionId converts a TraceId into a protobuf PTransactionId. It expects the traceId to be either a TransactionId (agentId/agentStartTime/transactionSequence fields) or a supported TraceId variant; any other runtime type reaches the final throw of IllegalArgumentException. This is a defensive check against passing the wrong TraceId implementation into the gRPC mapper.","triggerScenarios":"Calling newTransactionId (directly or via Span/TSpan mapping) with a TraceId implementation whose concrete type is not the expected TransactionId class — e.g. a custom TraceId, a mock, or a TraceId from a different profiler version/lineage.","commonSituations":"Custom trace implementations from plugins or test stubs; mixing pinpoint commons/profiler versions where TraceId interfaces changed; passing Span's traceId from a mocked/span-impl variant in unit tests into the gRPC mapper.","solutions":["Ensure the TraceId passed in is the profiler's TransactionId implementation (DefaultTransactionId) as produced by the trace context.","In tests, use the real TraceIdFactory/TransactionId instead of mock TraceId implementations.","Align Pinpoint component versions so the TraceId interface/implementation hierarchy matches the mapper's expectations.","Convert the custom TraceId to a TransactionId (agentId, agentStartTime, transactionSequence) before calling newTransactionId."],"exampleFix":"// before\nPTransactionId pId = TraceIdMapStructUtils.newTransactionId(mockTraceId);\n\n// after\nTraceId realTxId = traceContext.createTraceId(agentId, agentStartTime, transactionSequence);\nPTransactionId pId = TraceIdMapStructUtils.newTransactionId(realTxId);","handlingStrategy":"type-guard","validationCode":"if (!(traceId instanceof TransactionId)) {\n    throw new IllegalArgumentException(\"Expected TransactionId, got: \" + traceId.getClass());\n}","typeGuard":"static boolean isTransactionId(TraceId traceId) {\n    return traceId instanceof TransactionId\n            || (traceId.getAgentId() != null && traceId.getTransactionSequence() != null);\n}","tryCatchPattern":"try {\n    PTransactionId pId = TraceIdMapStructUtils.newTransactionId(traceId);\n} catch (IllegalArgumentException e) {\n    logger.warn(\"Unexpected TraceId implementation {}: {}\", traceId.getClass(), e.getMessage());\n    pId = buildPTransactionIdFromFields(traceId); // manual fallback\n}","preventionTips":["Obtain TraceId instances from the trace context/TraceIdFactory, not from mocks or custom implementations.","In tests, use DefaultTransactionId or a real factory instead of stubbing TraceId.","Keep pinpoint commons and profiler modules on matching versions so the TraceId hierarchy matches the mapper."],"tags":["java","grpc","type-mismatch","mapper","tracing"],"backgroundTag":"type-mismatch","analyzedSha":"744c3d3075e595656abb1ae331ad2c0e4c9eb996","analyzedAt":"2026-09-07T18:48:45.289Z","contentChangedAt":"2026-09-07T18:48:45.289Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}