-
Notifications
You must be signed in to change notification settings - Fork 75
fix: Populate method level attributes in metrics recording #4149
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
Changes from all commits
64377a5
1440456
427877e
054f881
eaac7ef
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -30,7 +30,8 @@ | |
| package com.google.api.gax.tracing; | ||
|
|
||
| import static com.google.common.truth.Truth.assertThat; | ||
| import static org.mockito.Mockito.mock; | ||
| import static org.mockito.Answers.RETURNS_DEEP_STUBS; | ||
| import static org.mockito.Mockito.*; | ||
|
|
||
| import io.opentelemetry.api.OpenTelemetry; | ||
| import org.junit.jupiter.api.BeforeEach; | ||
|
|
@@ -46,7 +47,7 @@ void setUp() { | |
| } | ||
|
|
||
| @Test | ||
| void newTracer_createsTracer_successfully() { | ||
| void newTracerWithSpanName_shouldCreateTracer_ifMetricsRecorderIsNotNull() { | ||
| tracerFactory.withContext(ApiTracerContext.empty()); | ||
| ApiTracer actual = | ||
| tracerFactory.newTracer( | ||
|
|
@@ -55,10 +56,32 @@ void newTracer_createsTracer_successfully() { | |
| } | ||
|
|
||
| @Test | ||
| void newTracer_createsBaseTracer_ifMetricsRecorderIsNull() { | ||
| void newTracerWithSpanName_shouldCreateBaseTracer_ifMetricsRecorderIsNull() { | ||
| ApiTracer actual = | ||
| tracerFactory.newTracer( | ||
| mock(ApiTracer.class), mock(SpanName.class), ApiTracerFactory.OperationType.Unary); | ||
| assertThat(actual).isInstanceOf(BaseApiTracer.class); | ||
| } | ||
|
|
||
| @Test | ||
| void newTracerWithApiTracerContext_shouldMergeApiTracerContext() { | ||
| ApiTracerContext clientLevelTracerContext = mock(ApiTracerContext.class, RETURNS_DEEP_STUBS); | ||
| ApiTracerContext methodLevelTracerContext = mock(ApiTracerContext.class); | ||
| when(clientLevelTracerContext.libraryMetadata().artifactName()).thenReturn("does not matter"); | ||
| when(clientLevelTracerContext.merge(methodLevelTracerContext)) | ||
| .thenReturn(clientLevelTracerContext); | ||
|
|
||
| tracerFactory.withContext(clientLevelTracerContext); | ||
| ApiTracer actual = tracerFactory.newTracer(mock(ApiTracer.class), methodLevelTracerContext); | ||
|
|
||
| verify(clientLevelTracerContext).merge(methodLevelTracerContext); | ||
| assertThat(actual).isInstanceOf(GoldenSignalsMetricsTracer.class); | ||
|
Comment on lines
+75
to
+78
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This test correctly checks that a You'll also need to add the following import: ApiTracer actual = tracerFactory.newTracer(mock(ApiTracer.class), methodLevelTracerContext);
verify(clientLevelTracerContext).merge(methodLevelTracerContext);
assertThat(actual).isInstanceOf(GoldenSignalsMetricsTracer.class); |
||
| } | ||
|
|
||
| @Test | ||
| void newTracerWithApiTracerContext_shouldCreateBaseTracer_ifMetricsRecorderIsNull() { | ||
| ApiTracer actual = tracerFactory.newTracer(mock(ApiTracer.class), mock(ApiTracerContext.class)); | ||
|
|
||
| assertThat(actual).isInstanceOf(BaseApiTracer.class); | ||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This null check for
metricsRecorderis duplicated from the othernewTracermethod (lines 56-59). To improve maintainability and avoid code duplication, consider extracting this logic into a private helper method. For example:Then both
newTracermethods can call this helper.