{"record":{"id":"204a575fae182232","repo":"temporalio/temporal","slug":"failed-to-get-caller-info-for-metric-definition","errorCode":null,"errorMessage":"failed to get caller info for metric definition","messagePattern":"failed to get caller info for metric definition","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"common/metrics/defs_base.debug.go","lineNumber":26,"sourceCode":"\n// metricDefinition contains the definition for a metric\ntype metricDefinition struct {\n\tname        string\n\tdescription string\n\tunit        MetricUnit\n\tfile        string\n\tline        int\n}\n\nfunc newMetricDefinition(name string, opts ...Option) metricDefinition {\n\td := metricDefinition{\n\t\tname:        name,\n\t\tdescription: \"\",\n\t\tunit:        \"\",\n\t}\n\t_, file, line, ok := runtime.Caller(2)\n\tif !ok {\n\t\tpanic(\"failed to get caller info for metric definition\")\n\t}\n\td.file = file\n\td.line = line\n\tfor _, opt := range opts {\n\t\topt.apply(&d)\n\t}\n\treturn d\n}\n\nfunc (md metricDefinition) Name() string {\n\treturn md.name\n}\n\nfunc (md metricDefinition) Unit() MetricUnit {\n\treturn md.unit\n}\n\nfunc (md metricDefinition) File() string {","sourceCodeStart":8,"sourceCodeEnd":44,"githubUrl":"https://github.com/temporalio/temporal/blob/bde624efd13fbd3843654058db6d9c716166318b/common/metrics/defs_base.debug.go#L8-L44","documentation":"newMetricDefinition uses runtime.Caller(2) to record the source file and line where a metric was declared, for debugging/metric-attribution purposes. If runtime.Caller fails to walk the stack (extremely rare; can happen with inlined or manipulated stacks, e.g. runtime tricks, -gcflags=-l mismatches, or calling via reflect/assembly wrappers), the library panics. It is a programmer-error invariant, not a runtime condition.","triggerScenarios":"Defining a metric via newMetricDefinition (any metric definition constructor) in a context where runtime.Caller(2) returns ok=false — practically only when the call stack is shorter than expected or the code path is invoked through non-standard stack manipulation.","commonSituations":"Refactoring metric definition helpers so the stack depth no longer matches the hardcoded Caller(2) offset; unusual build flags affecting inlining; exotic code generation wrappers.","solutions":["Check that metric definitions are created directly through the provided constructor/vars helpers, not through extra intermediate wrappers that shift the stack depth","If you added a wrapper layer, adjust the runtime.Caller depth in defs_base.debug.go accordingly","Rebuild without nonstandard compiler flags that may suppress inlining assumptions","Report upstream if it reproduces with stock metric definition calls"],"exampleFix":"// before\n_, file, line, ok := runtime.Caller(2)\nif !ok {\n\tpanic(\"failed to get caller info for metric definition\")\n}\n// after\n_, file, line, ok := runtime.Caller(1) // depth adjusted for new wrapper layer\nif !ok {\n\tfile, line = \"unknown\", 0 // degrade gracefully instead of panicking\n}","handlingStrategy":"fallback","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":["Create metric definitions only through the provided package helpers so the stack-depth assumption in runtime.Caller(2) holds","Avoid adding intermediate wrapper functions around metric definition constructors","Avoid nonstandard build flags that change inlining around metric definitions"],"tags":["go","runtime","metrics","panic"],"backgroundTag":"runtime-caller-failed","analyzedSha":"bde624efd13fbd3843654058db6d9c716166318b","analyzedAt":"2026-09-01T07:18:39.080Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}