Skip to content

Commit

Permalink
wip: log as trace tags instead of logs
Browse files Browse the repository at this point in the history
  • Loading branch information
qlonik committed Mar 6, 2024
1 parent 36babae commit cd9d4c4
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 3 deletions.
2 changes: 1 addition & 1 deletion privacy-profile-composer/pkg/envoyfilter/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ func (p *ConfigParser) Parse(any *anypb.Any, callbacks api.ConfigCallbackHandler
if internalCidrsExist, ok := configStruct["internal_cidrs"]; !ok {
return nil, fmt.Errorf("missing internal_cidrs")
} else if internalCidrs, ok := internalCidrsExist.([]string); !ok {
return nil, fmt.Errorf("internal_cidrs: expect a list of strings while got %T", internalCidrs)
return nil, fmt.Errorf("internal_cidrs: expect a list of strings while got %T", internalCidrsExist)
} else {
parsedCidrs, err := parseCIDRs(internalCidrs)
if err != nil {
Expand Down
34 changes: 32 additions & 2 deletions privacy-profile-composer/pkg/envoyfilter/filter.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package envoyfilter
import (
"bytes"
"context"
"encoding/json"
"fmt"
"log"
"net"
Expand Down Expand Up @@ -67,8 +68,29 @@ func (f *Filter) DecodeHeaders(header api.RequestHeaderMap, endStream bool) api.
span := f.tracer.StartSpan("test span in decode headers", zipkin.Parent(f.parentSpanContext))
defer span.Finish()

span.Tag("opa-enforce", fmt.Sprint(f.config.opaEnforce))
span.Tag("sidecar-direction", fmt.Sprint(f.config.direction))

f.headerMetadata = common.ExtractHeaderData(header)

span.Tag("method", f.headerMetadata.Method)
span.Tag("host", f.headerMetadata.Host)
span.Tag("path", f.headerMetadata.Path)
span.Tag("svc-name", f.headerMetadata.SvcName)
span.Tag("purpose", f.headerMetadata.Purpose)
if f.headerMetadata.EnvoyPeerMetadata != nil {
encoded, err := json.Marshal(f.headerMetadata.EnvoyPeerMetadata)
if err != nil {
span.Tag("envoy-peer-metadata-error", fmt.Sprint(err))
} else {
span.Tag("envoy-peer-metadata", string(encoded))
}
}

// TODO: should these two be added to `f.headerMetadata`?
span.Tag("protocol", header.Protocol())
span.Tag("scheme", header.Scheme())

// TODO: Insert it into OpenTelemetry baggage for tracing?
header.Add("x-prose-purpose", f.headerMetadata.Purpose) // For OPA

Expand All @@ -90,16 +112,22 @@ func (f *Filter) DecodeHeaders(header api.RequestHeaderMap, endStream bool) api.
// and only process the body in this case
destinationAddress, err := f.callbacks.GetProperty("destination.address")
if err != nil {
log.Println(err)
span.Tag("error", "true")
span.Tag("error-msg", fmt.Sprint(err))
return api.Continue
}

span.Tag("destination-address", destinationAddress)

isInternalDestination, err := f.checkInternalAddress(destinationAddress)
if err != nil {
log.Println(err)
span.Tag("error", "true")
span.Tag("error-msg", fmt.Sprint(err))
return api.Continue
}

span.Tag("is-internal-destination", fmt.Sprint(isInternalDestination))

if isInternalDestination {
log.Printf("outbound sidecar processed a request to another sidecar in the mesh" +
"Prose will process it through the inbound decode function\n")
Expand All @@ -114,6 +142,8 @@ func (f *Filter) DecodeHeaders(header api.RequestHeaderMap, endStream bool) api.
return api.Continue
}

span.Tag("process-decode-body", fmt.Sprint(f.processDecodeBody))

return api.StopAndBuffer
}

Expand Down

0 comments on commit cd9d4c4

Please sign in to comment.