|
1 | 1 | package custmsg |
2 | 2 |
|
3 | 3 | import ( |
| 4 | + "bytes" |
4 | 5 | "context" |
5 | 6 | "fmt" |
6 | 7 | "maps" |
7 | 8 |
|
8 | | - "google.golang.org/protobuf/proto" |
9 | | - |
| 9 | + "github.com/golang/protobuf/jsonpb" |
10 | 10 | "github.com/smartcontractkit/chainlink-common/pkg/beholder" |
11 | 11 | "github.com/smartcontractkit/chainlink-common/pkg/beholder/pb" |
12 | 12 | ) |
@@ -99,18 +99,21 @@ func sendLogAsCustomMessageW(ctx context.Context, msg string, labels map[string] |
99 | 99 | //if err != nil { |
100 | 100 | // return fmt.Errorf("could not wrap labels to map: %w", err) |
101 | 101 | //} |
102 | | - |
103 | 102 | // Define a custom protobuf payload to emit |
104 | 103 | payload := &pb.BaseMessage{ |
105 | 104 | Msg: msg, |
106 | 105 | Labels: labels, |
107 | 106 | } |
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) |
109 | 112 | 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) |
111 | 114 | } |
112 | 115 |
|
113 | | - err = beholder.GetEmitter().Emit(ctx, payloadBytes, |
| 116 | + err = beholder.GetEmitter().Emit(ctx, buf.Bytes(), |
114 | 117 | "beholder_data_schema", "/beholder-base-message/versions/1", // required |
115 | 118 | "beholder_domain", "platform", // required |
116 | 119 | "beholder_entity", "BaseMessage", // required |
|
0 commit comments