From 49361fa97f4f120541974a0e163e97a65945e468 Mon Sep 17 00:00:00 2001 From: Gerry Agbobada Date: Wed, 11 Oct 2023 13:58:02 +0200 Subject: [PATCH] Use the full, cleaned up module name --- CHANGELOG.md | 3 +++ pkg/autometrics/instrument.go | 11 +++++------ 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8ed1f6e..413b087 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,9 @@ versioning](https://go.dev/doc/modules/version-numbers). ### Changed +- [All] autometrics now reports the fully qualified package name and cleans up the pointer + specifiers from reported pointer receiver methods + ### Deprecated ### Removed diff --git a/pkg/autometrics/instrument.go b/pkg/autometrics/instrument.go index 17b8982..5bc6db7 100644 --- a/pkg/autometrics/instrument.go +++ b/pkg/autometrics/instrument.go @@ -35,12 +35,11 @@ func CallerInfo() (callInfo CallInfo) { if index == -1 { callInfo.FuncName = functionName } else { - moduleIndex := strings.LastIndex(functionName[:index], ".") - if moduleIndex == -1 { - callInfo.ModuleName = functionName[:index] - } else { - callInfo.ModuleName = functionName[moduleIndex+1 : index] - } + callInfo.ModuleName = strings.ReplaceAll(strings.ReplaceAll(strings.ReplaceAll( + functionName[:index], + "(", ""), + ")", ""), + "*", "") callInfo.FuncName = functionName[index+1:] }