forked from grafana/grafana
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
K8s: Add tracing to apiserver startup (grafana#95744)
Co-authored-by: Stephanie Hingtgen <[email protected]>
- Loading branch information
1 parent
c517880
commit 003b2f1
Showing
3 changed files
with
72 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package tracing | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/grafana/dskit/services" | ||
"github.com/grafana/grafana/pkg/semconv" | ||
"go.opentelemetry.io/otel/trace" | ||
) | ||
|
||
var _ services.NamedService = &ServiceTracer{} | ||
|
||
// ServiceTracer wraps service.NamedService and adds tracing. | ||
// Currently it is limited to the starting -> running state transition. | ||
type ServiceTracer struct { | ||
services.NamedService | ||
tracer trace.Tracer | ||
} | ||
|
||
// NewServiceTracer creates a new ServiceTracer. | ||
func NewServiceTracer(tracerProvider trace.TracerProvider, service services.NamedService) *ServiceTracer { | ||
tracer := tracerProvider.Tracer("pkg/modules/tracing") | ||
return &ServiceTracer{NamedService: service, tracer: tracer} | ||
} | ||
|
||
func (s *ServiceTracer) StartAsync(ctx context.Context) error { | ||
spanCtx, span := s.tracer.Start(ctx, "Service Start", trace.WithAttributes(semconv.GrafanaServiceName(s.ServiceName()))) | ||
go func() { | ||
if err := s.AwaitRunning(spanCtx); err != nil { | ||
span.RecordError(err) | ||
} | ||
span.End() | ||
}() | ||
return s.NamedService.StartAsync(ctx) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters