Skip to content

Commit

Permalink
tracing: outline span creation in StartSpan so string concat can be i…
Browse files Browse the repository at this point in the history
…nlined and folded at compiletime

Fixes #67
  • Loading branch information
Jorropo committed Dec 8, 2023
1 parent b50da98 commit b48c418
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 3 deletions.
7 changes: 6 additions & 1 deletion bitswap/client/internal/tracing.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,10 @@ import (
)

func StartSpan(ctx context.Context, name string, opts ...trace.SpanStartOption) (context.Context, trace.Span) {
return otel.Tracer("go-bitswap").Start(ctx, "Bitswap."+name, opts...)
return startSpan(ctx, "Bitswap.Client."+name, opts...)
}

// outline logic so the string concatenation can be inlined and executed at compile time
func startSpan(ctx context.Context, name string, opts ...trace.SpanStartOption) (context.Context, trace.Span) {
return otel.Tracer("go-bitswap").Start(ctx, name, opts...)
}
7 changes: 6 additions & 1 deletion bitswap/internal/tracing.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,10 @@ import (
)

func StartSpan(ctx context.Context, name string, opts ...trace.SpanStartOption) (context.Context, trace.Span) {
return otel.Tracer("go-bitswap").Start(ctx, "Bitswap."+name, opts...)
return startSpan(ctx, "Bitswap."+name, opts...)
}

// outline logic so the string concatenation can be inlined and executed at compile time
func startSpan(ctx context.Context, name string, opts ...trace.SpanStartOption) (context.Context, trace.Span) {
return otel.Tracer("go-bitswap").Start(ctx, name, opts...)
}
7 changes: 6 additions & 1 deletion blockservice/internal/tracing.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,10 @@ import (
)

func StartSpan(ctx context.Context, name string, opts ...trace.SpanStartOption) (context.Context, trace.Span) {
return otel.Tracer("go-blockservice").Start(ctx, "Blockservice."+name, opts...)
return startSpan(ctx, "Blockservice."+name, opts...)
}

// outline logic so the string concatenation can be inlined and executed at compile time
func startSpan(ctx context.Context, name string, opts ...trace.SpanStartOption) (context.Context, trace.Span) {
return otel.Tracer("go-blockservice").Start(ctx, name, opts...)
}

0 comments on commit b48c418

Please sign in to comment.