Skip to content

Commit

Permalink
fixed nits
Browse files Browse the repository at this point in the history
  • Loading branch information
aranjans committed Dec 19, 2024
1 parent 57fd38a commit b0aad8a
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 7 deletions.
17 changes: 10 additions & 7 deletions stats/opentelemetry/e2e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,6 @@ func Test(t *testing.T) {
// subset of information that is needed to verify if correct trace is being
// attributed to the rpc.
type traceSpanInfo struct {
sc trace2.SpanContext
spanKind string
name string
events []trace.Event
Expand Down Expand Up @@ -627,11 +626,11 @@ func pollForWantMetrics(ctx context.Context, t *testing.T, reader *metric.Manual
// correct emission of metrics during a Unary RPC and a Streaming RPC, ensuring that
// the metrics reflect the operations performed, including the size of the compressed
// message.
func TestServerWithMetricsAndTraceOptions(t *testing.T) {
func (s) TestMetricsAndTracesOptionEnabled(t *testing.T) {
// Create default metrics options
mo, reader := defaultMetricsOptions(t, nil)
// Create default trace options
to, _ := defaultTraceOptions(t)
to, exporter := defaultTraceOptions(t)

ss := setupStubServer(t, mo, to)
defer ss.Stop()
Expand Down Expand Up @@ -672,6 +671,12 @@ func TestServerWithMetricsAndTraceOptions(t *testing.T) {
UnaryCompressedMessageSize: float64(57),
})
testutils.CompareMetrics(ctx, t, reader, gotMetrics, wantMetrics)

// Verify traces
spans := exporter.GetSpans()
if got, want := len(spans), 6; got != want {
t.Fatalf("got %d spans, want %d", got, want)
}
}

// TestSpan verifies that the gRPC Trace Binary propagator correctly
Expand All @@ -687,11 +692,10 @@ func TestServerWithMetricsAndTraceOptions(t *testing.T) {
// - Validates that the tracing information is recorded accurately in
// the OpenTelemetry backend.
func (s) TestSpan(t *testing.T) {
mo, _ := defaultMetricsOptions(t, nil)
// Using defaultTraceOptions to set up OpenTelemetry with an in-memory exporter
traceOptions, spanExporter := defaultTraceOptions(t)
// Start the server with OpenTelemetry options
ss := setupStubServer(t, mo, traceOptions)
ss := setupStubServer(t, nil, traceOptions)
defer ss.Stop()

ctx, cancel := context.WithTimeout(context.Background(), defaultTestTimeout)
Expand Down Expand Up @@ -971,13 +975,12 @@ func (s) TestSpan(t *testing.T) {
// - Checks that the trace ID and span ID are correctly assigned and accessible
// in the OpenTelemetry backend.
func (s) TestSpan_WithW3CContextPropagator(t *testing.T) {
mo, _ := defaultMetricsOptions(t, nil)
// Using defaultTraceOptions to set up OpenTelemetry with an in-memory exporter
traceOptions, spanExporter := defaultTraceOptions(t)
// Set the W3CContextPropagator as part of TracingOptions.
traceOptions.TextMapPropagator = propagation.NewCompositeTextMapPropagator(propagation.TraceContext{})
// Start the server with OpenTelemetry options
ss := setupStubServer(t, mo, traceOptions)
ss := setupStubServer(t, nil, traceOptions)
defer ss.Stop()

ctx, cancel := context.WithTimeout(context.Background(), defaultTestTimeout)
Expand Down
16 changes: 16 additions & 0 deletions stats/opentelemetry/experimental/api.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,19 @@
/*
* Copyright 2024 gRPC authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package experimental

import (
Expand Down

0 comments on commit b0aad8a

Please sign in to comment.