Skip to content

Commit ac77f0a

Browse files
committed
Merge remote-tracking branch 'origin/main' into observability/tracing-attr/http-method-definition
2 parents e771036 + 7ab6d2e commit ac77f0a

15 files changed

Lines changed: 136 additions & 40 deletions

gax-java/gax/src/main/java/com/google/api/gax/tracing/ApiTracerFactory.java

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -62,27 +62,15 @@ enum OperationType {
6262
*/
6363
ApiTracer newTracer(ApiTracer parent, SpanName spanName, OperationType operationType);
6464

65-
/**
66-
* Create a new {@link ApiTracer} that will be a child of the current context.
67-
*
68-
* @param parent the parent of this tracer
69-
* @param tracerContext the method-definition-specific tracer context
70-
* @param operationType the type of operation that the tracer will trace
71-
*/
72-
default ApiTracer newTracer(
73-
ApiTracer parent, ApiTracerContext tracerContext, OperationType operationType) {
74-
SpanName spanName = SpanName.of(tracerContext);
75-
return newTracer(parent, spanName, operationType);
76-
}
77-
7865
/**
7966
* Create a new {@link ApiTracer} that will be a child of the current context.
8067
*
8168
* @param parent the parent of this tracer
8269
* @param tracerContext the method-definition-specific tracer context
8370
*/
8471
default ApiTracer newTracer(ApiTracer parent, ApiTracerContext tracerContext) {
85-
return newTracer(parent, tracerContext, tracerContext.operationType());
72+
SpanName spanName = SpanName.of(tracerContext);
73+
return newTracer(parent, spanName, tracerContext.operationType());
8674
}
8775

8876
/**

gax-java/gax/src/main/java/com/google/api/gax/tracing/MetricsTracerFactory.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131

3232
import com.google.api.core.BetaApi;
3333
import com.google.api.core.InternalApi;
34+
import com.google.common.base.Preconditions;
3435
import com.google.common.collect.ImmutableMap;
3536
import java.util.Map;
3637

@@ -66,6 +67,7 @@ public MetricsTracerFactory(MetricsRecorder metricsRecorder, Map<String, String>
6667

6768
@Override
6869
public ApiTracer newTracer(ApiTracer parent, SpanName spanName, OperationType operationType) {
70+
Preconditions.checkNotNull(operationType, "operationType cannot be null.");
6971
MetricsTracer metricsTracer =
7072
new MetricsTracer(
7173
MethodName.of(spanName.getClientName(), spanName.getMethodName()), metricsRecorder);

gax-java/gax/src/main/java/com/google/api/gax/tracing/OpencensusTracerFactory.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ public OpencensusTracerFactory(Map<String, String> spanAttributes) {
9696
/** {@inheritDoc } */
9797
@Override
9898
public ApiTracer newTracer(ApiTracer parent, SpanName spanName, OperationType operationType) {
99+
Preconditions.checkNotNull(operationType, "operationType cannot be null.");
99100
// Default to the current in context span. This is used for outermost tracers that inherit
100101
// the caller's parent span.
101102
Span parentSpan = internalTracer.getCurrentSpan();

gax-java/gax/src/main/java/com/google/api/gax/tracing/SpanTracerFactory.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,7 @@ public ApiTracer newTracer(ApiTracer parent, SpanName spanName, OperationType op
7676
}
7777

7878
@Override
79-
public ApiTracer newTracer(
80-
ApiTracer parent, ApiTracerContext apiTracerContext, OperationType operationType) {
79+
public ApiTracer newTracer(ApiTracer parent, ApiTracerContext apiTracerContext) {
8180
ApiTracerContext mergedContext = this.apiTracerContext.merge(apiTracerContext);
8281

8382
String attemptSpanName;

gax-java/gax/src/main/java/com/google/api/gax/tracing/TracedBatchingCallable.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,8 @@ public TracedBatchingCallable(
7373
ApiTracerContext apiTracerContext,
7474
BatchingDescriptor<RequestT, ResponseT> batchingDescriptor) {
7575
this.tracerFactory = tracerFactory;
76-
this.apiTracerContext = apiTracerContext;
76+
this.apiTracerContext =
77+
apiTracerContext.toBuilder().setOperationType(OperationType.Batching).build();
7778
this.batchingDescriptor = batchingDescriptor;
7879
this.innerCallable = innerCallable;
7980
this.spanName = SpanName.of(apiTracerContext);

gax-java/gax/src/main/java/com/google/api/gax/tracing/TracedBidiCallable.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,9 @@ public TracedBidiCallable(
7474
@Nonnull ApiTracerContext apiTracerContext) {
7575
this.tracerFactory = Preconditions.checkNotNull(tracerFactory, "tracerFactory can't be null");
7676
this.apiTracerContext =
77-
Preconditions.checkNotNull(apiTracerContext, "apiTracerContext can't be null");
77+
Preconditions.checkNotNull(apiTracerContext, "apiTracerContext can't be null").toBuilder()
78+
.setOperationType(OperationType.BidiStreaming)
79+
.build();
7880
this.innerCallable = Preconditions.checkNotNull(innerCallable, "innerCallable can't be null");
7981
this.spanName = SpanName.of(this.apiTracerContext);
8082
}

gax-java/gax/src/main/java/com/google/api/gax/tracing/TracedClientStreamingCallable.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,9 @@ public TracedClientStreamingCallable(
7474
@Nonnull ApiTracerContext apiTracerContext) {
7575
this.tracerFactory = Preconditions.checkNotNull(tracerFactory, "tracerFactory can't be null");
7676
this.apiTracerContext =
77-
Preconditions.checkNotNull(apiTracerContext, "apiTracerContext can't be null");
77+
Preconditions.checkNotNull(apiTracerContext, "apiTracerContext can't be null").toBuilder()
78+
.setOperationType(OperationType.ClientStreaming)
79+
.build();
7880
this.innerCallable = Preconditions.checkNotNull(innerCallable, "innerCallable can't be null");
7981
this.spanName = SpanName.of(this.apiTracerContext);
8082
}

gax-java/gax/src/main/java/com/google/api/gax/tracing/TracedServerStreamingCallable.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,9 @@ public TracedServerStreamingCallable(
7070
@Nonnull ApiTracerContext apiTracerContext) {
7171
this.tracerFactory = Preconditions.checkNotNull(tracerFactory, "tracerFactory can't be null");
7272
this.apiTracerContext =
73-
Preconditions.checkNotNull(apiTracerContext, "apiTracerContext can't be null");
73+
Preconditions.checkNotNull(apiTracerContext, "apiTracerContext can't be null").toBuilder()
74+
.setOperationType(OperationType.ServerStreaming)
75+
.build();
7476
this.innerCallable = Preconditions.checkNotNull(innerCallable, "innerCallable can't be null");
7577
this.spanName = SpanName.of(this.apiTracerContext);
7678
}

gax-java/gax/src/main/java/com/google/api/gax/tracing/TracedUnaryCallable.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,8 @@ public TracedUnaryCallable(
6868
ApiTracerContext apiTracerContext) {
6969
this.innerCallable = innerCallable;
7070
this.tracerFactory = tracerFactory;
71-
this.apiTracerContext = apiTracerContext;
71+
this.apiTracerContext =
72+
apiTracerContext.toBuilder().setOperationType(OperationType.Unary).build();
7273
this.spanName = SpanName.of(apiTracerContext);
7374
}
7475

gax-java/gax/src/test/java/com/google/api/gax/tracing/SpanTracerFactoryTest.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ void testNewTracer_createsSpanTracer(boolean useContext) {
7373
.setTransport(Transport.GRPC)
7474
.setLibraryMetadata(LibraryMetadata.empty())
7575
.build();
76-
tracer = factory.newTracer(null, context, OperationType.Unary);
76+
tracer = factory.newTracer(null, context);
7777
} else {
7878
tracer = factory.newTracer(null, SpanName.of("service", "method"), OperationType.Unary);
7979
}
@@ -98,7 +98,7 @@ void testNewTracer_addsAttributes(boolean useContext) {
9898
.setTransport(Transport.GRPC)
9999
.setLibraryMetadata(LibraryMetadata.empty())
100100
.build();
101-
tracer = factory.newTracer(null, context, OperationType.Unary);
101+
tracer = factory.newTracer(null, context);
102102
} else {
103103
tracer = factory.newTracer(null, SpanName.of("service", "method"), OperationType.Unary);
104104
}
@@ -132,7 +132,7 @@ void testWithContext_addsInferredAttributes(boolean useContext) {
132132
.setTransport(Transport.GRPC)
133133
.setLibraryMetadata(LibraryMetadata.empty())
134134
.build();
135-
tracer = factoryWithContext.newTracer(null, callContext, OperationType.Unary);
135+
tracer = factoryWithContext.newTracer(null, callContext);
136136
} else {
137137
tracer =
138138
factoryWithContext.newTracer(null, SpanName.of("service", "method"), OperationType.Unary);
@@ -164,7 +164,7 @@ void testWithContext_noEndpointContext_doesNotAddServerAddressAttribute(boolean
164164
.setTransport(Transport.GRPC)
165165
.setLibraryMetadata(LibraryMetadata.empty())
166166
.build();
167-
tracer = factoryWithContext.newTracer(null, callContext, OperationType.Unary);
167+
tracer = factoryWithContext.newTracer(null, callContext);
168168
} else {
169169
tracer =
170170
factoryWithContext.newTracer(null, SpanName.of("service", "method"), OperationType.Unary);
@@ -190,7 +190,7 @@ void testNewTracer_withContext_grpc_usesFullMethodName() {
190190
.build();
191191

192192
SpanTracerFactory factory = new SpanTracerFactory(traceManager);
193-
ApiTracer tracer = factory.newTracer(null, context, OperationType.Unary);
193+
ApiTracer tracer = factory.newTracer(null, context);
194194

195195
tracer.attemptStarted(null, 1);
196196

@@ -216,7 +216,7 @@ void testNewTracer_withContext_http_usesHttpMethodAndPathTemplate(
216216
.build();
217217

218218
SpanTracerFactory factory = new SpanTracerFactory(traceManager);
219-
ApiTracer tracer = factory.newTracer(null, context, OperationType.Unary);
219+
ApiTracer tracer = factory.newTracer(null, context);
220220

221221
tracer.attemptStarted(null, 1);
222222

@@ -250,7 +250,7 @@ void testNewTracer_mergesFactoryContext() {
250250
.setLibraryMetadata(LibraryMetadata.empty())
251251
.build();
252252

253-
ApiTracer tracer = factory.newTracer(null, callContext, OperationType.Unary);
253+
ApiTracer tracer = factory.newTracer(null, callContext);
254254
tracer.attemptStarted(null, 1);
255255

256256
ArgumentCaptor<Map<String, Object>> attributesCaptor = ArgumentCaptor.forClass(Map.class);

0 commit comments

Comments
 (0)