Skip to content
This repository was archived by the owner on Apr 17, 2023. It is now read-only.

Commit

Permalink
(MAINT) Refactor telemetry to pass root span name
Browse files Browse the repository at this point in the history
Prior to this commit, the telemetry package hard coded the root span to
execution; this commit modifies the Start function to take an additional
paramater, rootCommandName, which is passed when called in main to ensure
that the root span is appropriately named. This will enable broader reuse
by other PDK tools such as PRM.

This commit also renames the variable containing the root span in main
from span to parentSpan in preparation for spinning up a child span in
main instead of in each subcommand.
  • Loading branch information
michaeltlombardi committed Oct 7, 2021
1 parent 31d37c2 commit 8f537af
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 5 deletions.
4 changes: 2 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ var (
func main() {
// Telemetry must be initialized before anything else;
// If the telemetry build tag was not passed, this is all null ops
ctx, traceProvider, span := telemetry.Start(context.Background(), honeycomb_api_key, honeycomb_dataset)
defer telemetry.ShutDown(ctx, traceProvider, span)
ctx, traceProvider, parentSpan := telemetry.Start(context.Background(), honeycomb_api_key, honeycomb_dataset, "pct")
defer telemetry.ShutDown(ctx, traceProvider, parentSpan)

var rootCmd = root.CreateRootCommand()

Expand Down
4 changes: 2 additions & 2 deletions pkg/telemetry/telemetry.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import (
"go.opentelemetry.io/otel/sdk/resource"
)

func Start(ctx context.Context, honeycomb_api_key string, honeycomb_dataset string) (context.Context, *sdktrace.TracerProvider, trace.Span) {
func Start(ctx context.Context, honeycomb_api_key string, honeycomb_dataset string, rootSpanName string) (context.Context, *sdktrace.TracerProvider, trace.Span) {
var tp *sdktrace.TracerProvider
// if telemetry is turned on and honeycomb is configured, hook it up
api_key_set := honeycomb_api_key != "not_set" && honeycomb_api_key != ""
Expand Down Expand Up @@ -76,7 +76,7 @@ func Start(ctx context.Context, honeycomb_api_key string, honeycomb_dataset stri
tracer := otel.Tracer("pct")

var span trace.Span
ctx, span = tracer.Start(ctx, "execution")
ctx, span = tracer.Start(ctx, rootSpanName)

// The Protected ID is hashed base on application name to prevent any
// accidental leakage of a reversable ID.
Expand Down
2 changes: 1 addition & 1 deletion pkg/telemetry/telemetry_noop.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"context"
)

func Start(ctx context.Context, honeycomb_api_key string, honeycomb_dataset string) (context.Context, string, string) {
func Start(ctx context.Context, honeycomb_api_key string, honeycomb_dataset string, rootSpanName string) (context.Context, string, string) {
// deliberately does nothing
return ctx, "", ""
}
Expand Down

0 comments on commit 8f537af

Please sign in to comment.