Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Update default Otel Attribute from method_name to method #2833

Merged
merged 5 commits into from
Jun 11, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions gax-java/gax/clirr-ignored-differences.xml
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,10 @@
<className>com/google/api/gax/rpc/StubSettings</className>
<method>* getServiceName()</method>
</difference>
<!-- Update default method_name Otel attribute to method -->
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since MetricsTracer is an internal API, can we make exclude the whole class?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wasn't find a way to ignore all differences, so I kept it as <differenceType>6011</differenceType>. I just used a wildcard for <field>.

<difference>
<differenceType>6011</differenceType>
<className>com/google/api/gax/tracing/MetricsTracer</className>
<field>METHOD_NAME_ATTRIBUTE</field>
</difference>
</differences>
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
@BetaApi
@InternalApi
public class MetricsTracer implements ApiTracer {
public static final String METHOD_NAME_ATTRIBUTE = "method_name";
public static final String METHOD_ATTRIBUTE = "method";
public static final String LANGUAGE_ATTRIBUTE = "language";
public static final String STATUS_ATTRIBUTE = "status";
public static final String DEFAULT_LANGUAGE = "Java";
Expand All @@ -66,7 +66,7 @@ public class MetricsTracer implements ApiTracer {
private final AtomicBoolean operationFinished;

public MetricsTracer(MethodName methodName, MetricsRecorder metricsRecorder) {
this.attributes.put(METHOD_NAME_ATTRIBUTE, methodName.toString());
this.attributes.put(METHOD_ATTRIBUTE, methodName.toString());
this.attributes.put(LANGUAGE_ATTRIBUTE, DEFAULT_LANGUAGE);
this.metricsRecorder = metricsRecorder;
this.operationFinished = new AtomicBoolean();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@ void testNewTracer_notNull() {

@Test
void testNewTracer_HasCorrectParameters() {

// Call the newTracer method
ApiTracer apiTracer = metricsTracerFactory.newTracer(parent, spanName, OperationType.Unary);

Expand All @@ -75,7 +74,9 @@ void testNewTracer_HasCorrectParameters() {
Truth.assertThat(apiTracer).isNotNull();

MetricsTracer metricsTracer = (MetricsTracer) apiTracer;
Truth.assertThat(metricsTracer.getAttributes().get("method_name"))
Truth.assertThat(metricsTracer.getAttributes().get(MetricsTracer.METHOD_ATTRIBUTE))
.isEqualTo("testService.testMethod");
Truth.assertThat(metricsTracer.getAttributes().get(MetricsTracer.LANGUAGE_ATTRIBUTE))
.isEqualTo(MetricsTracer.DEFAULT_LANGUAGE);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,11 @@ void setUp() {

private ImmutableMap<String, String> getAttributes(Code statusCode) {
return ImmutableMap.of(
"status",
MetricsTracer.STATUS_ATTRIBUTE,
statusCode.toString(),
"method_name",
MetricsTracer.METHOD_ATTRIBUTE,
DEFAULT_METHOD_NAME,
"language",
MetricsTracer.LANGUAGE_ATTRIBUTE,
MetricsTracer.DEFAULT_LANGUAGE);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,7 @@ void testGrpc_operationSucceeded_recordsMetrics() throws InterruptedException {

Map<String, String> attributeMapping =
ImmutableMap.of(
MetricsTracer.METHOD_NAME_ATTRIBUTE,
MetricsTracer.METHOD_ATTRIBUTE,
"Echo.Echo",
MetricsTracer.LANGUAGE_ATTRIBUTE,
MetricsTracer.DEFAULT_LANGUAGE);
Expand All @@ -324,7 +324,7 @@ void testHttpJson_operationSucceeded_recordsMetrics() throws InterruptedExceptio

Map<String, String> attributeMapping =
ImmutableMap.of(
MetricsTracer.METHOD_NAME_ATTRIBUTE,
MetricsTracer.METHOD_ATTRIBUTE,
"google.showcase.v1beta1.Echo/Echo",
MetricsTracer.LANGUAGE_ATTRIBUTE,
MetricsTracer.DEFAULT_LANGUAGE);
Expand Down Expand Up @@ -354,7 +354,7 @@ void testGrpc_operationCancelled_recordsMetrics() throws Exception {

Map<String, String> attributeMapping =
ImmutableMap.of(
MetricsTracer.METHOD_NAME_ATTRIBUTE,
MetricsTracer.METHOD_ATTRIBUTE,
"Echo.Block",
MetricsTracer.LANGUAGE_ATTRIBUTE,
MetricsTracer.DEFAULT_LANGUAGE);
Expand Down Expand Up @@ -382,7 +382,7 @@ void testHttpJson_operationCancelled_recordsMetrics() throws Exception {

Map<String, String> attributeMapping =
ImmutableMap.of(
MetricsTracer.METHOD_NAME_ATTRIBUTE,
MetricsTracer.METHOD_ATTRIBUTE,
"google.showcase.v1beta1.Echo/Block",
MetricsTracer.LANGUAGE_ATTRIBUTE,
MetricsTracer.DEFAULT_LANGUAGE);
Expand Down Expand Up @@ -411,7 +411,7 @@ void testGrpc_operationFailed_recordsMetrics() throws InterruptedException {

Map<String, String> attributeMapping =
ImmutableMap.of(
MetricsTracer.METHOD_NAME_ATTRIBUTE,
MetricsTracer.METHOD_ATTRIBUTE,
"Echo.Block",
MetricsTracer.LANGUAGE_ATTRIBUTE,
MetricsTracer.DEFAULT_LANGUAGE);
Expand Down Expand Up @@ -441,7 +441,7 @@ void testHttpJson_operationFailed_recordsMetrics() throws InterruptedException {

Map<String, String> attributeMapping =
ImmutableMap.of(
MetricsTracer.METHOD_NAME_ATTRIBUTE,
MetricsTracer.METHOD_ATTRIBUTE,
"google.showcase.v1beta1.Echo/Block",
MetricsTracer.LANGUAGE_ATTRIBUTE,
MetricsTracer.DEFAULT_LANGUAGE);
Expand Down Expand Up @@ -504,7 +504,7 @@ void testGrpc_attemptFailedRetriesExhausted_recordsMetrics() throws Exception {

Map<String, String> attributeMapping =
ImmutableMap.of(
MetricsTracer.METHOD_NAME_ATTRIBUTE,
MetricsTracer.METHOD_ATTRIBUTE,
"Echo.Echo",
MetricsTracer.LANGUAGE_ATTRIBUTE,
MetricsTracer.DEFAULT_LANGUAGE);
Expand Down Expand Up @@ -572,7 +572,7 @@ void testHttpJson_attemptFailedRetriesExhausted_recordsMetrics() throws Exceptio

Map<String, String> attributeMapping =
ImmutableMap.of(
MetricsTracer.METHOD_NAME_ATTRIBUTE,
MetricsTracer.METHOD_ATTRIBUTE,
"google.showcase.v1beta1.Echo/Echo",
MetricsTracer.LANGUAGE_ATTRIBUTE,
MetricsTracer.DEFAULT_LANGUAGE);
Expand Down Expand Up @@ -602,7 +602,7 @@ void testGrpc_attemptPermanentFailure_recordsMetrics() throws InterruptedExcepti

Map<String, String> attributeMapping =
ImmutableMap.of(
MetricsTracer.METHOD_NAME_ATTRIBUTE,
MetricsTracer.METHOD_ATTRIBUTE,
"Echo.Block",
MetricsTracer.LANGUAGE_ATTRIBUTE,
MetricsTracer.DEFAULT_LANGUAGE);
Expand Down Expand Up @@ -630,7 +630,7 @@ void testHttpJson_attemptPermanentFailure_recordsMetrics() throws InterruptedExc

Map<String, String> attributeMapping =
ImmutableMap.of(
MetricsTracer.METHOD_NAME_ATTRIBUTE,
MetricsTracer.METHOD_ATTRIBUTE,
"google.showcase.v1beta1.Echo/Block",
MetricsTracer.LANGUAGE_ATTRIBUTE,
MetricsTracer.DEFAULT_LANGUAGE);
Expand Down Expand Up @@ -699,7 +699,7 @@ void testGrpc_multipleFailedAttempts_successfulOperation() throws Exception {

Map<String, String> attributeMapping =
ImmutableMap.of(
MetricsTracer.METHOD_NAME_ATTRIBUTE,
MetricsTracer.METHOD_ATTRIBUTE,
"Echo.Block",
MetricsTracer.LANGUAGE_ATTRIBUTE,
MetricsTracer.DEFAULT_LANGUAGE);
Expand Down Expand Up @@ -769,7 +769,7 @@ void testHttpJson_multipleFailedAttempts_successfulOperation() throws Exception

Map<String, String> attributeMapping =
ImmutableMap.of(
MetricsTracer.METHOD_NAME_ATTRIBUTE,
MetricsTracer.METHOD_ATTRIBUTE,
"google.showcase.v1beta1.Echo/Block",
MetricsTracer.LANGUAGE_ATTRIBUTE,
MetricsTracer.DEFAULT_LANGUAGE);
Expand Down
Loading