Skip to content

Commit c8c9327

Browse files
authored
Improve logging in TestBasicTrace to show unexpected labels (#108)
* Use configurable exponential backoff and longer duration for trace retries * Improve logging in TestBasicTrace to show unexpected labels The test previously only failed with the count of unexpected labels, making it hard to debug which labels were added. This change collects and prints the unexpected labels.
1 parent e1533a3 commit c8c9327

3 files changed

Lines changed: 16 additions & 11 deletions

File tree

cloudbuild-e2e-gae-standard.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ steps:
4444
cd opentelemetry-operations-go
4545
LATEST_TAG=$$(git describe --tags $$(git rev-list --tags --max-count=1))
4646
git checkout $$LATEST_TAG
47-
- name: golang:1.24.2
47+
- name: golang:1.25.5
4848
id: zip-code
4949
entrypoint: /bin/bash
5050
args:
@@ -64,7 +64,7 @@ steps:
6464
env: ["PROJECT_ID=$PROJECT_ID"]
6565
args:
6666
- gae-standard
67-
- --runtime=go124
67+
- --runtime=go125
6868
- --appsource=/workspace/opentelemetry-operations-go/e2e-test-server/appsource.zip
6969

7070
logsBucket: gs://opentelemetry-ops-e2e-cloud-build-logs

e2etesting/e2e_testing.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -126,9 +126,10 @@ type Args struct {
126126
CloudFunctionsGen2 *CloudFunctionsGen2Cmd `arg:"subcommand:cloud-functions-gen2" help:"Deploy the test server on Cloud Function (2nd Gen) and execute tests"`
127127

128128
CmdWithProjectId
129-
GoTestFlags string `help:"go test flags to pass through, e.g. --gotestflags='-test.v'"`
130-
HealthCheckTimeout time.Duration `arg:"--health-check-timeout" help:"A duration (e.g. 5m) to wait for the test server health check. Default is 2m." default:"15m"`
131-
129+
GoTestFlags string `help:"go test flags to pass through, e.g. --gotestflags='-test.v'"`
130+
HealthCheckTimeout time.Duration `arg:"--health-check-timeout" help:"A duration (e.g. 5m) to wait for the test server health check. Default is 2m." default:"15m"`
131+
TraceBackoffInitial time.Duration `arg:"--trace-backoff-initial" help:"Initial exponential backoff duration for trace retries" default:"1s"`
132+
TraceBackoffTotal time.Duration `arg:"--trace-backoff-total" help:"Total maximum duration for trace retries" default:"60s"`
132133
// This is used in a new terraform workspace's name and in the GCP resources
133134
// we create. Pass the GCB build ID in CI to get the build id formatted into
134135
// resources created for debugging. If not provided, we generate a hex

e2etestrunner/trace_test.go

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,8 @@ func getTraceWithRetry(
7575
traceId string,
7676
) *cloudtrace.Trace {
7777
var trace *cloudtrace.Trace
78-
backoff, _ := retry.NewConstant(1 * time.Second)
79-
backoff = retry.WithMaxDuration(time.Second*10, backoff)
78+
backoff, _ := retry.NewExponential(args.TraceBackoffInitial)
79+
backoff = retry.WithMaxDuration(args.TraceBackoffTotal, backoff)
8080
err := retry.Do(ctx, backoff, func(ctx context.Context) error {
8181
var err error
8282
trace, err = cloudtraceService.Projects.Traces.Get(args.ProjectID, traceId).Context(ctx).Do()
@@ -125,7 +125,7 @@ func TestBasicTrace(t *testing.T) {
125125
)
126126

127127
// Ignore-able labels (resource, instrumentation library)
128-
numLabels := 0
128+
var nonResourceLabels []string
129129
for key := range span.Labels {
130130
if strings.HasPrefix(key, "g.co/r/") {
131131
continue
@@ -138,11 +138,15 @@ func TestBasicTrace(t *testing.T) {
138138
if strings.HasPrefix(key, "k8s.") {
139139
continue
140140
}
141-
numLabels += 1
141+
// Ignore specific GCP resource labels that are known to be added by the exporter.
142+
if key == "gcp.project_id" {
143+
continue
144+
}
145+
nonResourceLabels = append(nonResourceLabels, key)
142146
}
143147

144-
if numLabels != 2 {
145-
t.Fatalf("Expected exactly 2 non-resource labels, got %v", numLabels)
148+
if len(nonResourceLabels) != 2 {
149+
t.Fatalf("Expected exactly 2 non-resource labels, got %v. Labels found: %v", len(nonResourceLabels), nonResourceLabels)
146150
}
147151

148152
labelCases := []struct {

0 commit comments

Comments
 (0)