Skip to content

Commit b4c83c9

Browse files
committed
Marshal to custom message to JSON to see Beholder logs in Loki
1 parent 235758e commit b4c83c9

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

pkg/custmsg/custom_message.go

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
package custmsg
22

33
import (
4+
"bytes"
45
"context"
56
"fmt"
67
"maps"
78

8-
"google.golang.org/protobuf/proto"
9-
9+
"github.com/golang/protobuf/jsonpb"
1010
"github.com/smartcontractkit/chainlink-common/pkg/beholder"
1111
"github.com/smartcontractkit/chainlink-common/pkg/beholder/pb"
1212
)
@@ -99,18 +99,21 @@ func sendLogAsCustomMessageW(ctx context.Context, msg string, labels map[string]
9999
//if err != nil {
100100
// return fmt.Errorf("could not wrap labels to map: %w", err)
101101
//}
102-
103102
// Define a custom protobuf payload to emit
104103
payload := &pb.BaseMessage{
105104
Msg: msg,
106105
Labels: labels,
107106
}
108-
payloadBytes, err := proto.Marshal(payload)
107+
108+
// We marshal to JSON so we can read these messages in Loki
109+
marshaler := &jsonpb.Marshaler{}
110+
var buf bytes.Buffer
111+
err := marshaler.Marshal(&buf, payload)
109112
if err != nil {
110-
return fmt.Errorf("sending custom message failed to marshal protobuf: %w", err)
113+
return fmt.Errorf("sending custom message failed to marshal to JSON: %w", err)
111114
}
112115

113-
err = beholder.GetEmitter().Emit(ctx, payloadBytes,
116+
err = beholder.GetEmitter().Emit(ctx, buf.Bytes(),
114117
"beholder_data_schema", "/beholder-base-message/versions/1", // required
115118
"beholder_domain", "platform", // required
116119
"beholder_entity", "BaseMessage", // required

0 commit comments

Comments
 (0)