TestStartErrorsThenEnd tests that an End call after Start errors works without problems, as this is a possible codepath in the public observability API.
(t *testing.T)
| 526 | // without problems, as this is a possible codepath in the public observability |
| 527 | // API. |
| 528 | func (s) TestStartErrorsThenEnd(t *testing.T) { |
| 529 | invalidConfig := &config{ |
| 530 | ProjectID: "fake", |
| 531 | CloudLogging: &cloudLogging{ |
| 532 | ClientRPCEvents: []clientRPCEvents{ |
| 533 | { |
| 534 | Methods: []string{":-)"}, |
| 535 | MaxMetadataBytes: 30, |
| 536 | MaxMessageBytes: 30, |
| 537 | }, |
| 538 | }, |
| 539 | }, |
| 540 | } |
| 541 | invalidConfigJSON, err := json.Marshal(invalidConfig) |
| 542 | if err != nil { |
| 543 | t.Fatalf("failed to convert config to JSON: %v", err) |
| 544 | } |
| 545 | oldObservabilityConfig := envconfig.ObservabilityConfig |
| 546 | oldObservabilityConfigFile := envconfig.ObservabilityConfigFile |
| 547 | envconfig.ObservabilityConfig = string(invalidConfigJSON) |
| 548 | envconfig.ObservabilityConfigFile = "" |
| 549 | defer func() { |
| 550 | envconfig.ObservabilityConfig = oldObservabilityConfig |
| 551 | envconfig.ObservabilityConfigFile = oldObservabilityConfigFile |
| 552 | }() |
| 553 | ctx, cancel := context.WithTimeout(context.Background(), defaultTestTimeout) |
| 554 | defer cancel() |
| 555 | if err := Start(ctx); err == nil { |
| 556 | t.Fatalf("Invalid patterns not triggering error") |
| 557 | } |
| 558 | End() |
| 559 | } |
| 560 | |
| 561 | // TestLoggingLinkedWithTraceClientSide tests that client side logs get the |
| 562 | // trace and span id corresponding to the created Call Level Span for the RPC. |