Skip to content

Commit

Permalink
Merge pull request #2 from snappyflow/session
Browse files Browse the repository at this point in the history
SNP-7396 - Modify the apm-server to add session details
  • Loading branch information
Siddharth-KP-ML authored May 24, 2023
2 parents 03b2bd8 + 6e4a978 commit 0989192
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 0 deletions.
16 changes: 16 additions & 0 deletions model/modeldecoder/transaction.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ func decodeTransaction(input Input, schema *jsonschema.Schema) (*model.Transacti

fieldName := field.Mapper(input.Config.HasShortFieldNames)
ctx, err := decodeContext(getObject(raw, fieldName("context")), input.Config, &input.Metadata)
session, err := decodeSession(getObject(raw, fieldName("session")), input.Config.HasShortFieldNames, err)
if err != nil {
return nil, err
}
Expand All @@ -150,6 +151,7 @@ func decodeTransaction(input Input, schema *jsonschema.Schema) (*model.Transacti
Sampled: decoder.BoolPtr(raw, fieldName("sampled")),
Marks: decodeV2Marks(getObject(raw, fieldName("marks"))),
Timestamp: decoder.TimeEpochMicro(raw, fieldName("timestamp")),
Session: session,
SpanCount: model.SpanCount{
Dropped: decoder.IntPtr(raw, fieldName("dropped"), fieldName("span_count")),
Started: decoder.IntPtr(raw, fieldName("started"), fieldName("span_count"))},
Expand Down Expand Up @@ -251,3 +253,17 @@ func decodeRUMV3Marks(raw map[string]interface{}, cfg Config) model.TransactionM
)
return marks
}

// decodes the session details from given transaction
func decodeSession(sessionInput map[string]interface{}, hasShortFieldNames bool, err error) (*model.Session, error) {
if sessionInput == nil {
return &model.Session{}, nil
}
decoder := utility.ManualDecoder{}
fieldName := field.Mapper(hasShortFieldNames)
session := &model.Session{
ID: decoder.StringPtr(sessionInput, fieldName("id")),
Sequence: decoder.IntPtr(sessionInput, fieldName("sequence")),
}
return session, decoder.Err
}
20 changes: 20 additions & 0 deletions model/transaction.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,12 @@ var (
transactionProcessorEntry = common.MapStr{"name": transactionProcessorName, "event": transactionDocType}
)

// Session holds all information sent under key session
type Session struct {
ID *string
Sequence *int
}

type Transaction struct {
Metadata Metadata

Expand All @@ -63,6 +69,7 @@ type Transaction struct {
Labels *Labels
Custom *Custom
UserExperience *UserExperience
Session *Session

Experimental interface{}

Expand Down Expand Up @@ -91,6 +98,7 @@ func (e *Transaction) fields() common.MapStr {
fields.maybeSetMapStr("custom", e.Custom.Fields())
fields.maybeSetMapStr("message", e.Message.Fields())
fields.maybeSetMapStr("experience", e.UserExperience.Fields())
fields.maybeSetMapStr("session", e.Session.Fields())
if e.SpanCount.Dropped != nil || e.SpanCount.Started != nil {
spanCount := common.MapStr{}
if e.SpanCount.Dropped != nil {
Expand Down Expand Up @@ -166,3 +174,15 @@ func (m TransactionMark) fields() common.MapStr {
}
return out
}

// Fields returns common.MapStr holding transformed data for attribute session.
func (session *Session) Fields() common.MapStr {
if session == nil {
return nil
}
var fields = common.MapStr{}
// Remove in 8.0
utility.Set(fields, "id", session.ID)
utility.Set(fields, "sequence", session.Sequence)
return fields
}
10 changes: 10 additions & 0 deletions model/transaction/_meta/fields.yml
Original file line number Diff line number Diff line change
Expand Up @@ -77,3 +77,13 @@
type: long
description: >
Age of a message in milliseconds.
- name: session
type: group
dynamic: false
fields:
- name: id
type: keyword

- name: sequence
type: long

0 comments on commit 0989192

Please sign in to comment.