MCPcopy
hub / github.com/grpc/grpc-go / TestLoggingLinkedWithTrace

Method TestLoggingLinkedWithTrace

gcp/observability/observability_test.go:849–1088  ·  view source on GitHub ↗

TestLoggingLinkedWithTrace tests that client and server side logs get the trace and span id corresponding to either the Call Level Span or Server Span (no determinism, so can only assert one or the other), for Unary and Streaming RPCs.

(t *testing.T)

Source from the content-addressed store, hash-verified

847// (no determinism, so can only assert one or the other), for Unary and
848// Streaming RPCs.
849func (s) TestLoggingLinkedWithTrace(t *testing.T) {
850 fle := &fakeLoggingExporter{
851 t: t,
852 }
853 oldNewLoggingExporter := newLoggingExporter
854 defer func() {
855 newLoggingExporter = oldNewLoggingExporter
856 }()
857
858 newLoggingExporter = func(context.Context, *config) (loggingExporter, error) {
859 return fle, nil
860 }
861
862 idCh := testutils.NewChannel()
863
864 fe := &fakeOpenCensusExporter{
865 t: t,
866 idCh: idCh,
867 }
868 oldNewExporter := newExporter
869 defer func() {
870 newExporter = oldNewExporter
871 }()
872
873 newExporter = func(*config) (tracingMetricsExporter, error) {
874 return fe, nil
875 }
876
877 const projectID = "project-id"
878 tracesAndLogsConfig := &config{
879 ProjectID: projectID,
880 CloudLogging: &cloudLogging{
881 ClientRPCEvents: []clientRPCEvents{
882 {
883 Methods: []string{"*"},
884 MaxMetadataBytes: 30,
885 MaxMessageBytes: 30,
886 },
887 },
888 ServerRPCEvents: []serverRPCEvents{
889 {
890 Methods: []string{"*"},
891 MaxMetadataBytes: 30,
892 MaxMessageBytes: 30,
893 },
894 },
895 },
896 CloudTrace: &cloudTrace{
897 SamplingRate: 1.0,
898 },
899 }
900 cleanup, err := setupObservabilitySystemWithConfig(tracesAndLogsConfig)
901 if err != nil {
902 t.Fatalf("error setting up observability %v", err)
903 }
904 defer cleanup()
905 ss := &stubserver.StubServer{
906 UnaryCallF: func(context.Context, *testpb.SimpleRequest) (*testpb.SimpleResponse, error) {

Callers

nothing calls this directly

Calls 15

StartMethod · 0.95
StopMethod · 0.95
ReceiveMethod · 0.95
SendMethod · 0.95
DoneMethod · 0.95
FireMethod · 0.95
NewChannelFunction · 0.92
NewEventFunction · 0.92
idsToStringMethod · 0.80
FatalfMethod · 0.65
RecvMethod · 0.65

Tested by

no test coverage detected