From 61dfd446d3e07dcdb311b2221445e8d3ca840a53 Mon Sep 17 00:00:00 2001 From: Sithum Bopitiya Date: Sun, 3 Sep 2023 14:28:53 +0530 Subject: [PATCH] Set span id to tag --- peer/bridge/bridge.go | 5 +++++ relayer/handlers.go | 5 +++++ 2 files changed, 10 insertions(+) diff --git a/peer/bridge/bridge.go b/peer/bridge/bridge.go index 5be1c65..d5dafcf 100644 --- a/peer/bridge/bridge.go +++ b/peer/bridge/bridge.go @@ -8,6 +8,7 @@ import ( "github.com/nbd-wtf/go-nostr" "github.com/sithumonline/demedia-nostr/relayer" "github.com/sithumonline/demedia-nostr/relayer/ql" + "go.opentelemetry.io/otel/attribute" "go.opentelemetry.io/otel/propagation" "go.opentelemetry.io/otel/trace" ) @@ -29,12 +30,14 @@ func (t *BridgeService) Ql(ctx context.Context, argType ql.BridgeArgs, replyType } ctx = propagation.TraceContext{}.Extract(ctx, call.Carrier) ctx, span := t.tracer.Start(ctx, "ql.method") + span.SetAttributes(attribute.String("span_id", span.SpanContext().SpanID().String())) defer span.End() log := relayer.DefaultLogger() log.InfofWithContext(ctx, "Received a Ql call, method: %s", call.Method) switch call.Method { case "saveEvent": ctx, span := t.tracer.Start(ctx, "ql.method.saveEvent") + span.SetAttributes(attribute.String("span_id", span.SpanContext().SpanID().String())) defer span.End() var d nostr.Event err := json.Unmarshal(call.Body, &d) @@ -45,6 +48,7 @@ func (t *BridgeService) Ql(ctx context.Context, argType ql.BridgeArgs, replyType return t.relay.Storage().SaveEvent(&d) case "queryEvents": ctx, span := t.tracer.Start(ctx, "ql.method.queryEvents") + span.SetAttributes(attribute.String("span_id", span.SpanContext().SpanID().String())) defer span.End() var d nostr.Filter err := json.Unmarshal(call.Body, &d) @@ -65,6 +69,7 @@ func (t *BridgeService) Ql(ctx context.Context, argType ql.BridgeArgs, replyType return nil case "deleteEvent": ctx, span := t.tracer.Start(ctx, "ql.method.deleteEvent") + span.SetAttributes(attribute.String("span_id", span.SpanContext().SpanID().String())) defer span.End() var d nostr.Event err := json.Unmarshal(call.Body, &d) diff --git a/relayer/handlers.go b/relayer/handlers.go index 9c417f1..a91a080 100644 --- a/relayer/handlers.go +++ b/relayer/handlers.go @@ -18,6 +18,7 @@ import ( "github.com/nbd-wtf/go-nostr/nip11" "github.com/nbd-wtf/go-nostr/nip42" "github.com/sithumonline/demedia-nostr/relayer/hashutil" + "go.opentelemetry.io/otel/attribute" "golang.org/x/exp/slices" ) @@ -45,6 +46,7 @@ var upgrader = websocket.Upgrader{ func (s *Server) handleWebsocket(w http.ResponseWriter, r *http.Request) { ctx, span := s.tracer.Start(r.Context(), "handleWebsocket") + span.SetAttributes(attribute.String("span_id", span.SpanContext().SpanID().String())) defer span.End() s.Log.InfofWithContext(ctx, "handling websocket request from %s", r.RemoteAddr) store := s.relay.Storage() @@ -73,6 +75,7 @@ func (s *Server) handleWebsocket(w http.ResponseWriter, r *http.Request) { // reader go func() { ctx, span := s.tracer.Start(ctx, "handleWebsocket.reader") + span.SetAttributes(attribute.String("span_id", span.SpanContext().SpanID().String())) defer span.End() defer func() { ticker.Stop() @@ -99,6 +102,7 @@ func (s *Server) handleWebsocket(w http.ResponseWriter, r *http.Request) { s.Log.InfofWithContext(ctx, "auth challenge sent") for { ctx, span := s.tracer.Start(ctx, "handleWebsocket.reader.for") + span.SetAttributes(attribute.String("span_id", span.SpanContext().SpanID().String())) s.Log.InfofWithContext(ctx, "inside for loop and waiting for message") typ, message, err := conn.ReadMessage() if err != nil { @@ -120,6 +124,7 @@ func (s *Server) handleWebsocket(w http.ResponseWriter, r *http.Request) { go func(message []byte) { ctx, span := s.tracer.Start(ctx, "handleWebsocket.reader.for.go") + span.SetAttributes(attribute.String("span_id", span.SpanContext().SpanID().String())) defer span.End() s.Log.InfofWithContext(ctx, "initializing go routine for message") var notice string