Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

capture code stacktrace #184

Merged
merged 22 commits into from
Jan 11, 2024
Merged
Show file tree
Hide file tree
Changes from 13 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,11 @@ protolint:
gomodtidy:
go mod tidy -v

generate:
generate_code:
SylvainJuge marked this conversation as resolved.
Show resolved Hide resolved
go generate ./...

generate: generate_code update-licenses

fieldalignment:
go run golang.org/x/tools/go/analysis/passes/fieldalignment/cmd/[email protected] -test=false $(shell go list ./... | grep -v modeldecoder/generator | grep -v test | grep -v model/modelpb)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,7 @@ func TestDecodeMapToTransactionModel(t *testing.T) {
"representative_count",
"stacktrace.library_frame",
"stacktrace.vars",
"code",
// stacktrace original and sourcemap values are set when sourcemapping is applied
"stacktrace.original",
"stacktrace.sourcemap",
Expand Down
3 changes: 3 additions & 0 deletions input/elasticapm/internal/modeldecoder/v2/span_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,9 @@ func TestDecodeMapToSpanModel(t *testing.T) {
// Derived using service.target.*
"destination_service.Resource",

// only provided for otel-based agents
"code",

// Not set for spans:
"destination_service.response_time",
"destination_service.ResponseTime.Count",
Expand Down
7 changes: 7 additions & 0 deletions input/otlp/traces.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ const (
attributeUrlFull = "url.full"
attributeUserAgentOriginal = "user_agent.original"
attributeDbElasticsearchClusterName = "db.elasticsearch.cluster.name"
attributeStackTrace = "code.stacktrace" // semconv 1.24 or later
)

// ConsumeTracesResult contains the number of rejected spans and error message for partial success response.
Expand Down Expand Up @@ -746,6 +747,12 @@ func TranslateSpan(spanKind ptrace.SpanKind, attributes pcommon.Map, event *mode
httpURL = stringval
isHTTP = true

case attributeStackTrace:
if event.Span.Code == nil {
event.Span.Code = modelpb.CodeFromVTPool()
}
event.Span.Code.Stacktrace = stringval

// miscellaneous
case "span.kind": // filter out
case semconv.AttributePeerService:
Expand Down
9 changes: 9 additions & 0 deletions input/otlp/traces_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1596,6 +1596,15 @@ func TestGRPCTransactionFromNodejsSDK(t *testing.T) {
})
}

func TestSpanCodeStacktrace(t *testing.T) {
t.Run("code stacktrace", func(t *testing.T) {
event := transformSpanWithAttributes(t, map[string]interface{}{
"code.stacktrace": "stacktrace value",
})
assert.Equal(t, "stacktrace value", event.Span.Code.Stacktrace)
})
}

func testJaegerLogs() []jaegermodel.Log {
return []jaegermodel.Log{{
// errors that can be converted to elastic errors
Expand Down
22 changes: 22 additions & 0 deletions model/modeljson/internal/marshal_fastjson.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions model/modeljson/internal/span.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ type Span struct {
Composite *SpanComposite `json:"composite,omitempty"`
Destination *SpanDestination `json:"destination,omitempty"`
DB *DB `json:"db,omitempty"`
Code *Code `json:"code,omitempty"`
SylvainJuge marked this conversation as resolved.
Show resolved Hide resolved
Sync *bool `json:"sync,omitempty"`
Kind string `json:"kind,omitempty"`
Action string `json:"action,omitempty"`
Expand All @@ -35,6 +36,10 @@ type Span struct {
RepresentativeCount float64 `json:"representative_count,omitempty"`
}

type Code struct {
Stacktrace string `json:"stacktrace,omitempty"`
}

type SpanDestination struct {
Service SpanDestinationService `json:"service"`
}
Expand Down
6 changes: 6 additions & 0 deletions model/modeljson/span.pb.json.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,12 @@ func SpanModelJSON(e *modelpb.Span, out *modeljson.Span) {
}
}
}
if e.Code != nil {
out.Code = &modeljson.Code{
Stacktrace: e.Code.Stacktrace,
}
}

if n := len(e.Links); n > 0 {
out.Links = make([]modeljson.SpanLink, n)
for i, link := range e.Links {
Expand Down
Loading
Loading