Skip to content

Commit

Permalink
Set span id to tag
Browse files Browse the repository at this point in the history
  • Loading branch information
sithumonline committed Sep 3, 2023
1 parent 27f3012 commit 61dfd44
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
5 changes: 5 additions & 0 deletions peer/bridge/bridge.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand Down
5 changes: 5 additions & 0 deletions relayer/handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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()
Expand All @@ -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 {
Expand All @@ -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
Expand Down

0 comments on commit 61dfd44

Please sign in to comment.