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

feat: Add debug logging of Event/Reading details #666

Merged
merged 1 commit into from
Jan 30, 2021
Merged
Changes from all 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
36 changes: 34 additions & 2 deletions internal/runtime/runtime.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
"net/http"
"reflect"
"strconv"
"strings"
"sync"

"github.com/edgexfoundry/app-functions-sdk-go/v2/appcontext"
Expand Down Expand Up @@ -92,6 +93,7 @@ func (gr *GolangRuntime) ProcessMessage(edgexcontext *appcontext.Context, envelo
case *dtos.Event:
lc.Debug("Pipeline is expecting an Event")

var event *dtos.Event
var apiVersion string

// TODO: remove once fully switched over to V2 Event DTO
Expand All @@ -105,10 +107,10 @@ func (gr *GolangRuntime) ProcessMessage(edgexcontext *appcontext.Context, envelo
// TODO: remove once fully switched over to V2 Event DTO and simply call unmarshalEventDTO.
switch apiVersion {
case ApiV1:
target, err = gr.unmarshalV1EventToV2Event(envelope, lc)
event, err = gr.unmarshalV1EventToV2Event(envelope, lc)

case ApiV2:
target, err = gr.unmarshalEventDTO(envelope, lc)
event, err = gr.unmarshalEventDTO(envelope, lc)

default:
err = fmt.Errorf("unsupported API Version '%s' detected", apiVersion)
Expand All @@ -120,6 +122,12 @@ func (gr *GolangRuntime) ProcessMessage(edgexcontext *appcontext.Context, envelo
return &MessageError{Err: err, ErrorCode: http.StatusBadRequest}
}

if lc.LogLevel() == models.DebugLog {
gr.debugLogEvent(lc, event)
}

target = event

default:
customTypeName := di.TypeInstanceToName(target)
lc.Debugf("Pipeline is expecting a custom type of %s", customTypeName)
Expand Down Expand Up @@ -147,6 +155,30 @@ func (gr *GolangRuntime) ProcessMessage(edgexcontext *appcontext.Context, envelo
return gr.ExecutePipeline(target, envelope.ContentType, edgexcontext, transforms, 0, false)
}

func (gr *GolangRuntime) debugLogEvent(lc logger.LoggingClient, event *dtos.Event) {
lc.Debugf("Event Received with ProfileName=%s, DeviceName=%s and ReadingCount=%d",
event.ProfileName,
event.DeviceName,
len(event.Readings))
for index, reading := range event.Readings {
switch strings.ToLower(reading.ValueType) {
case strings.ToLower(v2.ValueTypeBinary):
lc.Debugf("Reading #%d received with ResourceName=%s, ValueType=%s, MediaType=%s and BinaryValue of size=`%d`",
index+1,
reading.ResourceName,
reading.ValueType,
reading.MediaType,
len(reading.BinaryValue))
default:
lc.Debugf("Reading #%d received with ResourceName=%s, ValueType=%s, Value=`%s`",
index+1,
reading.ResourceName,
reading.ValueType,
reading.Value)
}
}
}

func logError(lc logger.LoggingClient, err error, correlationID string) {
lc.Errorf("%s. %s=%s", err.Error(), clients.CorrelationHeader, correlationID)
}
Expand Down