From e56c5e404626d027a3e97b8c67d93fc0f7b0706a Mon Sep 17 00:00:00 2001 From: Florian Lehner Date: Tue, 22 Oct 2024 08:44:27 +0200 Subject: [PATCH] reporter: use semantic convention to report frame type (#167) Signed-off-by: Florian Lehner Co-authored-by: Christos Kalkanis --- README.md | 5 +++-- libpf/frametype.go | 5 ----- libpf/frametype_test.go | 8 +++++--- libpf/interpretertype.go | 24 ++++++++++++++---------- libpf/libpf_test.go | 4 ++-- reporter/otlp_reporter.go | 8 +++++--- 6 files changed, 29 insertions(+), 25 deletions(-) diff --git a/README.md b/README.md index 377fef6a..5f3c1bd1 100644 --- a/README.md +++ b/README.md @@ -91,9 +91,10 @@ devfiler spins up a local server that listens on `0.0.0.0:11000`. To run it, simply download and unpack the archive from the following URL: -https://upload.elastic.co/d/a3033fd2b515144b1c566961495302dac4da3223e59832f7755e18ac7fd94a19 +https://upload.elastic.co/d/87e7697991940ec37f0c6e39ac38d213f65e8dc1ef9dbedff6aab9cba0adfaba + +Authentication token: `c74dfc4db2212015` -Authentication token: `786a077d31b02bda` The archive contains a build for each of the following platforms: diff --git a/libpf/frametype.go b/libpf/frametype.go index cc3cf045..30ec130d 100644 --- a/libpf/frametype.go +++ b/libpf/frametype.go @@ -4,8 +4,6 @@ package libpf // import "go.opentelemetry.io/ebpf-profiler/libpf" import ( - "fmt" - "go.opentelemetry.io/ebpf-profiler/support" ) @@ -98,9 +96,6 @@ func (ty FrameType) String() string { return abortFrameName default: interp := ty.Interpreter() - if ty.IsError() { - return fmt.Sprintf("%s-error", interp) - } return interp.String() } } diff --git a/libpf/frametype_test.go b/libpf/frametype_test.go index 0cec0938..52dc0b93 100644 --- a/libpf/frametype_test.go +++ b/libpf/frametype_test.go @@ -14,8 +14,10 @@ func TestFrameTypeFromString(t *testing.T) { for _, ft := range []FrameType{ unknownFrame, PHPFrame, PythonFrame, NativeFrame, KernelFrame, HotSpotFrame, RubyFrame, PerlFrame, V8Frame, DotnetFrame, AbortFrame} { - name := ft.String() - result := FrameTypeFromString(name) - require.Equal(t, ft, result) + t.Run(ft.String(), func(t *testing.T) { + name := ft.String() + result := FrameTypeFromString(name) + require.Equal(t, ft, result) + }) } } diff --git a/libpf/interpretertype.go b/libpf/interpretertype.go index 5bbca6ca..d6be8137 100644 --- a/libpf/interpretertype.go +++ b/libpf/interpretertype.go @@ -54,22 +54,26 @@ func (i InterpreterType) Frame() FrameType { var interpreterTypeToString = map[InterpreterType]string{ UnknownInterp: "unknown", PHP: "php", - PHPJIT: "phpjit", - Python: "python", - Native: "native", - Kernel: "kernel", - HotSpot: "jvm", - Ruby: "ruby", - Perl: "perl", - V8: "v8", - Dotnet: "dotnet", - APMInt: "apm-integration", + // OTel SemConv does not differentiate between jitted code and interpreted code. + PHPJIT: "php", + Python: "cpython", + Native: "native", + Kernel: "kernel", + HotSpot: "jvm", + Ruby: "ruby", + Perl: "perl", + V8: "v8js", + Dotnet: "dotnet", + APMInt: "apm-integration", } var stringToInterpreterType = make(map[string]InterpreterType, len(interpreterTypeToString)) func init() { for k, v := range interpreterTypeToString { + if k == PHPJIT { + continue + } stringToInterpreterType[v] = k } } diff --git a/libpf/libpf_test.go b/libpf/libpf_test.go index cc76f09c..d2f0e938 100644 --- a/libpf/libpf_test.go +++ b/libpf/libpf_test.go @@ -29,13 +29,13 @@ func TestTraceType(t *testing.T) { ty: PythonFrame, isErr: false, interp: Python, - str: "python", + str: "cpython", }, { ty: NativeFrame.Error(), isErr: true, interp: Native, - str: "native-error", + str: "native", }, } diff --git a/reporter/otlp_reporter.go b/reporter/otlp_reporter.go index 49e0ab31..8d83083d 100644 --- a/reporter/otlp_reporter.go +++ b/reporter/otlp_reporter.go @@ -543,13 +543,15 @@ func (r *OTLPReporter) getProfile() (profile *profiles.Profile, startTS, endTS u // Walk every frame of the trace. for i := range traceInfo.frameTypes { + frameAttributes := addProfileAttributes(profile, []attrKeyValue{ + {key: "profile.frame.type", value: traceInfo.frameTypes[i].String()}, + }, attributeMap) + loc := &profiles.Location{ // Id - Optional element we do not use. - TypeIndex: getStringMapIndex(stringMap, - traceInfo.frameTypes[i].String()), Address: uint64(traceInfo.linenos[i]), // IsFolded - Optional element we do not use. - // Attributes - Optional element we do not use. + Attributes: frameAttributes, } switch frameKind := traceInfo.frameTypes[i]; frameKind {