From bf2389df457c575b82d75e181e8269d965e5666b Mon Sep 17 00:00:00 2001 From: Joshua Wise Date: Tue, 21 Mar 2023 16:03:52 -0700 Subject: [PATCH] feat: Allow some non-Golang interfaces to be passed through in Events. Some users may wish to use sentry-go as a mechanism to proxy non-Golang events -- for instance, if reporting errors from a mobile or web application. We add Sentry event payload interfaces that make it easier to support other platforms, including stack frame interface members for "C-like" applications, and including the Debug Meta interface that allows the Sentry backend to symbolicate application backtraces. This change was authored under contract for FullStory. --- interfaces.go | 29 +++++++++++++++++++++++++++++ stacktrace.go | 20 +++++++++++++------- 2 files changed, 42 insertions(+), 7 deletions(-) diff --git a/interfaces.go b/interfaces.go index 5bdaa49bb..91c5e476e 100644 --- a/interfaces.go +++ b/interfaces.go @@ -241,6 +241,34 @@ type TransactionInfo struct { Source TransactionSource `json:"source,omitempty"` } +// The DebugMeta interface is not used in Golang apps, but may be populated +// when proxying Events from other platforms, like iOS, Android, and the +// Web. (See: https://develop.sentry.dev/sdk/event-payloads/debugmeta/ ). +type DebugMeta struct { + SdkInfo *DebugMetaSdkInfo `json:"sdk_info,omitempty"` + Images []DebugMetaImage `json:"images,omitempty"` +} + +type DebugMetaSdkInfo struct { + SdkName string `json:"sdk_name,omitempty"` + VersionMajor int `json:"version_major,omitempty"` + VersionMinor int `json:"version_minor,omitempty"` + VersionPatchlevel int `json:"version_patchlevel,omitempty"` +} + +type DebugMetaImage struct { + Type string `json:"type,omitempty"` // all + ImageAddr string `json:"image_addr,omitempty"` // macho,elf,pe + ImageSize int `json:"image_size,omitempty"` // macho,elf,pe + DebugID string `json:"debug_id,omitempty"` // macho,elf,pe,wasm,sourcemap + DebugFile string `json:"debug_file,omitempty"` // macho,elf,pe,wasm + CodeID string `json:"code_id,omitempty"` // macho,elf,pe,wasm + CodeFile string `json:"code_file,omitempty"` // macho,elf,pe,wasm,sourcemap + ImageVmaddr string `json:"image_vmaddr,omitempty"` // macho,elf,pe + Arch string `json:"arch,omitempty"` // macho,elf,pe + UUID string `json:"uuid,omitempty"` // proguard +} + // EventID is a hexadecimal string representing a unique uuid4 for an Event. // An EventID must be 32 characters long, lowercase and not have any dashes. type EventID string @@ -271,6 +299,7 @@ type Event struct { Modules map[string]string `json:"modules,omitempty"` Request *Request `json:"request,omitempty"` Exception []Exception `json:"exception,omitempty"` + DebugMeta *DebugMeta `json:"debug_meta,omitempty"` // The fields below are only relevant for transactions. diff --git a/stacktrace.go b/stacktrace.go index 8c256ec98..c3c5f5d55 100644 --- a/stacktrace.go +++ b/stacktrace.go @@ -166,13 +166,7 @@ type Frame struct { Symbol string `json:"symbol,omitempty"` // Module is, despite the name, the Sentry protocol equivalent of a Go // package's import path. - Module string `json:"module,omitempty"` - // Package is not used for Go stack trace frames. In other platforms it - // refers to a container where the Module can be found. For example, a - // Java JAR, a .NET Assembly, or a native dynamic library. - // It exists for completeness, allowing the construction and reporting - // of custom event payloads. - Package string `json:"package,omitempty"` + Module string `json:"module,omitempty"` Filename string `json:"filename,omitempty"` AbsPath string `json:"abs_path,omitempty"` Lineno int `json:"lineno,omitempty"` @@ -182,6 +176,18 @@ type Frame struct { PostContext []string `json:"post_context,omitempty"` InApp bool `json:"in_app,omitempty"` Vars map[string]interface{} `json:"vars,omitempty"` + // Package and the below are not used for Go stack trace frames. In + // other platforms it refers to a container where the Module can be + // found. For example, a Java JAR, a .NET Assembly, or a native + // dynamic library. They exists for completeness, allowing the + // construction and reporting of custom event payloads. + Package string `json:"package,omitempty"` + InstructionAddr string `json:"instruction_addr,omitempty"` + AddrMode string `json:"addr_mode,omitempty"` + SymbolAddr string `json:"symbol_addr,omitempty"` + ImageAddr string `json:"image_addr,omitempty"` + Platform string `json:"platform,omitempty"` + StackStart bool `json:"stack_start,omitempty"` } // NewFrame assembles a stacktrace frame out of runtime.Frame.