Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add option to set the service name for tracing #1779

Merged
merged 2 commits into from Nov 22, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions agent/agent_configuration.go
Expand Up @@ -33,4 +33,5 @@ type AgentConfiguration struct {
RedactedVars []string
AcquireJob string
TracingBackend string
TracingServiceName string
}
1 change: 1 addition & 0 deletions agent/job_runner.go
Expand Up @@ -611,6 +611,7 @@ func (r *JobRunner) createEnvironment() ([]string, error) {

if r.conf.AgentConfiguration.TracingBackend != "" {
env["BUILDKITE_TRACING_BACKEND"] = r.conf.AgentConfiguration.TracingBackend
env["BUILDKITE_TRACING_SERVICE_NAME"] = r.conf.AgentConfiguration.TracingServiceName
}

// see documentation for BuildkiteMessageMax
Expand Down
3 changes: 3 additions & 0 deletions bootstrap/config.go
Expand Up @@ -145,6 +145,9 @@ type Config struct {

// Backend to use for tracing. If an empty string, no tracing will occur.
TracingBackend string

// Service name to use when reporting traces.
TracingServiceName string
}

// ReadFromEnvironment reads configuration from the Environment, returns a map
Expand Down
4 changes: 2 additions & 2 deletions bootstrap/tracing.go
Expand Up @@ -73,7 +73,7 @@ func (b *Bootstrap) ddResourceName() string {
// abstraction so the agent can support multiple libraries if needbe.
func (b *Bootstrap) startTracingDatadog(ctx context.Context) (tracetools.Span, context.Context, stopper) {
opts := []tracer.StartOption{
tracer.WithServiceName("buildkite-agent"),
tracer.WithServiceName(b.Config.TracingServiceName),
tracer.WithSampler(tracer.NewAllSampler()),
tracer.WithAnalytics(true),
}
Expand Down Expand Up @@ -132,7 +132,7 @@ func (b *Bootstrap) startTracingOpenTelemetry(ctx context.Context) (tracetools.S
}

attributes := []attribute.KeyValue{
semconv.ServiceNameKey.String("buildkite-agent"),
semconv.ServiceNameKey.String(b.Config.TracingServiceName),
semconv.ServiceVersionKey.String(agent.Version()),
semconv.DeploymentEnvironmentKey.String("ci"),
}
Expand Down
8 changes: 8 additions & 0 deletions clicommand/agent_start.go
Expand Up @@ -101,6 +101,7 @@ type AgentStartConfig struct {
MetricsDatadogHost string `cli:"metrics-datadog-host"`
MetricsDatadogDistributions bool `cli:"metrics-datadog-distributions"`
TracingBackend string `cli:"tracing-backend"`
TracingServiceName string `cli:"tracing-service-name"`
Spawn int `cli:"spawn"`
SpawnWithPriority bool `cli:"spawn-with-priority"`
LogFormat string `cli:"log-format"`
Expand Down Expand Up @@ -510,6 +511,12 @@ var AgentStartCommand = cli.Command{
EnvVar: "BUILDKITE_TRACING_BACKEND",
Value: "",
},
cli.StringFlag{
Name: "tracing-service-name",
Usage: "Service name to use when reporting traces.",
EnvVar: "BUILDKITE_TRACING_SERVICE_NAME",
Value: "buildkite-agent",
},

// API Flags
AgentRegisterTokenFlag,
Expand Down Expand Up @@ -732,6 +739,7 @@ var AgentStartCommand = cli.Command{
RedactedVars: cfg.RedactedVars,
AcquireJob: cfg.AcquireJob,
TracingBackend: cfg.TracingBackend,
TracingServiceName: cfg.TracingServiceName,
}

if loader.File != nil {
Expand Down
8 changes: 8 additions & 0 deletions clicommand/bootstrap.go
Expand Up @@ -88,6 +88,7 @@ type BootstrapConfig struct {
CancelSignal string `cli:"cancel-signal"`
RedactedVars []string `cli:"redacted-vars" normalize:"list"`
TracingBackend string `cli:"tracing-backend"`
TracingServiceName string `cli:"tracing-service-name"`
}

var BootstrapCommand = cli.Command{
Expand Down Expand Up @@ -329,6 +330,12 @@ var BootstrapCommand = cli.Command{
EnvVar: "BUILDKITE_TRACING_BACKEND",
Value: "",
},
cli.StringFlag{
Name: "tracing-service-name",
Usage: "Service name to use when reporting traces.",
EnvVar: "BUILDKITE_TRACING_SERVICE_NAME",
Value: "buildkite-agent",
},
DebugFlag,
LogLevelFlag,
ExperimentsFlag,
Expand Down Expand Up @@ -426,6 +433,7 @@ var BootstrapCommand = cli.Command{
Shell: cfg.Shell,
Tag: cfg.Tag,
TracingBackend: cfg.TracingBackend,
TracingServiceName: cfg.TracingServiceName,
})

ctx, cancel := context.WithCancel(context.Background())
Expand Down