MCPcopy Create free account
hub / github.com/google/go-cloud / TestOpenTelemetry

Function TestOpenTelemetry

pubsub/pubsub_test.go:575–627  ·  view source on GitHub ↗

TestOpenTelemetry tests that OpenTelemetry tracing is working correctly.

(t *testing.T)

Source from the content-addressed store, hash-verified

573
574// TestOpenTelemetry tests that OpenTelemetry tracing is working correctly.
575func TestOpenTelemetry(t *testing.T) {
576 ctx := context.Background()
577
578 te := oteltest.NewTestExporter(t, OpenTelemetryViews)
579 defer func() {
580 err := te.Shutdown(ctx)
581 if err != nil {
582 t.Logf("Error shutting down test exporter: %v", err)
583 }
584 }()
585
586 ds := NewDriverSub()
587 dt := &driverTopic{
588 subs: []*driverSub{ds},
589 }
590 topic := NewTopic(dt, nil)
591 defer topic.Shutdown(ctx)
592 sub := NewSubscription(ds, nil, nil)
593 defer sub.Shutdown(ctx)
594 if err := topic.Send(ctx, &Message{Body: []byte("x")}); err != nil {
595 t.Fatal(err)
596 }
597 if err := topic.Shutdown(ctx); err != nil {
598 t.Fatal(err)
599 }
600 msg, err := sub.Receive(ctx)
601 if err != nil {
602 t.Fatal(err)
603 }
604 msg.Ack()
605 err = sub.Shutdown(ctx)
606 if err != nil {
607 t.Fatal(err)
608 }
609 _, _ = sub.Receive(ctx)
610
611 spans := te.GetSpans()
612 metrics := te.GetMetrics(ctx)
613
614 diff := oteltest.Diff(spans.Snapshots(), metrics, pkgName, "gocloud.dev/pubsub", []oteltest.Call{
615 {Method: "driver.Topic.SendBatch", Code: gcerrors.OK},
616 {Method: "Topic.Send", Code: gcerrors.OK},
617 {Method: "Topic.Shutdown", Code: gcerrors.OK},
618 {Method: "driver.Subscription.ReceiveBatch", Code: gcerrors.OK},
619 {Method: "Subscription.Receive", Code: gcerrors.OK},
620 {Method: "driver.Subscription.SendAcks", Code: gcerrors.OK},
621 {Method: "Subscription.Shutdown", Code: gcerrors.OK},
622 {Method: "Subscription.Receive", Code: gcerrors.FailedPrecondition},
623 })
624 if diff != "" {
625 t.Error(diff)
626 }
627}
628
629func TestURLMux(t *testing.T) {
630 ctx := context.Background()

Callers

nothing calls this directly

Calls 14

ShutdownMethod · 0.95
ShutdownMethod · 0.95
ShutdownMethod · 0.95
SendMethod · 0.95
ReceiveMethod · 0.95
GetSpansMethod · 0.95
GetMetricsMethod · 0.95
NewTestExporterFunction · 0.92
DiffFunction · 0.92
NewDriverSubFunction · 0.85
NewTopicFunction · 0.85
NewSubscriptionFunction · 0.85

Tested by

no test coverage detected