Skip to content

Commit 0338cf3

Browse files
add option to redact protobuf fields (#1284)
* add option to redact protobuf fields * Create sharp-dolphins-help.md * generated protobuf --------- Co-authored-by: github-actions <41898282+github-actions[bot]@users.noreply.github.com>
1 parent db57aec commit 0338cf3

File tree

5 files changed

+105
-0
lines changed

5 files changed

+105
-0
lines changed

.changeset/sharp-dolphins-help.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@livekit/protocol": patch
3+
---
4+
5+
add option to redact protobuf fields

livekit/logger/options.pb.go

Lines changed: 82 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

logger/proto.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ import (
2222
"go.uber.org/zap/zapcore"
2323
"google.golang.org/protobuf/proto"
2424
"google.golang.org/protobuf/reflect/protoreflect"
25+
26+
"github.com/livekit/protocol/livekit/logger"
2527
)
2628

2729
func Proto(val proto.Message) zapcore.ObjectMarshaler {
@@ -46,6 +48,11 @@ func (p protoMarshaller) MarshalLogObject(e zapcore.ObjectEncoder) error {
4648
k := f.JSONName()
4749
v := p.m.Get(f)
4850

51+
if proto.HasExtension(f.Options(), logger.E_Redact) {
52+
e.AddString(k, "<redacted>")
53+
continue
54+
}
55+
4956
if f.IsMap() {
5057
if m := v.Map(); m.IsValid() {
5158
e.AddObject(k, protoMapMarshaller{f, m})

magefile.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ func Proto() error {
6868
"livekit_webhook.proto",
6969
"livekit_metrics.proto",
7070
"livekit_token_source.proto",
71+
"logger/options.proto",
7172
}
7273
grpcProtoFiles := []string{
7374
"infra/link.proto",

protobufs/logger/options.proto

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
syntax = "proto3";
2+
package logger;
3+
4+
option go_package = "github.com/livekit/protocol/logger";
5+
6+
import "google/protobuf/descriptor.proto";
7+
8+
extend google.protobuf.FieldOptions {
9+
bool redact = 50001;
10+
}

0 commit comments

Comments
 (0)