Skip to content

Commit

Permalink
sample in all private graph spans
Browse files Browse the repository at this point in the history
  • Loading branch information
Vadman97 committed Apr 27, 2024
1 parent 7f7c137 commit 23af716
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
2 changes: 1 addition & 1 deletion backend/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -475,7 +475,7 @@ func main() {
})
privateServer.Use(private.NewGraphqlOAuthValidator(privateResolver.Store))
privateServer.Use(util.NewTracer(util.PrivateGraph))
privateServer.Use(htrace.NewGraphqlTracer(string(util.PrivateGraph)).WithRequestFieldLogging())
privateServer.Use(htrace.NewGraphqlTracer(string(util.PrivateGraph), trace.WithSpanKind(trace.SpanKindServer)).WithRequestFieldLogging())
privateServer.SetErrorPresenter(htrace.GraphQLErrorPresenter(string(util.PrivateGraph)))
privateServer.SetRecoverFunc(htrace.GraphQLRecoverFunc())
r.Handle("/",
Expand Down
9 changes: 6 additions & 3 deletions sdk/highlight-go/trace/tracer.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ import (
"github.com/vektah/gqlparser/v2/gqlerror"
"go.opentelemetry.io/otel/attribute"
semconv "go.opentelemetry.io/otel/semconv/v1.17.0"
"go.opentelemetry.io/otel/trace"
"time"
)

type GraphqlTracer interface {
Expand All @@ -24,10 +26,11 @@ type GraphqlTracer interface {
type Tracer struct {
graphName string
requestFieldLogging bool
opts []trace.SpanStartOption
}

func NewGraphqlTracer(graphName string) GraphqlTracer {
return Tracer{graphName: graphName}
func NewGraphqlTracer(graphName string, opts ...trace.SpanStartOption) GraphqlTracer {
return Tracer{graphName: graphName, opts: opts}
}

// WithRequestFieldLogging configures the tracer to log each graphql operation.
Expand Down Expand Up @@ -85,7 +88,7 @@ func (t Tracer) InterceptResponse(ctx context.Context, next graphql.ResponseHand
}
name := fmt.Sprintf("graphql.operation.%s", opName)

span, ctx := highlight.StartTrace(ctx, name)
span, ctx := highlight.StartTraceWithTimestamp(ctx, name, time.Now(), t.opts)
span.SetAttributes(
semconv.ServiceNameKey.String(t.graphName),
semconv.GraphqlOperationName(opName),
Expand Down

0 comments on commit 23af716

Please sign in to comment.