From cdbd98764b95c39507f621aeeb1629a97c86b772 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Frederik=20Sch=C3=B6ll?= Date: Mon, 7 Aug 2023 16:19:45 +0200 Subject: [PATCH] add trace_id to metering events --- metering.go | 5 +++ pb/last_generate.txt | 4 +- pb/sf/metering/v1/metering.pb.go | 56 ++++++++++++++++----------- pb/sf/metering/v1/metering_grpc.pb.go | 2 +- proto/sf/metering/v1/metering.proto | 4 +- 5 files changed, 44 insertions(+), 27 deletions(-) diff --git a/metering.go b/metering.go index 130f539..8ae53b2 100644 --- a/metering.go +++ b/metering.go @@ -19,6 +19,7 @@ type Event struct { UserID string `json:"user_id"` ApiKeyID string `json:"api_key_id"` IpAddress string `json:"ip_address"` + TraceId string `json:"trace_id"` Timestamp time.Time `json:"timestamp"` } @@ -33,6 +34,9 @@ func (ev Event) MarshalLogObject(enc zapcore.ObjectEncoder) error { if ev.IpAddress != "" { enc.AddString("ip_address", ev.IpAddress) } + if ev.TraceId != "" { + enc.AddString("trace_id", ev.TraceId) + } enc.AddString("endpoint", ev.Endpoint) enc.AddTime("timestamp", ev.Timestamp) @@ -52,6 +56,7 @@ func (ev Event) ToProto(network string) *pbmetering.Event { pbev.UserId = ev.UserID pbev.ApiKeyId = ev.ApiKeyID pbev.IpAddress = ev.IpAddress + pbev.TraceId = ev.TraceId pbev.Metrics = []*pbmetering.Metric{} for k, v := range ev.Metrics { diff --git a/pb/last_generate.txt b/pb/last_generate.txt index c9b27a9..8cdf9a4 100644 --- a/pb/last_generate.txt +++ b/pb/last_generate.txt @@ -1,2 +1,2 @@ -generate.sh - Fri 28 Jul 2023 09:19:28 EDT - julien -streamingfast/proto revision: cd783a0fb6717a2a1aa98db6b4cd4a8cf3568a3f +generate.sh - Mon Aug 7 16:11:09 CEST 2023 - fred +streamingfast/proto revision: e1df53e362aa4c4e9c884de5d51f5b671d8e93fa diff --git a/pb/sf/metering/v1/metering.pb.go b/pb/sf/metering/v1/metering.pb.go index 4f51791..128f019 100644 --- a/pb/sf/metering/v1/metering.pb.go +++ b/pb/sf/metering/v1/metering.pb.go @@ -1,7 +1,7 @@ // Code generated by protoc-gen-go. DO NOT EDIT. // versions: -// protoc-gen-go v1.27.1 -// protoc v4.23.2 +// protoc-gen-go v1.28.1 +// protoc v4.23.4 // source: sf/metering/v1/metering.proto package pbmetering @@ -81,6 +81,7 @@ type Event struct { Endpoint string `protobuf:"bytes,4,opt,name=endpoint,proto3" json:"endpoint,omitempty"` // Defines the blockchain (eth-mainnet, sol-mainnet ...) Network string `protobuf:"bytes,5,opt,name=network,proto3" json:"network,omitempty"` + TraceId string `protobuf:"bytes,6,opt,name=trace_id,json=traceId,proto3" json:"trace_id,omitempty"` Metrics []*Metric `protobuf:"bytes,20,rep,name=metrics,proto3" json:"metrics,omitempty"` Timestamp *timestamppb.Timestamp `protobuf:"bytes,30,opt,name=timestamp,proto3" json:"timestamp,omitempty"` } @@ -152,6 +153,13 @@ func (x *Event) GetNetwork() string { return "" } +func (x *Event) GetTraceId() string { + if x != nil { + return x.TraceId + } + return "" +} + func (x *Event) GetMetrics() []*Metric { if x != nil { return x.Metrics @@ -234,7 +242,7 @@ var file_sf_metering_v1_metering_proto_rawDesc = []byte{ 0x06, 0x45, 0x76, 0x65, 0x6e, 0x74, 0x73, 0x12, 0x2d, 0x0a, 0x06, 0x65, 0x76, 0x65, 0x6e, 0x74, 0x73, 0x18, 0x01, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x15, 0x2e, 0x73, 0x66, 0x2e, 0x6d, 0x65, 0x74, 0x65, 0x72, 0x69, 0x6e, 0x67, 0x2e, 0x76, 0x31, 0x2e, 0x45, 0x76, 0x65, 0x6e, 0x74, 0x52, 0x06, - 0x65, 0x76, 0x65, 0x6e, 0x74, 0x73, 0x22, 0xff, 0x01, 0x0a, 0x05, 0x45, 0x76, 0x65, 0x6e, 0x74, + 0x65, 0x76, 0x65, 0x6e, 0x74, 0x73, 0x22, 0x9a, 0x02, 0x0a, 0x05, 0x45, 0x76, 0x65, 0x6e, 0x74, 0x12, 0x17, 0x0a, 0x07, 0x75, 0x73, 0x65, 0x72, 0x5f, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x06, 0x75, 0x73, 0x65, 0x72, 0x49, 0x64, 0x12, 0x1c, 0x0a, 0x0a, 0x61, 0x70, 0x69, 0x5f, 0x6b, 0x65, 0x79, 0x5f, 0x69, 0x64, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x08, 0x61, @@ -243,26 +251,28 @@ var file_sf_metering_v1_metering_proto_rawDesc = []byte{ 0x64, 0x64, 0x72, 0x65, 0x73, 0x73, 0x12, 0x1a, 0x0a, 0x08, 0x65, 0x6e, 0x64, 0x70, 0x6f, 0x69, 0x6e, 0x74, 0x18, 0x04, 0x20, 0x01, 0x28, 0x09, 0x52, 0x08, 0x65, 0x6e, 0x64, 0x70, 0x6f, 0x69, 0x6e, 0x74, 0x12, 0x18, 0x0a, 0x07, 0x6e, 0x65, 0x74, 0x77, 0x6f, 0x72, 0x6b, 0x18, 0x05, 0x20, - 0x01, 0x28, 0x09, 0x52, 0x07, 0x6e, 0x65, 0x74, 0x77, 0x6f, 0x72, 0x6b, 0x12, 0x30, 0x0a, 0x07, - 0x6d, 0x65, 0x74, 0x72, 0x69, 0x63, 0x73, 0x18, 0x14, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x16, 0x2e, - 0x73, 0x66, 0x2e, 0x6d, 0x65, 0x74, 0x65, 0x72, 0x69, 0x6e, 0x67, 0x2e, 0x76, 0x31, 0x2e, 0x4d, - 0x65, 0x74, 0x72, 0x69, 0x63, 0x52, 0x07, 0x6d, 0x65, 0x74, 0x72, 0x69, 0x63, 0x73, 0x12, 0x38, - 0x0a, 0x09, 0x74, 0x69, 0x6d, 0x65, 0x73, 0x74, 0x61, 0x6d, 0x70, 0x18, 0x1e, 0x20, 0x01, 0x28, - 0x0b, 0x32, 0x1a, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, - 0x62, 0x75, 0x66, 0x2e, 0x54, 0x69, 0x6d, 0x65, 0x73, 0x74, 0x61, 0x6d, 0x70, 0x52, 0x09, 0x74, - 0x69, 0x6d, 0x65, 0x73, 0x74, 0x61, 0x6d, 0x70, 0x22, 0x30, 0x0a, 0x06, 0x4d, 0x65, 0x74, 0x72, - 0x69, 0x63, 0x12, 0x10, 0x0a, 0x03, 0x6b, 0x65, 0x79, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, - 0x03, 0x6b, 0x65, 0x79, 0x12, 0x14, 0x0a, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x18, 0x02, 0x20, - 0x01, 0x28, 0x01, 0x52, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x32, 0x44, 0x0a, 0x08, 0x4d, 0x65, - 0x74, 0x65, 0x72, 0x69, 0x6e, 0x67, 0x12, 0x38, 0x0a, 0x04, 0x45, 0x6d, 0x69, 0x74, 0x12, 0x16, - 0x2e, 0x73, 0x66, 0x2e, 0x6d, 0x65, 0x74, 0x65, 0x72, 0x69, 0x6e, 0x67, 0x2e, 0x76, 0x31, 0x2e, - 0x45, 0x76, 0x65, 0x6e, 0x74, 0x73, 0x1a, 0x16, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, - 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x45, 0x6d, 0x70, 0x74, 0x79, 0x22, 0x00, - 0x42, 0x41, 0x5a, 0x3f, 0x67, 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x73, - 0x74, 0x72, 0x65, 0x61, 0x6d, 0x69, 0x6e, 0x67, 0x66, 0x61, 0x73, 0x74, 0x2f, 0x64, 0x6d, 0x65, - 0x74, 0x65, 0x72, 0x69, 0x6e, 0x67, 0x2f, 0x70, 0x62, 0x2f, 0x73, 0x66, 0x2f, 0x6d, 0x65, 0x74, - 0x65, 0x72, 0x69, 0x6e, 0x67, 0x2f, 0x76, 0x31, 0x3b, 0x70, 0x62, 0x6d, 0x65, 0x74, 0x65, 0x72, - 0x69, 0x6e, 0x67, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, + 0x01, 0x28, 0x09, 0x52, 0x07, 0x6e, 0x65, 0x74, 0x77, 0x6f, 0x72, 0x6b, 0x12, 0x19, 0x0a, 0x08, + 0x74, 0x72, 0x61, 0x63, 0x65, 0x5f, 0x69, 0x64, 0x18, 0x06, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, + 0x74, 0x72, 0x61, 0x63, 0x65, 0x49, 0x64, 0x12, 0x30, 0x0a, 0x07, 0x6d, 0x65, 0x74, 0x72, 0x69, + 0x63, 0x73, 0x18, 0x14, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x16, 0x2e, 0x73, 0x66, 0x2e, 0x6d, 0x65, + 0x74, 0x65, 0x72, 0x69, 0x6e, 0x67, 0x2e, 0x76, 0x31, 0x2e, 0x4d, 0x65, 0x74, 0x72, 0x69, 0x63, + 0x52, 0x07, 0x6d, 0x65, 0x74, 0x72, 0x69, 0x63, 0x73, 0x12, 0x38, 0x0a, 0x09, 0x74, 0x69, 0x6d, + 0x65, 0x73, 0x74, 0x61, 0x6d, 0x70, 0x18, 0x1e, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x1a, 0x2e, 0x67, + 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x54, + 0x69, 0x6d, 0x65, 0x73, 0x74, 0x61, 0x6d, 0x70, 0x52, 0x09, 0x74, 0x69, 0x6d, 0x65, 0x73, 0x74, + 0x61, 0x6d, 0x70, 0x22, 0x30, 0x0a, 0x06, 0x4d, 0x65, 0x74, 0x72, 0x69, 0x63, 0x12, 0x10, 0x0a, + 0x03, 0x6b, 0x65, 0x79, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x03, 0x6b, 0x65, 0x79, 0x12, + 0x14, 0x0a, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x01, 0x52, 0x05, + 0x76, 0x61, 0x6c, 0x75, 0x65, 0x32, 0x44, 0x0a, 0x08, 0x4d, 0x65, 0x74, 0x65, 0x72, 0x69, 0x6e, + 0x67, 0x12, 0x38, 0x0a, 0x04, 0x45, 0x6d, 0x69, 0x74, 0x12, 0x16, 0x2e, 0x73, 0x66, 0x2e, 0x6d, + 0x65, 0x74, 0x65, 0x72, 0x69, 0x6e, 0x67, 0x2e, 0x76, 0x31, 0x2e, 0x45, 0x76, 0x65, 0x6e, 0x74, + 0x73, 0x1a, 0x16, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, + 0x62, 0x75, 0x66, 0x2e, 0x45, 0x6d, 0x70, 0x74, 0x79, 0x22, 0x00, 0x42, 0x41, 0x5a, 0x3f, 0x67, + 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x73, 0x74, 0x72, 0x65, 0x61, 0x6d, + 0x69, 0x6e, 0x67, 0x66, 0x61, 0x73, 0x74, 0x2f, 0x64, 0x6d, 0x65, 0x74, 0x65, 0x72, 0x69, 0x6e, + 0x67, 0x2f, 0x70, 0x62, 0x2f, 0x73, 0x66, 0x2f, 0x6d, 0x65, 0x74, 0x65, 0x72, 0x69, 0x6e, 0x67, + 0x2f, 0x76, 0x31, 0x3b, 0x70, 0x62, 0x6d, 0x65, 0x74, 0x65, 0x72, 0x69, 0x6e, 0x67, 0x62, 0x06, + 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, } var ( diff --git a/pb/sf/metering/v1/metering_grpc.pb.go b/pb/sf/metering/v1/metering_grpc.pb.go index 80b90ce..e4190ba 100644 --- a/pb/sf/metering/v1/metering_grpc.pb.go +++ b/pb/sf/metering/v1/metering_grpc.pb.go @@ -1,7 +1,7 @@ // Code generated by protoc-gen-go-grpc. DO NOT EDIT. // versions: // - protoc-gen-go-grpc v1.2.0 -// - protoc v4.23.2 +// - protoc v4.23.4 // source: sf/metering/v1/metering.proto package pbmetering diff --git a/proto/sf/metering/v1/metering.proto b/proto/sf/metering/v1/metering.proto index 3957c83..351d199 100644 --- a/proto/sf/metering/v1/metering.proto +++ b/proto/sf/metering/v1/metering.proto @@ -17,7 +17,7 @@ message Events { message Event { string user_id = 1; - string api_key_id = 2; + string api_key_id = 2; string ip_address = 3; // Defines the endpoint that emitted the event (sf.firehose.v1/Blocks ...) @@ -26,6 +26,8 @@ message Event { // Defines the blockchain (eth-mainnet, sol-mainnet ...) string network = 5; + string trace_id = 6; + repeated Metric metrics = 20; google.protobuf.Timestamp timestamp = 30;